Skip to content

Commit 51698ad

Browse files
committed
write proper docs for the launcher
and make the gui match the behavior described in the docs
1 parent 019cb73 commit 51698ad

2 files changed

Lines changed: 104 additions & 17 deletions

File tree

docs/gui/launcher.rst

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,63 @@
11
gui/launcher
22
============
3+
Tags: fort, adventure, legends, system
4+
:dfhack-keybind:`gui/launcher`
35

4-
In-game DFHack command launcher and help browser, with command autocomplete.
6+
In-game DFHack command launcher with integrated help. It is the primary GUI
7+
interface for running DFHack commands.
8+
9+
Usage::
10+
11+
gui/launcher [initial commandline]
12+
13+
Examples:
14+
15+
- ``gui/launcher``
16+
Opens the launcher dialog with the default help message.
17+
- ``gui/launcher prospect --show ores,veins``
18+
Opens the launcher dialog with the given command visible in the edit area,
19+
ready for modification or running. Commands related to the ``prospect``
20+
command will appear in the autocomplete list, and help text for the
21+
``prospect`` command will be displayed in the help area.
22+
23+
**Editing and running commands**
24+
25+
Enter the command you want to run by typing its name. If you want to start over,
26+
:kbd:`Ctrl`:kbd:`C` will clear the line. When you are happy with the command,
27+
hit :kbd:`Enter` to run it. Any output from the command will appear in the help
28+
area. If you want to run the command and close the dialog so you can get back to
29+
the game, use :kbd:`Shift`:kbd:`Enter` instead. The dialog also closes
30+
automatically if you run a command that brings up a new GUI screen. In the cases
31+
where the dialog does not reappear to show you the command output, the output
32+
(if any) will appear in the DFHack terminal console.
33+
34+
**Autocomplete**
35+
36+
As you type, autocomplete options for DFHack commands appear in the right
37+
column. If the first word of what you've typed matches a valid command, then the
38+
autocomplete options will also include commands that have similar functionality
39+
to the one that you've named. Hit :kbd:`Tab` or :kbd:`Shift`:kbd:`Tab` to cycle
40+
through the autocomplete options. Hit :kbd:`Alt`:kbd:`Left` if you want to undo
41+
the autocomplete and go back to the text you had before you hit :kbd:`Tab`.
42+
43+
**Context-sensitive help**
44+
45+
When you start ``gui/launcher`` without parameters, it shows some useful
46+
information in the help area about how to get started.
47+
48+
Once you have typed (or autocompleted) a word that matches a valid command, the
49+
help area shows the help for that command, including usage instructions. You can
50+
scroll the help text page by page with :kbd:`PgUp` and :kbd:`PgDn` or line by
51+
line with :kbd:`Ctrl`:kbd:`Up` and :kbd:`Ctrl`:kbd:`Down`.
52+
53+
**Command history**
54+
55+
``gui/launcher`` keeps a history of commands you have run to let you quickly run
56+
those commands again. You can scroll through your command history with the
57+
:kbd:`Up` and :kbd:`Down` cursor keys, or you can search your history for
58+
something specific with the :kbd:`Alt`:kbd:`S` hotkey. After you hit
59+
:kbd:`Alt`:kbd:`S`, start typing to search your history for a match. To find the
60+
next match for what you've already typed, hit :kbd:`Alt`:kbd:`S` again. You can
61+
run the matched command immediately with :kbd:`Enter` (or
62+
:kbd:`Shift`:kbd:`Enter`), or hit :kbd:`Esc` to edit the command before running
63+
it.

gui/launcher.lua

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- The DFHack in-game launcher
1+
-- The DFHack in-game command launcher
22
--@module=true
33

44
local gui = require('gui')
@@ -161,10 +161,12 @@ function EditPanel:init()
161161
on_change=self:callback('on_search_text'),
162162
on_unfocus=function()
163163
self:reset_history_idx()
164+
self.subviews.search.text = ''
164165
self.subviews.editfield:setFocus(true) end,
165166
on_submit=function()
166-
self.subviews.search.text = ''
167-
self.on_submit(self.subviews.editfield.text) end},
167+
self.on_submit(self.subviews.editfield.text) end,
168+
on_submit2=function()
169+
self.on_submit2(self.subviews.editfield.text) end},
168170
}
169171
end
170172

