summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-15 17:46:47 +0100
committersalmonik <salmonik@tuta.io>2026-11-15 17:46:47 +0100
commit1eebc384f60b73f8c0dbcd2dbcb1ce578702be46 (patch)
tree7727b565d30698024cdf230bf035a8273a135f7d /src
parent0.6.1: redraw from the caret row, not the block height (diff)
downloadagent686-1eebc384f60b73f8c0dbcd2dbcb1ce578702be46.tar.gz
agent686-1eebc384f60b73f8c0dbcd2dbcb1ce578702be46.zip
0.6.2: resizing no longer duplicates the prompt
The terminal reflows the input block and moves the caret with it, so drawing on resize produced a second copy. Recompute the caret's row and let the next redraw work from the reflowed block. Documented the dependency on reflowing terminals.
Diffstat (limited to '')
-rw-r--r--src/line.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/line.rs b/src/line.rs
index 613dffe..2b6c894 100644
--- a/src/line.rs
+++ b/src/line.rs
@@ -58,12 +58,14 @@ impl Editor {
58 draw(prompt, &buffer, cursor, &mut state)?; 58 draw(prompt, &buffer, cursor, &mut state)?;
59 } 59 }
60 Event::Resize(_, _) => { 60 Event::Resize(_, _) => {
61 // The terminal reflowed the block we were tracking, so the 61 // The terminal has already reflowed the block and moved the
62 // old row count is meaningless. Start a fresh prompt line 62 // caret with it, so drawing again here would duplicate the
63 // rather than risk erasing output above it. 63 // prompt. Recompute only where the caret now sits relative
64 println!(); 64 // to the block; the next redraw moves up from there.
65 state = DrawState::default(); 65 let width = terminal_width();
66 draw(prompt, &buffer, cursor, &mut state)?; 66 let (cursor_row, _) = layout(prompt, &buffer, cursor, width);
67 state.cursor_row = cursor_row;
68 state.rows = layout(prompt, &buffer, buffer.len(), width).0 + 1;
67 } 69 }
68 Event::Key(key) if key.kind == KeyEventKind::Press => { 70 Event::Key(key) if key.kind == KeyEventKind::Press => {
69 match handle_key(key, &mut buffer, &mut cursor, self) { 71 match handle_key(key, &mut buffer, &mut cursor, self) {