From 4a020df74e77be497193f265fa666f363a258d1b Mon Sep 17 00:00:00 2001 From: "K. Isom" Date: Tue, 17 Nov 2026 15:02:51 -0800 Subject: [PATCH] C-l and C-k l repaint the whole terminal C-l only cleared the status line and C-k l asked for nothing, and the terminal frame then sent only what ncurses believed had changed, so output another program wrote to the terminal stayed on screen. Both now request a full redraw, which the terminal honors with clearok(curscr); the GUI repaints every frame already. Co-Authored-By: Claude Opus 5.5 --- Command.cc | 3 +++ Editor.h | 19 +++++++++++++++++++ ImGuiFrontend.cc | 4 +++- TerminalFrontend.cc | 6 ++++++ tests/test_audit_regressions.cc | 23 +++++++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/Command.cc b/Command.cc index dbc6fc3..5e67808 100644 --- a/Command.cc +++ b/Command.cc @@ -1495,6 +1495,8 @@ cmd_quit_now(CommandContext &ctx) static bool cmd_refresh(CommandContext &ctx) { + // C-l: repaint the whole screen, whatever else this cancels. + ctx.editor.RequestFullRedraw(); // C-g is mapped to Refresh and acts as a general cancel key. // Cancel visual-line (multicursor) mode if active. if (Buffer *buf = ctx.editor.CurrentBuffer()) { @@ -5316,6 +5318,7 @@ cmd_reload_buffer(CommandContext &ctx) } ctx.editor.SetStatus(std::string("Reloaded ") + filename); ensure_cursor_visible(ctx.editor, *buf); + ctx.editor.RequestFullRedraw(); return true; } diff --git a/Editor.h b/Editor.h index fd97eff..8fcd3b2 100644 --- a/Editor.h +++ b/Editor.h @@ -202,6 +202,24 @@ public: } + // Ask the frontend to repaint the whole screen on its next draw (C-l, + // reload). The terminal otherwise sends only what ncurses believes + // changed, so output another program wrote to the terminal would stay. + void RequestFullRedraw() + { + full_redraw_requested_ = true; + } + + + // Returns whether a full redraw was requested, and clears the request. + bool ConsumeFullRedraw() + { + const bool on = full_redraw_requested_; + full_redraw_requested_ = false; + return on; + } + + void SetQuitConfirmPending(bool on) { quit_confirm_pending_ = on; @@ -630,6 +648,7 @@ private: // Quit state bool quit_requested_ = false; bool new_window_requested_ = false; + bool full_redraw_requested_ = false; bool quit_confirm_pending_ = false; bool close_confirm_pending_ = false; // awaiting y/N to save-before-close bool close_after_save_ = false; // if true, close buffer after successful Save/SaveAs diff --git a/ImGuiFrontend.cc b/ImGuiFrontend.cc index e873aa1..3d0f7d2 100644 --- a/ImGuiFrontend.cc +++ b/ImGuiFrontend.cc @@ -585,7 +585,9 @@ GUIFrontend::Step(Editor &ed, bool &running) } } - // Draw + // Draw. Every frame repaints the whole window, so a full-redraw + // request (C-l, reload) needs nothing more than clearing. + (void) wed.ConsumeFullRedraw(); ws.renderer.Draw(wed); // Render diff --git a/TerminalFrontend.cc b/TerminalFrontend.cc index 9b0343c..aada4ea 100644 --- a/TerminalFrontend.cc +++ b/TerminalFrontend.cc @@ -138,6 +138,12 @@ TerminalFrontend::Step(Editor &ed, bool &running) if (handled > 0) timeout(16); + // C-l or a reload: make the next refresh repaint every cell. + if (ed.ConsumeFullRedraw()) { + clearok(curscr, TRUE); + changed = true; + } + if (ed.QuitRequested()) { running = false; } diff --git a/tests/test_audit_regressions.cc b/tests/test_audit_regressions.cc index 0f9a803..2c9634b 100644 --- a/tests/test_audit_regressions.cc +++ b/tests/test_audit_regressions.cc @@ -2406,3 +2406,26 @@ TEST(Audit_B7_SanitizeSpans_WholeCharacters) ASSERT_TRUE(out[3].kind == TokenKind::Error); ASSERT_TRUE(out[4].kind == TokenKind::Error); // the earlier-starting span wins } + + +// C-l and C-k l ask the frontend for a full repaint: the terminal must +// repaint every cell, not only what ncurses believes changed, so output +// another program wrote to the terminal is cleared. +TEST(Redraw_RefreshAndReloadRequestFullRedraw) +{ + TempDir d("redraw"); + const std::string file = (d.path / "r.txt").string(); + std::ofstream(file) << "disk\n"; + TestHarness h; + Editor &ed = h.EditorRef(); + std::string err; + ASSERT_TRUE(ed.OpenFile(file, err)); + ASSERT_TRUE(!ed.ConsumeFullRedraw()); + + ASSERT_TRUE(h.Exec(CommandId::Refresh)); + ASSERT_TRUE(ed.ConsumeFullRedraw()); + ASSERT_TRUE(!ed.ConsumeFullRedraw()); // consumed + + ASSERT_TRUE(h.Exec(CommandId::ReloadBuffer)); + ASSERT_TRUE(ed.ConsumeFullRedraw()); +}