@@ -240,7 +242,10 @@ function EditPanel:onInput(keys)
240242
self:on_search_text(self.subviews.search.text)
241243
return true
242244
elseif keys.A_CARE_MOVE_W then -- Alt-Left
243-
self.on_change(self:pop_text())
245+
local text = self:pop_text()
246+
if text then
247+
self.on_change(text)
248+
end
244249
return true
245250
end
246251
end
@@ -250,6 +255,21 @@ end
250255
--
251256
HelpPanel = defclass(HelpPanel, widgets.Panel)
252257

258+
local DEFAULT_HELP_TEXT = [[Welcome to DFHack!
259+
260+
Type a command to see it's help text here. Hit ENTER
261+
to run the command, or Shift-ENTER to run the
262+
command and close this dialog. The dialog also
263+
closes automatically if you run a command that shows
264+
a new GUI screen.
265+
266+
Not sure what to do? Run the "help" command to get
267+
started.
268+
269+
To see help for this command launcher, type
270+
"launcher" and autocomplete to "gui/launcher" with
271+
the TAB key.]]
272+
253273
function HelpPanel:init()
254274
self.cur_entry = ""
255275

@@ -264,7 +284,7 @@ function HelpPanel:init()
264284
STANDARDSCROLL_PAGEUP='-page',
265285
STANDARDSCROLL_PAGEDOWN='+page',
266286
},
267-
text_to_wrap='Welcome to DFHack!'}
287+
text_to_wrap=DEFAULT_HELP_TEXT}
268288
}
269289
end
270290

@@ -369,12 +389,16 @@ function LauncherUI:do_autocomplete(delta)
369389
self.input_is_worth_saving = false
370390
end
371391

372-
local function launch(initial_help)
392+
local function launch(kwargs)
373393
view = LauncherUI{parent_focus=dfhack.gui.getCurFocus(true)}
374394
view:show()
375395
view:on_edit_input('')
376-
if initial_help then
377-
view.subviews.help:set_help(initial_help)
396+
if kwargs.initial_help then
397+
view.subviews.help:set_help(kwargs.initial_help)
398+
end
399+
if kwargs.command then
400+
view.subviews.edit:set_text(kwargs.command)
401+
view:on_edit_input(kwargs.command)
378402
end
379403
end
380404

@@ -389,19 +413,22 @@ function LauncherUI:run_command(reappear, text)
389413
dfhack.addCommandToHistory(HISTORY_ID, HISTORY_FILE, text)
390414
add_history(history, history_set, text)
391415
local output = dfhack.run_command_silent(text)
392-
if not reappear then
393-
return
394-
end
395416
-- if we displayed a new dfhack screen, don't come back up even if reappear
396-
-- is true so the user can interact with the new screen
417+
-- is true. otherwise, the user can't interact with the new screen. if we're
418+
-- not reappearing with the output, print the output to the console.
397419
local parent_focus = dfhack.gui.getCurFocus(true)
398-
if parent_focus:startswith('dfhack/') and
399-
parent_focus ~= self.parent_focus then
420+
if not reappear or (parent_focus:startswith('dfhack/') and
421+
parent_focus ~= self.parent_focus) then
422+
if #output > 0 then
423+
print('Output from command run from gui/launcher:')
424+
print('> '..text)
425+
print(output)
426+
end
400427
return
401428
end
402429
-- reappear and show the command output
403430
local initial_help = ('> %s\n\n%s'):format(text, output)
404-
launch(initial_help)
431+
launch({initial_help=initial_help})
405432
end
406433

407434
function LauncherUI:getWantedFrameSize()
@@ -466,5 +493,6 @@ if view then
466493
-- hitting the launcher hotkey while it is open should close the dialog
467494
view:dismiss()
468495
else
469-
launch()
496+
local args = {...}
497+
launch({command=table.concat(args, ' ')})
470498
end

0 commit comments

Comments
 (0)