Skip to content

Commit

Permalink
Merge pull request #917 from myk002/myk_persistent_scrollback
Browse files Browse the repository at this point in the history
[gui/launcher] keep persistent scrollback buffer
  • Loading branch information
myk002 authored Jan 3, 2024
2 parents d116a91 + d12fe53 commit 3d79df3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions docs/gui/launcher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------
Expand Down
15 changes: 14 additions & 1 deletion gui/launcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -388,7 +393,7 @@ function HelpPanel:init()
STANDARDSCROLL_PAGEUP='-halfpage',
STANDARDSCROLL_PAGEDOWN='+halfpage',
},
text_to_wrap=''},
text_to_wrap=persisted_scrollback},
},
},
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
--
Expand Down

0 comments on commit 3d79df3

Please sign in to comment.