From 21bff53c31973df9dfc9a5ee9bcee5b1c2004ea5 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 7 Jan 2024 14:36:59 -0800 Subject: Be more efficient with full screen refreshes. xterm has some bad flickering if I just naively repaint the whole screen every time. We can easily track whether we need to repaint the whole screen or just the line. --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 5a0d639..8e0cff8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use term::Key; enum Mode { Insert, Paste, + MultilinePaste, Normal, } @@ -213,6 +214,18 @@ impl StateHistory { } (Mode::Paste, Mode::Paste) => (), (Mode::Paste, _) => { + let Ok((_, col)) = term::cursor_pos(&mut self.stdin) else { + return; + }; + self.cursor_col = col; + let _ = self.repaint_line_full(); + let _ = stdout().flush(); + } + (Mode::MultilinePaste, Mode::MultilinePaste) => (), + (Mode::MultilinePaste, Mode::Paste) => { + return; + } + (Mode::MultilinePaste, _) => { let Ok((_, col)) = term::cursor_pos(&mut self.stdin) else { return; }; @@ -256,7 +269,7 @@ fn edit(file: &OsStr) -> Result<(), Box> { let c = term::read_key(&mut state.stdin)?; match c { Key::Timeout => { - if state.mode != Mode::Paste { + if state.mode != Mode::Paste && state.mode != Mode::MultilinePaste { continue; } state.set_mode(Mode::Insert); @@ -344,7 +357,7 @@ fn edit(file: &OsStr) -> Result<(), Box> { let _ = stdout().flush(); } Key::Char(b'\r') => { - state.set_mode(Mode::Paste); + state.set_mode(Mode::MultilinePaste); state.buf = state.buf.insert( state .buf -- cgit v1.3.1