From d12fe53ab85cccaa110f7c9a5c891f5f6b09e8cf Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 3 Jan 2024 01:46:38 -0800 Subject: [PATCH] persistent scrollback buffer but not too large so it doesn't bog down --- changelog.txt | 1 + docs/gui/launcher.rst | 7 +++++-- gui/launcher.lua | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 772ad70895..c6caa5555b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -45,6 +45,7 @@ Template for new versions: - `confirm`: updated confirmation dialogs to use clickable widgets and draggable windows - `confirm`: added confirmation dialog for right clicking out of the trade agreement screen (so your trade agreement selections aren't lost) - `gui/autobutcher`: interface redesigned to better support mouse control +- `gui/launcher`: now persists the most recent 32KB of command output even if you close it and bring it back up ## Removed diff --git a/docs/gui/launcher.rst b/docs/gui/launcher.rst index 04d81b41f3..4c5c6da1a8 100644 --- a/docs/gui/launcher.rst +++ b/docs/gui/launcher.rst @@ -85,8 +85,11 @@ Once you run a command, the lower panel will switch to command output mode, where you can see any text the command printed to the screen. If you want to see more help text as you run further commands, you can switch the lower panel back to help mode with :kbd:`Ctrl`:kbd:`T`. The output text is kept for all the -commands you run while the launcher window is open, but is cleared if you -dismiss the launcher window and bring it back up. +commands you run while the launcher window is open (up to 256KB of text), but +only the most recent 32KB of text is saved if you dismiss the launcher window +and bring it back up. Command output is also printed to the external DFHack +console (the one you can show with `show` on Windows) or the parent terminal on +Unix-based systems if you need a longer history of the output. Command history --------------- diff --git a/gui/launcher.lua b/gui/launcher.lua index cfb8d38efc..79a4c55b9d 100644 --- a/gui/launcher.lua +++ b/gui/launcher.lua @@ -23,6 +23,9 @@ local TITLE = 'DFHack Launcher' -- within 1s when adding text to a full scrollback buffer local SCROLLBACK_CHARS = 2^18 +-- smaller amount of scrollback persisted between gui/launcher invocations +local PERSISTED_SCROLLBACK_CHARS = 2^15 + config = config or json.open('dfhack-config/launcher.json') base_freq = base_freq or json.open('hack/data/base_command_counts.json') user_freq = user_freq or json.open('dfhack-config/command_counts.json') @@ -340,6 +343,8 @@ HelpPanel.ATTRS{ frame_inset={t=0, l=1, r=1, b=0}, } +persisted_scrollback = persisted_scrollback or '' + -- this text is intentionally unwrapped so the in-UI wrapping can do the job local DEFAULT_HELP_TEXT = [[Welcome to DFHack! @@ -388,7 +393,7 @@ function HelpPanel:init() STANDARDSCROLL_PAGEUP='-halfpage', STANDARDSCROLL_PAGEDOWN='+halfpage', }, - text_to_wrap=''}, + text_to_wrap=persisted_scrollback}, }, }, } @@ -419,6 +424,7 @@ function HelpPanel:add_output(output) label:scroll('end') line_num = label.start_line_num end + persisted_scrollback = text:sub(-PERSISTED_SCROLLBACK_CHARS) HelpPanel_update_label(label, text) if line_num == 1 then label:scroll(text_height - 1) @@ -455,6 +461,13 @@ function HelpPanel:postComputeFrame() HelpPanel_update_label(self.subviews.help_label, wrapped_help) end +function HelpPanel:postUpdateLayout() + if not self.sentinel then + self.sentinel = true + self.subviews.output_label:scroll('end') + end +end + ---------------------------------- -- MainPanel --