Nicer color theme.
This commit is contained in:
parent
fb1996c21a
commit
14adcf99cb
|
@ -25,6 +25,57 @@ use self::{
|
||||||
|
|
||||||
const EMPTY_MOD: KeyModifiers = KeyModifiers::empty();
|
const EMPTY_MOD: KeyModifiers = KeyModifiers::empty();
|
||||||
|
|
||||||
|
// Color theme.
|
||||||
|
// Styles are (FG, BG).
|
||||||
|
const STYLE_MAIN: Style = Style(
|
||||||
|
Color::Rgb {
|
||||||
|
r: 0xD0,
|
||||||
|
g: 0xD0,
|
||||||
|
b: 0xD0,
|
||||||
|
},
|
||||||
|
Color::Rgb {
|
||||||
|
r: 0x28,
|
||||||
|
g: 0x28,
|
||||||
|
b: 0x28,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const STYLE_CURSOR: Style = Style(
|
||||||
|
Color::Rgb {
|
||||||
|
r: 0x00,
|
||||||
|
g: 0x00,
|
||||||
|
b: 0x00,
|
||||||
|
},
|
||||||
|
Color::Rgb {
|
||||||
|
r: 0xD0,
|
||||||
|
g: 0xD0,
|
||||||
|
b: 0xD0,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const STYLE_GUTTER: Style = Style(
|
||||||
|
Color::Rgb {
|
||||||
|
r: 0x70,
|
||||||
|
g: 0x70,
|
||||||
|
b: 0x70,
|
||||||
|
},
|
||||||
|
Color::Rgb {
|
||||||
|
r: 0x28,
|
||||||
|
g: 0x28,
|
||||||
|
b: 0x28,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const STYLE_INFO: Style = Style(
|
||||||
|
Color::Rgb {
|
||||||
|
r: 0xD0,
|
||||||
|
g: 0xD0,
|
||||||
|
b: 0xD0,
|
||||||
|
},
|
||||||
|
Color::Rgb {
|
||||||
|
r: 0x50,
|
||||||
|
g: 0x50,
|
||||||
|
b: 0x50,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
/// Generalized ui loop.
|
/// Generalized ui loop.
|
||||||
macro_rules! ui_loop {
|
macro_rules! ui_loop {
|
||||||
($term_ui:ident,draw $draw:block,key_press($key:ident) $key_press:block) => {
|
($term_ui:ident,draw $draw:block,key_press($key:ident) $key_press:block) => {
|
||||||
|
@ -151,7 +202,7 @@ impl TermUI {
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
draw {
|
draw {
|
||||||
self.screen.clear(Color::Black);
|
self.screen.clear(STYLE_MAIN.1);
|
||||||
self.draw_editor(&self.editor, (0, 0), (self.height - 1, self.width - 1));
|
self.draw_editor(&self.editor, (0, 0), (self.height - 1, self.width - 1));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -285,8 +336,6 @@ impl TermUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn go_to_line_ui_loop(&mut self) {
|
fn go_to_line_ui_loop(&mut self) {
|
||||||
let style = Style(Color::Black, Color::Cyan);
|
|
||||||
|
|
||||||
let mut cancel = false;
|
let mut cancel = false;
|
||||||
let prefix = "Jump to line: ";
|
let prefix = "Jump to line: ";
|
||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
|
@ -296,17 +345,17 @@ impl TermUI {
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
draw {
|
draw {
|
||||||
self.screen.clear(Color::Black);
|
self.screen.clear(STYLE_MAIN.1);
|
||||||
self.draw_editor(&self.editor, (0, 0), (self.height - 1, self.width - 1));
|
self.draw_editor(&self.editor, (0, 0), (self.height - 1, self.width - 1));
|
||||||
for i in 0..self.width {
|
for i in 0..self.width {
|
||||||
self.screen.draw(i, 0, " ", style);
|
self.screen.draw(i, 0, " ", STYLE_INFO);
|
||||||
}
|
}
|
||||||
self.screen.draw(1, 0, prefix, style);
|
self.screen.draw(1, 0, prefix, STYLE_INFO);
|
||||||
self.screen.draw(
|
self.screen.draw(
|
||||||
prefix.len() + 1,
|
prefix.len() + 1,
|
||||||
0,
|
0,
|
||||||
&line[..],
|
&line[..],
|
||||||
style,
|
STYLE_INFO,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -377,18 +426,16 @@ impl TermUI {
|
||||||
c1: (usize, usize),
|
c1: (usize, usize),
|
||||||
c2: (usize, usize),
|
c2: (usize, usize),
|
||||||
) {
|
) {
|
||||||
let style = Style(Color::Black, Color::Cyan);
|
|
||||||
|
|
||||||
// Fill in top row with info line color
|
// Fill in top row with info line color
|
||||||
for i in c1.1..(c2.1 + 1) {
|
for i in c1.1..(c2.1 + 1) {
|
||||||
self.screen.draw(i, c1.0, " ", style);
|
self.screen.draw(i, c1.0, " ", STYLE_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filename and dirty marker
|
// Filename and dirty marker
|
||||||
let filename = editor.file_path.display();
|
let filename = editor.file_path.display();
|
||||||
let dirty_char = if editor.dirty { "*" } else { "" };
|
let dirty_char = if editor.dirty { "*" } else { "" };
|
||||||
let name = format!("{}{}", filename, dirty_char);
|
let name = format!("{}{}", filename, dirty_char);
|
||||||
self.screen.draw(c1.1 + 1, c1.0, &name[..], style);
|
self.screen.draw(c1.1 + 1, c1.0, &name[..], STYLE_INFO);
|
||||||
|
|
||||||
// Percentage position in document
|
// Percentage position in document
|
||||||
// TODO: use view instead of cursor for calculation if there is more
|
// TODO: use view instead of cursor for calculation if there is more
|
||||||
|
@ -400,8 +447,12 @@ impl TermUI {
|
||||||
100
|
100
|
||||||
};
|
};
|
||||||
let pstring = format!("{}%", percentage);
|
let pstring = format!("{}%", percentage);
|
||||||
self.screen
|
self.screen.draw(
|
||||||
.draw(c2.1 - pstring.len().min(c2.1), c1.0, &pstring[..], style);
|
c2.1 - pstring.len().min(c2.1),
|
||||||
|
c1.0,
|
||||||
|
&pstring[..],
|
||||||
|
STYLE_INFO,
|
||||||
|
);
|
||||||
|
|
||||||
// Text encoding info and tab style
|
// Text encoding info and tab style
|
||||||
let nl = match editor.line_ending_type {
|
let nl = match editor.line_ending_type {
|
||||||
|
@ -421,7 +472,7 @@ impl TermUI {
|
||||||
nl, soft_tabs_str, editor.soft_tab_width as usize
|
nl, soft_tabs_str, editor.soft_tab_width as usize
|
||||||
);
|
);
|
||||||
self.screen
|
self.screen
|
||||||
.draw(c2.1 - 30.min(c2.1), c1.0, &info_line[..], style);
|
.draw(c2.1 - 30.min(c2.1), c1.0, &info_line[..], STYLE_INFO);
|
||||||
|
|
||||||
// Draw main text editing area
|
// Draw main text editing area
|
||||||
self.draw_editor_text(editor, (c1.0 + 1, c1.1), c2);
|
self.draw_editor_text(editor, (c1.0 + 1, c1.1), c2);
|
||||||
|
@ -458,8 +509,7 @@ impl TermUI {
|
||||||
// Fill in the gutter with the appropriate background
|
// Fill in the gutter with the appropriate background
|
||||||
for y in c1.0..(c2.0 + 1) {
|
for y in c1.0..(c2.0 + 1) {
|
||||||
for x in c1.1..(c1.1 + gutter_width - 1) {
|
for x in c1.1..(c1.1 + gutter_width - 1) {
|
||||||
self.screen
|
self.screen.draw(x, y, " ", STYLE_GUTTER);
|
||||||
.draw(x, y, " ", Style(Color::White, Color::Blue));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,12 +520,8 @@ impl TermUI {
|
||||||
let lnx = c1.1 + (gutter_width - 1 - digit_count(line_num as u32, 10) as usize);
|
let lnx = c1.1 + (gutter_width - 1 - digit_count(line_num as u32, 10) as usize);
|
||||||
let lny = screen_line as usize;
|
let lny = screen_line as usize;
|
||||||
if lny >= c1.0 && lny <= c2.0 {
|
if lny >= c1.0 && lny <= c2.0 {
|
||||||
self.screen.draw(
|
self.screen
|
||||||
lnx,
|
.draw(lnx, lny, &format!("{}", line_num)[..], STYLE_GUTTER);
|
||||||
lny,
|
|
||||||
&format!("{}", line_num)[..],
|
|
||||||
Style(Color::White, Color::Blue),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,33 +565,20 @@ impl TermUI {
|
||||||
// Actually print the character
|
// Actually print the character
|
||||||
if rope_slice_is_line_ending(&g) {
|
if rope_slice_is_line_ending(&g) {
|
||||||
if at_cursor {
|
if at_cursor {
|
||||||
self.screen.draw(
|
self.screen
|
||||||
px as usize,
|
.draw(px as usize, py as usize, " ", STYLE_CURSOR);
|
||||||
py as usize,
|
|
||||||
" ",
|
|
||||||
Style(Color::Black, Color::White),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else if g == "\t" {
|
} else if g == "\t" {
|
||||||
for i in 0..width {
|
for i in 0..width {
|
||||||
let tpx = px as usize + i;
|
let tpx = px as usize + i;
|
||||||
if tpx <= c2.1 {
|
if tpx <= c2.1 {
|
||||||
self.screen.draw(
|
self.screen.draw(tpx as usize, py as usize, " ", STYLE_MAIN);
|
||||||
tpx as usize,
|
|
||||||
py as usize,
|
|
||||||
" ",
|
|
||||||
Style(Color::White, Color::Black),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if at_cursor {
|
if at_cursor {
|
||||||
self.screen.draw(
|
self.screen
|
||||||
px as usize,
|
.draw(px as usize, py as usize, " ", STYLE_CURSOR);
|
||||||
py as usize,
|
|
||||||
" ",
|
|
||||||
Style(Color::Black, Color::White),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if at_cursor {
|
if at_cursor {
|
||||||
|
@ -553,14 +586,14 @@ impl TermUI {
|
||||||
px as usize,
|
px as usize,
|
||||||
py as usize,
|
py as usize,
|
||||||
&g,
|
&g,
|
||||||
Style(Color::Black, Color::White),
|
STYLE_CURSOR,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
self.screen.draw_rope_slice(
|
self.screen.draw_rope_slice(
|
||||||
px as usize,
|
px as usize,
|
||||||
py as usize,
|
py as usize,
|
||||||
&g,
|
&g,
|
||||||
Style(Color::White, Color::Black),
|
STYLE_MAIN,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,12 +646,8 @@ impl TermUI {
|
||||||
&& (px <= c2.1 as isize)
|
&& (px <= c2.1 as isize)
|
||||||
&& (py <= c2.0 as isize)
|
&& (py <= c2.0 as isize)
|
||||||
{
|
{
|
||||||
self.screen.draw(
|
self.screen
|
||||||
px as usize,
|
.draw(px as usize, py as usize, " ", STYLE_CURSOR);
|
||||||
py as usize,
|
|
||||||
" ",
|
|
||||||
Style(Color::Black, Color::White),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user