aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-01-07 14:36:59 -0800
committerRose Hogenson <rosehogenson@posteo.net>2024-01-07 14:36:59 -0800
commit21bff53c31973df9dfc9a5ee9bcee5b1c2004ea5 (patch)
tree7fa926057572e03746370abacf185b01a766994c /src
parent67701b76345eb99c11e27fe44a3ad806f4619cde (diff)
downloadeditor-21bff53c31973df9dfc9a5ee9bcee5b1c2004ea5.tar.zst
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.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs17
1 files changed, 15 insertions, 2 deletions
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,
}
@@ -217,6 +218,18 @@ impl StateHistory {
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;
+ };
+ self.cursor_col = col;
let _ = self.repaint_all();
let _ = self.repaint_line_full();
let _ = stdout().flush();
@@ -256,7 +269,7 @@ fn edit(file: &OsStr) -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
let _ = stdout().flush();
}
Key::Char(b'\r') => {
- state.set_mode(Mode::Paste);
+ state.set_mode(Mode::MultilinePaste);
state.buf = state.buf.insert(
state
.buf