diff options
author | Christian Duerr <contact@christianduerr.com> | 2017-12-10 00:33:58 +0100 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-12-24 09:46:54 -0800 |
commit | fe29b8c6873c82517a218067abbf56b64cae413b (patch) | |
tree | a2cff4b838448d9e45ed56374db363dbcf724259 /src | |
parent | 8195d7103498043270523bd81d703cb678cd11a2 (diff) | |
download | alacritty-fe29b8c6873c82517a218067abbf56b64cae413b.tar.gz alacritty-fe29b8c6873c82517a218067abbf56b64cae413b.zip |
Add custom box cursor for unfocused window
Diffstat (limited to 'src')
-rw-r--r-- | src/display.rs | 6 | ||||
-rw-r--r-- | src/event.rs | 1 | ||||
-rw-r--r-- | src/term/mod.rs | 48 |
3 files changed, 25 insertions, 30 deletions
diff --git a/src/display.rs b/src/display.rs index bfd62c32..8e3d8814 100644 --- a/src/display.rs +++ b/src/display.rs @@ -354,6 +354,7 @@ impl Display { // // TODO I wonder if the renderable cells iter could avoid the // mutable borrow + let window_focused = self.window.is_focused; self.renderer.with_api(config, &size_info, visual_bell_intensity, |mut api| { // Clear screen to update whole background with new color if background_color_changed { @@ -361,7 +362,10 @@ impl Display { } // Draw the grid - api.render_cells(terminal.renderable_cells(config, selection), glyph_cache); + api.render_cells( + terminal.renderable_cells(config, selection, window_focused), + glyph_cache, + ); }); } diff --git a/src/event.rs b/src/event.rs index c8fb83e9..894777fa 100644 --- a/src/event.rs +++ b/src/event.rs @@ -330,6 +330,7 @@ impl<N: Notify> Processor<N> { processor.ctx.terminal.dirty = true; processor.ctx.terminal.next_is_urgent = Some(false); } else { + processor.ctx.terminal.dirty = true; *hide_cursor = false; } diff --git a/src/term/mod.rs b/src/term/mod.rs index 86115171..da59a037 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -118,6 +118,7 @@ impl<'a> RenderableCellsIter<'a> { config: &'b Config, selection: Option<RangeInclusive<index::Linear>>, cursor_style: CursorStyle, + window_focused: bool, ) -> RenderableCellsIter<'b> { let cursor_index = Linear(cursor.line.0 * grid.num_cols().0 + cursor.col.0); @@ -132,10 +133,15 @@ impl<'a> RenderableCellsIter<'a> { config: config, colors: colors, cursor_cells: ArrayDeque::new(), - }.initialize(cursor_style) + }.initialize(cursor_style, window_focused) } - fn populate_block_cursor(&mut self) { + fn populate_block_cursor(&mut self, window_focused: bool) { + if !window_focused { + self.populate_cursor(font::BOX_CURSOR_CHAR, ' '); + return; + } + let (text_color, cursor_color) = if self.config.custom_cursor_colors() { ( Color::Named(NamedColor::CursorText), @@ -173,33 +179,14 @@ impl<'a> RenderableCellsIter<'a> { } fn populate_beam_cursor(&mut self) { - let mut cursor_cell = self.grid[self.cursor]; - self.cursor_cells.push_back(Indexed { - line: self.cursor.line, - column: self.cursor.col, - inner: cursor_cell, - }); - - let cursor_color = self.text_cursor_color(&cursor_cell); - cursor_cell.c = font::BEAM_CURSOR_CHAR; - cursor_cell.fg = cursor_color; - self.cursor_cells.push_back(Indexed { - line: self.cursor.line, - column: self.cursor.col, - inner: cursor_cell, - }); - - if self.is_wide_cursor(&cursor_cell) { - cursor_cell.c = ' '; - self.cursor_cells.push_back(Indexed { - line: self.cursor.line, - column: self.cursor.col + 1, - inner: cursor_cell, - }); - } + self.populate_cursor(font::BEAM_CURSOR_CHAR, ' '); } fn populate_underline_cursor(&mut self) { + self.populate_cursor(font::UNDERLINE_CURSOR_CHAR, font::UNDERLINE_CURSOR_CHAR); + } + + fn populate_cursor(&mut self, cursor: char, wide_cursor: char) { let mut cursor_cell = self.grid[self.cursor]; self.cursor_cells.push_back(Indexed { line: self.cursor.line, @@ -208,7 +195,7 @@ impl<'a> RenderableCellsIter<'a> { }); let cursor_color = self.text_cursor_color(&cursor_cell); - cursor_cell.c = font::UNDERLINE_CURSOR_CHAR; + cursor_cell.c = cursor; cursor_cell.fg = cursor_color; self.cursor_cells.push_back(Indexed { line: self.cursor.line, @@ -217,6 +204,7 @@ impl<'a> RenderableCellsIter<'a> { }); if self.is_wide_cursor(&cursor_cell) { + cursor_cell.c = wide_cursor; self.cursor_cells.push_back(Indexed { line: self.cursor.line, column: self.cursor.col + 1, @@ -243,11 +231,11 @@ impl<'a> RenderableCellsIter<'a> { }); } - fn initialize(mut self, cursor_style: CursorStyle) -> Self { + fn initialize(mut self, cursor_style: CursorStyle, window_focused: bool) -> Self { if self.cursor_is_visible() { match cursor_style { CursorStyle::Block => { - self.populate_block_cursor(); + self.populate_block_cursor(window_focused); }, CursorStyle::Beam => { self.populate_beam_cursor(); @@ -971,6 +959,7 @@ impl Term { &'b self, config: &'b Config, selection: Option<&'b Selection>, + window_focused: bool, ) -> RenderableCellsIter { let selection = selection.and_then(|s| s.to_span(self)) .map(|span| span.to_range()); @@ -983,6 +972,7 @@ impl Term { config, selection, self.cursor_style.unwrap_or(self.default_cursor_style), + window_focused, ) } |