tui: show the Computing... progress as a real Modal (was invisible)

The Renderer-overlay approach to the global progress box didn't render. Use a
proper Modal like the palette / file dialog, driven by a plain bool
'computing_open' raised when a source starts and lowered when it ends or
aborts. The tick handler stays ahead of the modal guard, so the script keeps
running (and the screen behind it keeps updating) while the modal is shown;
computing_open is also added to the guard so stray keys are ignored mid-load.
The console screen's own Computing block was already removed, so no duplicate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-03 19:11:27 +02:00
parent 53eb79c760
commit ac2edd90c4
3 changed files with 19 additions and 15 deletions

View File

@@ -299,6 +299,7 @@ void Tui::Source(const std::string &filename) {
source_origin_screen = screen_idx; // a sourced line that leaves this screen aborts source_origin_screen = screen_idx; // a sourced line that leaves this screen aborts
in_source = true; in_source = true;
loading = true; loading = true;
computing_open = true; // raise the global "Computing…" progress modal
if (!screen_ptr) { if (!screen_ptr) {
// Headless fallback (e.g. tests): drain synchronously. // Headless fallback (e.g. tests): drain synchronously.
@@ -352,6 +353,7 @@ void Tui::ProcessNextSourceLine() {
+ " is interactive (would open a screen) — aborting."); + " is interactive (would open a screen) — aborting.");
screen_idx = source_origin_screen; screen_idx = source_origin_screen;
loading.store(false); loading.store(false);
computing_open = false;
tick_in_flight.store(false); tick_in_flight.store(false);
in_source = loading_prev_in_source; in_source = loading_prev_in_source;
return; return;
@@ -364,6 +366,7 @@ void Tui::ProcessNextSourceLine() {
Print("source: " + loading_filename Print("source: " + loading_filename
+ " (" + std::to_string(loading_executed) + " line(s))"); + " (" + std::to_string(loading_executed) + " line(s))");
loading.store(false); loading.store(false);
computing_open = false;
tick_in_flight.store(false); tick_in_flight.store(false);
in_source = loading_prev_in_source; in_source = loading_prev_in_source;
} }

View File

@@ -59,31 +59,31 @@ void Tui::Run() {
auto with_error = with_confirm auto with_error = with_confirm
| Modal(BuildErrorModal(), &error_open); | Modal(BuildErrorModal(), &error_open);
// Global "Computing…" overlay while a script loads — visible on any screen // Global "Computing…" progress modal while a script loads — a proper Modal
// (not just the console), so opening a script from the dashboard shows // (like the palette / file dialog), so it shows on any screen, e.g. when a
// progress instead of looking frozen. // script is opened from the dashboard. The Renderer re-reads the live
auto with_loading = Renderer(with_error, [this, with_error] { // progress every frame.
Element base = with_error->Render(); auto computing_modal = Renderer([this] {
if (!loading) return base;
std::string progress = std::to_string(loading_executed) + " / " std::string progress = std::to_string(loading_executed) + " / "
+ std::to_string((int)loading_lines.size()) + " lines"; + std::to_string((int)loading_lines.size()) + " lines";
Element modal = vbox({ return vbox({
text(" Computing… ") | bold | center, text(" Computing… ") | bold | center,
separator(), separator(),
text(loading_filename) | center, text(loading_filename) | center,
text(progress) | center, text(progress) | center,
}) | borderDouble | size(WIDTH, GREATER_THAN, 40); }) | borderDouble | size(WIDTH, GREATER_THAN, 40);
return dbox({base, modal | center});
}); });
auto with_loading = with_error | Modal(computing_modal, &computing_open);
auto root = CatchEvent(with_loading, [this](Event e) { auto root = CatchEvent(with_loading, [this](Event e) {
// Source ticks drive the line-by-line loader; handle them on ANY screen // Source ticks drive the line-by-line loader; handle them on ANY screen
// so `source` works from the dashboard, not only the console. // (and before the modal guard) so `source` keeps running while the
// Computing modal is up.
if (e == Event::Special("\x02tick")) { ProcessNextSourceLine(); return true; } if (e == Event::Special("\x02tick")) { ProcessNextSourceLine(); return true; }
// Modals own their events while open. Error modal sits on top. // Modals own their events while open. Error modal sits on top.
if (error_open || confirm_open || palette_open if (error_open || confirm_open || palette_open
|| sigtype_dialog_open || file_dialog.open) return false; || sigtype_dialog_open || file_dialog.open || computing_open) return false;
// Ctrl-P opens the palette from any screen. // Ctrl-P opens the palette from any screen.
if (e == Event::CtrlP) { OpenPalette(); return true; } if (e == Event::CtrlP) { OpenPalette(); return true; }

View File

@@ -104,6 +104,7 @@ class Tui {
int loading_lineno; int loading_lineno;
bool loading_prev_in_source; bool loading_prev_in_source;
int source_origin_screen = 0; ///< screen a `source` started from; a sourced line that navigates away (opens an interactive screen) aborts it. int source_origin_screen = 0; ///< screen a `source` started from; a sourced line that navigates away (opens an interactive screen) aborts it.
bool computing_open = false; ///< drives the global "Computing…" progress modal while a script loads.
ftxui::ScreenInteractive *screen_ptr; ///< set in Run() so Source() can post events. ftxui::ScreenInteractive *screen_ptr; ///< set in Run() so Source() can post events.
// ---- Dashboard scroll state (0 = top; grows as the user scrolls down) ---- // ---- Dashboard scroll state (0 = top; grows as the user scrolls down) ----