-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown.lua - Steam version update #901
Conversation
Features: - Added support of screens: - Unit/Health/Description - Unit/Personality/Traits - Item/Description - Added name, age & profession of units to description - Improved markdown formatting (headers, line dividers) - By default, the file name is now “markdown_/Your_World_Name/_export.md” Docs: - Moved the helpstr to markdown.rst - Added tags - Improved docs - Added error messages with instructions Refactoring: - Refactored the code - Removed code for processing of unsupported screens (it had time & month processing, as well as logic for other screens - might be useful in the future) - Argument '-n' is now '-o' for "overwrite" and it can be placed before or after the filename - Replacing whitespaces from user input with underscores - Changed success message based on write mode - Bug fixes (of the new script): - Clicks on tabs, used for data loading, now use relative coordinates to support different screen resolutions - Removed redundant check "if unit or item"
Hi @myk002 , |
pre-commit.ci autofix |
cb8c325
to
cdee3c7
Compare
1097eaa
to
881fbd6
Compare
docs/markdown.rst
Outdated
|
||
Options | ||
------- | ||
markdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this is a tool that could benefit from a global hotkey - (Ctrl-Shift-s
?) so people can click on things with the mouse and export them quickly with their left hand. This would be added to the keybindings file in the other repo: https://github.com/DFHack/dfhack/blob/develop/data/init/dfhack.keybindings.init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add it later, thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct way to add keybinding? I'm not sure what @dawrfmode means, and maybe I should be using @textviewer instead
save description of selected unit or item in markdown format
keybinding add Ctrl-Shift-S@dwarfmode markdown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that refers to the "context" where the hotkey should be considered active. dwarfmode
is fort mode, but you can make the hotkey local to more specific contexts (the strings returned from dfhack.gui.getCurFocus(true)
). that way, the hotkey will only show up in the DFHack context menu where it is applicable.
e.g.
keybinding add Ctrl-Shift-S@dwarfmode/ViewSheets/UNIT|dwarfmode/ViewSheets/ITEM|...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, let's add it later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I call the command with the hotkey, it doesn't show success message (or any message). Is it expected behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using Shift+R.
keybinding list Shift-R gives an empty list.
The potential conflicts I see are:
Ctrl+R - recording
(easy to misclick)
and
materials: q->workshop; b->select items:
#keybinding add Shift-R "job-material RHYOLITE"
Which is fine, because we will only use the command in our context window
Pull request to add the hotkey:
DFHack/dfhack#4470
d39ffef
to
ae21aaa
Compare
markdown.lua
Outdated
local unit = dfhack.gui.getSelectedUnit(true) | ||
|
||
if not item and not unit then | ||
print([[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use dfhack.printerr
for a nice red color
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code returns white text. Is it expected behavior?
if not item and not unit then
dfhack.printerr([[
Error: No unit or item is currently selected.
- To select a unit, click on it.
- For items that are installed as buildings (like statues or beds),
open the building's interface and click the magnifying glass icon.
Please select a valid target and try running the script again.]])
-- Early return to avoid proceeding further if no unit or item is selected
return
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the red color only shows up on the DFHack console. the launcher output won't ever show color since color information isn't available via the API that gui/launcher
uses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I resolve this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the best way to resolve this would be to create a proper UI for the tool -- add an export link to the screens where export is supported. In fact, this might be a better solution than the global keybinding since the feature will be more discoverable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example overlay code (which you'd integrate into markdown.lua
):
--@ module=true
local overlay = require('plugins.overlay')
local widgets = require('gui.widgets')
MarkdownOverlay = defclass(MarkdownOverlay, overlay.OverlayWidget)
MarkdownOverlay.ATTRS{
desc='Adds links to screen where text can be exported to a file.',
default_pos={x=-30, y=21},
default_enabled=true,
viewscreens={
'dwarfmode/ViewSheets/ITEM',
'dwarfmode/ViewSheets/UNIT',
},
frame={w=21, h=1},
}
function MarkdownOverlay:init()
self:addviews{
widgets.TextButton{
view_id='button',
label='Export text',
key='CUSTOM_CTRL_T',
on_activate=self:callback('do_export'),
},
widgets.TextButton{
view_id='button_good',
label='Export done',
text_pen=COLOR_GREEN,
key='CUSTOM_CTRL_T',
visible=false,
},
}
end
function MarkdownOverlay:do_export()
dfhack.run_script('markdown')
self.subviews.button.visible = false
self.subviews.button_good.visible = true
local end_ms = dfhack.getTickCount() + 5000
local function label_reset()
if dfhack.getTickCount() < end_ms then
dfhack.timeout(10, 'frames', label_reset)
else
self.subviews.button_good.visible = false
self.subviews.button.visible = true
end
end
label_reset()
end
OVERLAY_WIDGETS = {overlay=MarkdownOverlay}
default_pos
might need some tweaking -- I just made those numbers up without testing
I also used Ctrl-T since that's what many screen-specific DFHack overlays use
I don't think it changes anything for this PR, but be aware that we're correcting some of the definitions for the internal markup structures: |
Changes: - Replaced manual argument parsing with DFHack's argparse.processArgsGetopt - Now support "--overwrite" argument. - Switched to dfhack.printerr - Default filename is now ``markdown_{worldname}.md`` instead of ``markdown_{worldname}_export.md`` - Removed unused variables - Mention UTF-8 and argument option in docs - Minor docs improvements
- Other minor changes to the markdown.rst
- Added (hard-coded) root folder name to the export success message (Exported to ``Dwarf Fortress/markdown_{worldname}.md``)
It looks like you figured this out. Sorry for the long delay! |
Co-authored-by: Myk <[email protected]>
I will be away from computer for another 3 weeks, will get back to it end of Jan probably. Thank you for the review! |
- Changed FileHandle error handling - Removed empty else statement Docs: - Removed "|" characters - Tweaked directory description - Minor improvements
I want to rename the script to "Record keeper" (to reference the hotkey) or "Text extractor" |
with ``gui/quickcmd`` and ``keybinding``.
This script is already known as |
Updated script to work with the Steam version
Features:
Docs:
Refactoring:
Manual testing done before opening the PR:
markdown
)markdown descriptions
)markdown -o
)markdown descriptions -o
/markdown -o descriptions
)