Compare commits

...

2 Commits

Author SHA1 Message Date
mars 547dea6ac0 Selected line# and cursorline styling 2023-04-12 21:25:12 -04:00
mars b29891571b Sane default theme 2023-04-12 20:31:51 -04:00
3 changed files with 54 additions and 93 deletions

View File

@ -74,15 +74,17 @@ impl Buffer {
cols: u16,
rows: u16,
scroll: Cursor,
cursor: Cursor,
out: &mut impl Write,
) -> crossterm::Result<u32> {
self.parse();
let mut styles = self.styles.lock();
let linenr_style = styles.get_scope("ui.linenr");
let linenr_style = styles.get_scope("ui.linenr").clone();
let linenr_width = self.text.len_lines().ilog10() + 1;
let gutter_width = linenr_width + 1;
let text_width = cols as usize - gutter_width as usize;
let line_padding: String = std::iter::repeat(' ').take(text_width).collect();
out.queue(cursor::MoveTo(0, 0))?;
@ -94,22 +96,40 @@ impl Buffer {
}
let row = row as usize + scroll.line;
let is_selected = row == cursor.line;
let linenr_style = if is_selected {
styles.get_scope("ui.linenr.selected").clone()
} else {
linenr_style
};
let line_style = if is_selected {
styles.get_scope("ui.cursorline.primary").clone()
} else {
Default::default()
};
let linenr = format!("{:width$} ", row, width = linenr_width as usize);
linenr_style.print_styled(out, &linenr)?;
let lhs = scroll.column;
let width = line.len_chars();
let mut remaining = text_width;
line_buf.clear();
if lhs < width {
let window = text_width.min(width - lhs);
let rhs = lhs + window;
let styled = &self.styled[row];
for (style, range) in styled.iter() {
for (chunk_style, range) in styled.iter() {
let range = range.start.max(lhs)..range.end.min(rhs);
if range.start < range.end {
// this range is in view so display
let content = line.slice(range.clone());
let mut style = line_style.clone();
style.apply(chunk_style);
style.print_styled(&mut line_buf, content)?;
remaining = text_width.saturating_sub(range.end);
}
if range.end >= rhs {
@ -119,6 +139,9 @@ impl Buffer {
}
}
let padding = &line_padding[0..remaining];
line_style.print_styled(&mut line_buf, padding)?;
out.write_all(&line_buf)?;
out.queue(cursor::MoveToNextLine(1))?;
}

View File

@ -170,7 +170,7 @@ impl State {
// draw buffer
let buffer_rows = if show_status_bar { rows - 1 } else { rows };
let lr_width = self.buffer.draw(cols, buffer_rows, self.scroll, out)?;
let lr_width = self.buffer.draw(cols, buffer_rows, self.scroll, self.cursor, out)?;
// draw cursor
let cursor_pos = set_cursor_pos.unwrap_or_else(|| {

View File

@ -1,92 +1,30 @@
"ui.linenr" = "gray"
"ui.cursorline" = {}
"ui.linenr" = "black"
"ui.linenr.selected" = "white"
"error" = "love"
"error" = "red"
"attribute" = "iris"
"type" = "foam"
# "type.builtin" = ""
"constructor" = "foam"
"comment" = { fg = "muted", modifiers = ["italic"]}
"constant" = "foam"
"constant.builtin" = "rose"
"constant.character" = "gold"
"constant.character.escape" = "pine"
"constant.numeric" = "gold"
"entity.name" = "rose"
"invalid" = "love"
"keyword" = "pine"
"keyword.operator" = "subtle"
"label" = "foam"
"operator" = "subtle"
"punctuation" = "subtle"
"string" = "gold"
# "string.regexp" = ""
# "string.special" = ""
# "string.special.path" = ""
# "string.special.url" = ""
# "string.special.symbol" = ""
"variable" = "text"
"variable.builtin" = "love"
"variable.parameter" = "iris"
"markup.heading.marker" = "muted"
"markup.heading" = { fg = "iris", modifiers = ["bold"] }
"markup.heading.1" = { fg = "iris", modifiers = ["bold"] }
"markup.heading.2" = { fg = "foam", modifiers = ["bold"] }
"markup.heading.3" = { fg = "rose", modifiers = ["bold"] }
"markup.heading.4" = { fg = "gold", modifiers = ["bold"] }
"markup.heading.5" = { fg = "pine", modifiers = ["bold"] }
"markup.heading.6" = { fg = "foam", modifiers = ["bold"] }
# "markup.heading.completion" = ""
# "markup.heading.hover" = ""
"markup.list" = "muted"
# "markup.list.unnumbered" = ""
# "markup.list.numbered" = ""
"markup.bold" = { modifiers = ["bold"] }
"markup.italic" = { modifiers = ["italic"] }
"markup.strikethrough" = { modifiers = ["crossed_out"] }
"markup.link" = "iris"
"markup.link.url" = { fg = "iris", underline = { color = "iris", style = "line" } }
"markup.link.label" = "subtle"
"markup.link.text" = "text"
"markup.quote" = "subtle"
"markup.raw" = "subtle"
# "markup.raw.inline" = {}
# "markup.raw.inline.completion" = {}
# "markup.raw.inline.hover" = {}
# "markup.raw.block" = {}
# "markup.normal" = ""
# "markup.normal.completion" = ""
# "markup.normal.hover" = ""
"diff" = "overlay"
"diff.plus" = "foam"
"diff.minus" = "love"
"diff.delta" = "highlight_high"
# "diff.delta.moved" = ""
[palette]
base = "#191724"
surface = "#1f1d2e"
overlay = "#26233a"
muted = "#6e6a86"
subtle = "#908caa"
text = "#e0def4"
love = "#eb6f92"
love_10 = "#311f30"
gold = "#f6c177"
gold_10 = "#30282c"
rose = "#ebbcba"
rose_10 = "#2f2834"
pine = "#31748f"
pine_10 = "#1a2030"
foam = "#9ccfd8"
foam_10 = "#252937"
iris = "#c4a7e7"
iris_10 = "#2b2539"
highlight_low = "#21202e"
highlight_med = "#403d52"
highlight_high = "#524f67"
"comment" = { fg = "black", modifiers = ["italics"] }
"constant" = "yellow"
"constant.character.escape" = "light-cyan"
"constant.language" = "magenta"
"constant.numeric" = "blue"
"entity.name" = "blue"
"entity.other.attribute-name" = "red"
"entity.other.inherited-class" = "red"
"invalid.deprecated" = "red"
"invalid" = "red"
"keyword" = "magenta"
"keyword.control" = "magenta"
"keyword.declaration" = "blue"
"keyword.operator" = "blue"
"meta.path" = "blue"
"punctuation" = "gray"
"punctuation.definition.string.begin" = "green"
"punctuation.definition.string.end" = "green"
"storage" = "magenta"
"storage.type" = "magenta"
"string" = "green"
"support" = "yellow"
"variable" = "green"
"variable.language" = "magenta"