Render the cursor position, fixup colors

I thought it would be nice to use the default xterm palette, but
I really hate the contrast of its default blue on black, so switch
to the palette from my xterm config.
This commit is contained in:
Wez Furlong committed 2018-01-27 22:17:31 -08:00
1 parent 1d4fc17187
commit 0ab8cf1eec
3 files changed
+45 -16

No files matched your search

+26 -14
View File
@@ -46,6 +46,7 @@ pub struct ColorPalette {
colors: [RgbColor; 256],
foreground: RgbColor,
background: RgbColor,
cursor: RgbColor,
}
impl ColorPalette {
@@ -57,6 +58,10 @@ impl ColorPalette {
&ColorAttribute::Rgb(color) => color,
}
}
pub fn cursor(&self) -> RgbColor {
self.cursor
}
}
impl Default for ColorPalette {
@@ -67,20 +72,20 @@ impl Default for ColorPalette {
// The XTerm ansi color set
static ANSI: [RgbColor; 16] = [
RgbColor{ red: 0x00, green: 0x00, blue: 0x00}, // Black
RgbColor{ red: 0x80, green: 0x00, blue: 0x00}, // Maroon
RgbColor{ red: 0x00, green: 0x80, blue: 0x00}, // Green
RgbColor{ red: 0x80, green: 0x80, blue: 0x00}, // Olive
RgbColor{ red: 0x00, green: 0x00, blue: 0x80}, // Navy
RgbColor{ red: 0x80, green: 0x00, blue: 0x80}, // Purple
RgbColor{ red: 0x00, green: 0x80, blue: 0x80}, // Teal
RgbColor{ red: 0xc0, green: 0xc0, blue: 0xc0}, // Silver
RgbColor{ red: 0x80, green: 0x80, blue: 0x80}, // Grey
RgbColor{ red: 0xff, green: 0x00, blue: 0x00}, // Red
RgbColor{ red: 0x00, green: 0xff, blue: 0x00}, // Lime
RgbColor{ red: 0xff, green: 0xff, blue: 0x00}, // Yellow
RgbColor{ red: 0x00, green: 0x00, blue: 0xff}, // Blue
RgbColor{ red: 0xff, green: 0x00, blue: 0xff}, // Fuschia
RgbColor{ red: 0x00, green: 0xff, blue: 0xff}, // Aqua
RgbColor{ red: 0xcc, green: 0x55, blue: 0x55}, // Maroon
RgbColor{ red: 0x55, green: 0xcc, blue: 0x55}, // Green
RgbColor{ red: 0xcd, green: 0xcd, blue: 0x55}, // Olive
RgbColor{ red: 0x54, green: 0x55, blue: 0xcb}, // Navy
RgbColor{ red: 0xcc, green: 0x55, blue: 0xcc}, // Purple
RgbColor{ red: 0x7a, green: 0xca, blue: 0xca}, // Teal
RgbColor{ red: 0xcc, green: 0xcc, blue: 0xcc}, // Silver
RgbColor{ red: 0x55, green: 0x55, blue: 0x55}, // Grey
RgbColor{ red: 0xff, green: 0x55, blue: 0x55}, // Red
RgbColor{ red: 0x55, green: 0xff, blue: 0x55}, // Lime
RgbColor{ red: 0xff, green: 0xff, blue: 0x55}, // Yellow
RgbColor{ red: 0x55, green: 0x55, blue: 0xff}, // Blue
RgbColor{ red: 0xff, green: 0x55, blue: 0xff}, // Fuschia
RgbColor{ red: 0x55, green: 0xff, blue: 0xff}, // Aqua
RgbColor{ red: 0xff, green: 0xff, blue: 0xff}, // White
];
@@ -136,10 +141,17 @@ impl Default for ColorPalette {
let foreground = colors[249]; // Grey70
let background = colors[AnsiColor::Black as usize];
let cursor = RgbColor {
red: 0x52,
green: 0xad,
blue: 0x70,
};
ColorPalette {
colors,
foreground,
background,
cursor,
}
}
}
+6
View File
@@ -427,6 +427,12 @@ impl TerminalState {
let len = screen.lines.len();
(width, &screen.lines[len - height..len])
}
/// Returns the 0-based cursor position relative to the top left of
/// the visible screen
pub fn cursor_pos(&self) -> (usize, usize) {
(self.cursor_x, self.cursor_y)
}
}
pub struct Terminal {
+13 -2
View File
@@ -137,7 +137,9 @@ impl<'a> TerminalWindow<'a> {
let (phys_cols, lines) = self.terminal.visible_cells();
for line in lines.iter() {
let (cursor_x, cursor_y) = self.terminal.cursor_pos();
for (line_idx, line) in lines.iter().enumerate() {
let mut x = 0 as isize;
y += cell_height as isize;
@@ -146,6 +148,11 @@ impl<'a> TerminalWindow<'a> {
if cell_idx > phys_cols {
break;
}
let is_cursor_cell = if cell_idx == cursor_x && line_idx == cursor_y {
true
} else {
false
};
let has_color = self.font.has_color(info.font_idx)?;
let ft_glyph = self.font.load_glyph(info.font_idx, info.glyph_pos)?;
@@ -169,7 +176,11 @@ impl<'a> TerminalWindow<'a> {
y - cell_height as isize,
info.num_cells as usize * self.cell_width as usize,
cell_height,
bg_color.into(),
if is_cursor_cell {
palette.cursor()
} else {
bg_color
}.into(),
);
let scale = if (info.x_advance / info.num_cells as f64).floor() > self.cell_width {