Fix CMake build console: log area fills dialog, full log shown, scrolls to end

The build-result dialog packed its ScrolledWindow with
gtk_container_add(), which packs a GtkBox child with expand=FALSE,
so the log area stayed at its ~2-line natural height pinned to the
top and the rest of the 700x420 window was wasted space. Pack it
with gtk_box_pack_start(..., TRUE, TRUE, 0) so it fills the dialog.

Also drop the 6000-char tail truncation (the log now scrolls, so the
whole build log is visible), wrap long lines so cmake command lines
are readable without horizontal scrolling, and start scrolled to the
end of the log (via an idle callback, so the scroll happens after
realisation/allocation and lands on the true last line) where build
failures are.
This commit is contained in:
cnmcdee committed 2026-12-01 01:00:41 +00:00
1 parent 563870f9b7
commit cb95f5f73c
1 file changed
+26 -4
+26 -4
View File
@@ -4203,19 +4203,41 @@ static void show_build_result(const std::string& title,
r.ok ? std::string("Build succeeded.\nExecutable: ") + r.exe_path +
"\n\n"
: std::string("Build FAILED.\n\n");
// Keep the dialog readable: show the tail of the log.
// Show the full log: the text view scrolls, so a long build log is
// fully visible instead of only its tail.
std::string log = r.output;
if (log.size() > 6000) log = "[…]\n" + log.substr(log.size() - 6000);
GtkWidget* view = gtk_text_view_new();
gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);
gtk_text_view_set_monospace(GTK_TEXT_VIEW(view), TRUE);
// Wrap long lines (cmake command lines) so the whole log is readable
// without horizontal scrolling.
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_CHAR);
GtkTextBuffer* buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
gtk_text_buffer_set_text(buf, (head + log).c_str(), -1);
GtkWidget* scroll = gtk_scrolled_window_new(nullptr, nullptr);
gtk_container_add(GTK_CONTAINER(scroll), view);
gtk_container_add(
GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dlg))), scroll);
// Pack expanding: gtk_container_add() on the dialog's GtkBox packs
// with expand=FALSE, which left the log area at its ~2-line natural
// height pinned to the top of the dialog and wasted the rest of the
// window. Pack with expand+fill so the log fills the dialog.
gtk_box_pack_start(
GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))), scroll,
TRUE, TRUE, 0);
gtk_widget_show_all(dlg);
// Failures land at the end of the log: start scrolled there so the
// error is visible immediately; the user can scroll up for the rest.
// Do it in an idle callback, not right after show_all: scrolling
// before the dialog is realized/allocated computes against the
// not-yet-final size and lands a few lines short of the true end.
// The idle runs inside gtk_dialog_run's loop, after allocation.
g_idle_add([](gpointer data) -> gboolean {
GtkTextView* v = GTK_TEXT_VIEW(data);
GtkTextBuffer* b = gtk_text_view_get_buffer(v);
GtkTextIter end;
gtk_text_buffer_get_end_iter(b, &end);
gtk_text_view_scroll_to_iter(v, &end, 0.0, FALSE, 0.0, 0.0);
return FALSE;
}, view);
gtk_dialog_run(GTK_DIALOG(dlg));
gtk_widget_destroy(dlg);
}