rendering now respects cursor visibility
This commit adds some plumbing for describing the cursor shape (block, line, blinking etc) and visibility, and feeds that through the mux and render layers. The renderer now knows to omit the cursor when it is not visible.
This commit is contained in:
1 parent
ce45a0ee01
commit
5abc4e543e
7 files changed
+40
-6
No files matched your search
@@ -25,6 +25,7 @@ use std::sync::Arc;
|
||||
use term::color::ColorPalette;
|
||||
use term::{CursorPosition, Line, Underline};
|
||||
use termwiz::color::RgbColor;
|
||||
use termwiz::surface::CursorShape;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
struct RowsAndCols {
|
||||
@@ -1053,6 +1054,7 @@ impl TermWindow {
|
||||
CursorPosition {
|
||||
x: cursor.x,
|
||||
y: cursor.y + first_line_offset as i64,
|
||||
..cursor
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1158,6 +1160,7 @@ impl TermWindow {
|
||||
CursorPosition {
|
||||
x: cursor.x,
|
||||
y: cursor.y + first_line_offset as i64,
|
||||
..cursor
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1774,7 +1777,9 @@ impl TermWindow {
|
||||
palette: &ColorPalette,
|
||||
) -> (Color, Color) {
|
||||
let selected = selection.contains(&cell_idx);
|
||||
let is_cursor = line_idx as i64 == cursor.y && cursor.x == cell_idx;
|
||||
let is_cursor = line_idx as i64 == cursor.y
|
||||
&& cursor.x == cell_idx
|
||||
&& cursor.shape != CursorShape::Hidden;
|
||||
|
||||
let (fg_color, bg_color) = match (selected, is_cursor) {
|
||||
// Normally, render the cell as configured
|
||||
|
||||
+8
-2
@@ -395,8 +395,14 @@ impl RenderableInner {
|
||||
|
||||
impl Renderable for RenderableState {
|
||||
fn get_cursor_position(&self) -> CursorPosition {
|
||||
let (x, y) = self.inner.borrow().surface.cursor_position();
|
||||
CursorPosition { x, y: y as i64 }
|
||||
let surface = &self.inner.borrow().surface;
|
||||
let (x, y) = surface.cursor_position();
|
||||
let shape = surface.cursor_shape();
|
||||
CursorPosition {
|
||||
x,
|
||||
y: y as i64,
|
||||
shape,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_dirty_lines(&self) -> Vec<(usize, Cow<Line>, Range<usize>)> {
|
||||
|
||||
@@ -64,8 +64,14 @@ impl std::io::Write for RenderableState {
|
||||
|
||||
impl Renderable for RenderableState {
|
||||
fn get_cursor_position(&self) -> CursorPosition {
|
||||
let (x, y) = self.inner.borrow().surface.cursor_position();
|
||||
CursorPosition { x, y: y as i64 }
|
||||
let surface = &self.inner.borrow().surface;
|
||||
let (x, y) = surface.cursor_position();
|
||||
let shape = surface.cursor_shape();
|
||||
CursorPosition {
|
||||
x,
|
||||
y: y as i64,
|
||||
shape,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_dirty_lines(&self) -> Vec<(usize, Cow<Line>, Range<usize>)> {
|
||||
|
||||
@@ -80,6 +80,7 @@ pub enum Position {
|
||||
pub struct CursorPosition {
|
||||
pub x: usize,
|
||||
pub y: VisibleRowIndex,
|
||||
pub shape: termwiz::surface::CursorShape,
|
||||
}
|
||||
|
||||
pub mod color;
|
||||
|
||||
@@ -17,6 +17,7 @@ use termwiz::escape::osc::{ChangeColorPair, ColorOrQuery, ITermFileData, ITermPr
|
||||
use termwiz::escape::{Action, ControlCode, Esc, EscCode, OneBased, OperatingSystemCommand, CSI};
|
||||
use termwiz::hyperlink::Rule as HyperlinkRule;
|
||||
use termwiz::image::{ImageCell, ImageData, TextureCoordinate};
|
||||
use termwiz::surface::CursorShape;
|
||||
|
||||
struct TabStop {
|
||||
tabs: Vec<bool>,
|
||||
@@ -777,6 +778,7 @@ impl TerminalState {
|
||||
let new_position = CursorPosition {
|
||||
x: event.x,
|
||||
y: event.y as VisibleRowIndex,
|
||||
..self.mouse_position
|
||||
};
|
||||
|
||||
if new_position != self.mouse_position {
|
||||
@@ -1218,6 +1220,11 @@ impl TerminalState {
|
||||
CursorPosition {
|
||||
x: self.cursor.x,
|
||||
y: self.cursor.y + self.viewport_offset,
|
||||
shape: if self.cursor_visible {
|
||||
self.mouse_position.shape
|
||||
} else {
|
||||
CursorShape::Hidden
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
use termwiz::escape::csi::{Edit, EraseInDisplay, EraseInLine};
|
||||
use termwiz::escape::{OneBased, OperatingSystemCommand, CSI};
|
||||
use termwiz::surface::CursorShape;
|
||||
|
||||
struct TestHost {
|
||||
title: String,
|
||||
@@ -235,7 +236,11 @@ impl TestTerm {
|
||||
|
||||
fn assert_cursor_pos(&self, x: usize, y: i64, reason: Option<&str>) {
|
||||
let cursor = self.cursor_pos();
|
||||
let expect = CursorPosition { x, y };
|
||||
let expect = CursorPosition {
|
||||
x,
|
||||
y,
|
||||
shape: CursorShape::Default,
|
||||
};
|
||||
assert_eq!(
|
||||
cursor, expect,
|
||||
"actual cursor (left) didn't match expected cursor (right) reason={:?}",
|
||||
|
||||
@@ -181,6 +181,10 @@ impl Surface {
|
||||
(self.xpos, self.ypos)
|
||||
}
|
||||
|
||||
pub fn cursor_shape(&self) -> CursorShape {
|
||||
self.cursor_shape
|
||||
}
|
||||
|
||||
pub fn title(&self) -> &str {
|
||||
&self.title
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user