From eb6354c8d2e13e6d9bb8d810bf45e5c1cd491d74 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 7 Dec 2021 22:53:08 -0500 Subject: fix some cursor position and visibility issues while scrolling --- src/history.rs | 28 +++++++++++++++++++--------- src/state.rs | 19 ++++++++++++++++--- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/history.rs b/src/history.rs index 9b4310e..7e8a836 100644 --- a/src/history.rs +++ b/src/history.rs @@ -29,32 +29,41 @@ impl History { out: &mut textmode::Output, repl_lines: usize, focus: Option, + scrolling: bool, offset: time::UtcOffset, ) -> anyhow::Result<()> { let mut used_lines = repl_lines; - let mut pos = None; + let mut cursor = None; for (idx, entry) in self.entries.iter().enumerate().rev() { let mut entry = entry.lock_arc().await; let focused = focus.map_or(false, |focus| idx == focus); - let last_row = entry.lines(self.size.1, focused); + let last_row = entry.lines(self.size.1, focused && !scrolling); used_lines += 1 + std::cmp::min(6, last_row); if used_lines > self.size.0 as usize { break; } - if focused && used_lines == 1 && entry.running() { + if focused && !scrolling && used_lines == 1 && entry.running() { used_lines = 2; } out.move_to( (self.size.0 as usize - used_lines).try_into().unwrap(), 0, ); - entry.render(out, self.size.1, focused, offset); - if focused { - pos = Some(out.screen().cursor_position()); + entry.render(out, self.size.1, focused, scrolling, offset); + if focused && !scrolling { + cursor = Some(( + out.screen().cursor_position(), + out.screen().hide_cursor(), + )); } } - if let Some(pos) = pos { + if let Some((pos, hide)) = cursor { out.move_to(pos.0, pos.1); + if hide { + out.write(b"\x1b[?25l"); + } else { + out.write(b"\x1b[?25h"); + } } Ok(()) } @@ -177,6 +186,7 @@ impl HistoryEntry { out: &mut textmode::Output, width: u16, focused: bool, + scrolling: bool, offset: time::UtcOffset, ) { out.set_bgcolor(textmode::Color::Rgb(32, 32, 32)); @@ -240,7 +250,7 @@ impl HistoryEntry { out.write(b"\x1b[?25l"); out.reset_attributes(); } else { - let last_row = self.lines(width, focused); + let last_row = self.lines(width, focused && !scrolling); if last_row > 5 { out.write(b"\r\n"); out.set_fgcolor(textmode::color::BLUE); @@ -270,7 +280,7 @@ impl HistoryEntry { } out_row += 1; } - if focused { + if focused && !scrolling { if let Some(row) = cursor_found { if screen.hide_cursor() { out.write(b"\x1b[?25l"); diff --git a/src/state.rs b/src/state.rs index 2cc24c5..75f7dfd 100644 --- a/src/state.rs +++ b/src/state.rs @@ -202,14 +202,20 @@ impl State { Scene::Readline => match self.focus { Focus::Readline => { self.history - .render(out, self.readline.lines(), None, self.offset) + .render( + out, + self.readline.lines(), + None, + false, + self.offset, + ) .await?; self.readline.render(out, true, self.offset).await?; } Focus::History(idx) => { if self.hide_readline { self.history - .render(out, 0, Some(idx), self.offset) + .render(out, 0, Some(idx), false, self.offset) .await?; } else { self.history @@ -217,6 +223,7 @@ impl State { out, self.readline.lines(), Some(idx), + false, self.offset, ) .await?; @@ -227,7 +234,13 @@ impl State { } Focus::Scrolling(idx) => { self.history - .render(out, self.readline.lines(), idx, self.offset) + .render( + out, + self.readline.lines(), + idx, + true, + self.offset, + ) .await?; self.readline .render(out, idx.is_none(), self.offset) -- cgit v1.2.3-54-g00ecf