A proof of concept for a TUI-based launcher written in Python using urwid, initially written for kelbot based on his query about 'a way to fire off a script via a "button" in a terminal'.
Suggested way to launch so it gets the current terminal's width: ./launcher.py --term-width="$(tput cols)"
This would use the default config at configs/default.py
and default layout at layouts/default.txt
.
While you could just edit configs/default.py and layouts/default.txt, it's recommended to use them solely as a template by duplicating to for example configs/media_controls.py
and layouts/media_controls.txt
and to edit those instead.
You can then select this new config file with: ./launcher.py --term-width="$(tput cols)" --config-file ./configs/media_controls.py
.
The new layout can be specified with --layout-file ./layouts/media_controls.txt
, but it's recommended to just specify the path with layout_file = Path('layouts/media_controls.txt')
in the config file instead, as shown in the example configs/default.py.
For a quick reference of the command line arguments: ./launcher.py --help
If you used the initial version of this script I posted to gist.github.com a few days ago, then you'll first want to back up your script, or clone this new version in a different location, as the launcher.py would otherwise be overwritten, and you'd lose your config.
This is one of the major reasons behind this update: the separation of config and script.
git clone https://github.com/FiXato/tui_launcher.git
cd tui_launcher
chmod +x launcher.py
cp configs/default.py configs/media_controls.py
cp layouts/default.txt layouts/media_controls.txt
button_rows.append()
as in the initial script to add rows of buttons, you can now put the contents of the keys of your commands
hash in your layouts/media_controls.txt
file, separating the buttons with commas, one row per line.
For example, if in your previous install you had:
button_rows.append(['Play', 'Stop', 'Pause'])
button_rows.append(['Rewind', 'Skip'])
button_rows.append(['Explore'])
You can now just add this to layouts/media_controls.txt
:
play, stop, pause
rewind, skip
Explore
You don't need to include the entire key; just a unique part of it would suffice. It's also case-insensitive, so you don't have to worry about matching capitals.
layout_file
in your config file configs/media_controls.py
../launcher.py --term-width="$(tput cols)" --config-file ./configs/media_controls.py
.Want to buy me a beer? Or toss a few coins to your code-witcher for new hardware? I accept PayPal donations.
If you prefer to support the development of this project, or one of my many other projects, in some other way, feel free to contact me, for example though mastodon, or any of my other contact methods.