Show HN: Trogon – An automatic TUI for command line apps (github.com)
Hi HN,
Trogon is a project to generate a TUI for command line apps.
It presents the arguments, options, and switches as a form. Editing the form generates a command line, which you can then run with a keypress.
I'm a lover of the command line. But I can recall only a fraction of the switches for most commands I use. I would love it if there was a TUI available for most commands.
Trogon currently works with Python and the Click library, but I would like it to cover more of the Python ecosystem and also generate TUIs for apps not written in Python.
More information in the repository.
Let me know what you think...
73 comments
[ 0.25 ms ] story [ 194 ms ] threadhttps://github.com/simonw/sqlite-utils/commit/ec12b780d5dcd6...
There's an animated GIF demo of the result here: https://github.com/simonw/sqlite-utils/issues/545#issuecomme...
To install:
Then add the trogon dependency - this command ensures it gets added to the correct virtual environment: Then run this: Screenshot in the docs: https://sqlite-utils.datasette.io/en/stable/cli.html#cli-tuiI’m thinking a lot could be extracted from help and man pages. But maybe for some apps we could just write it by hand, or partially by hand.
These schemas could be in a repo and downloaded on demand.
In fact I’d love to try to do that
Once you have that (and it’s actually adopted) there are many possibilities. TUI/GUI is just one of them. Think autocomplete, type checking, discoverability...
I hate to be the LLM guy but they're really good at processing semi-structured data to structured data. You could go that route and have a universal autocomplete for the CLI. Kinda like Co-Pilot for Bash, or you could use it to do what the parent's doing and have a universal TUI program for building commands.
[0] https://github.com/oilshell/oil/wiki/Shellac-Protocol-Propos...
I'm dreaming of a universal standard based on JSON Schema. Dynamicity is a challenge of course. I guess one needs to strike a balance between static data, say for each subcommand, and a full blown configuration language, say nix.
It's somewhat related to this because it's generating a TUI dynamically based on an input schema coming over the wire via gRPC.
Would love any feedback http://uggly.bytester.net
The biggest thing preventing me from learning more CLI explained in one sentence, I'll definitely be looking into this.
cmd —help
man cmd
ls -la /usr/share/doc/cmd
While some of the language can be daunting, it is generally good reads. And these days we have ChatGPT etc that can help explain tricky words etc in more context, even if you native language is not English.
My new default advice actually for junior developers here in Sweden. Works for many other tech areas too, not just the terminal.
https://twitter.com/renan_r_santoss/status/16603059638391029...
ok, we’re cooking with gas now!
[0]: https://typer.tiangolo.com/
I got it working for my sqlite-utils tool in zsh by running this:
Even though CLI parameters are passed to the application as strings, in reality they are often expected to be (and converted to) numbers, enums, lists, file descriptors, … And don't forget that some parameters are optional and/or can be repeated.
In short, there is ample opportunity for proper type annotations.
So you want the parameters to be annotated for their valid values?
Have you not heard of man pages?
I honestly have no idea what else you could mean by type annotations for cli parameters. Do you have an example?
I want that too, I've already started building it https://github.com/GrayHatter/hsh give me a few months :)
I think it sort of is, depending on one's point of view. I mean, at the end of the day, a CLI encantation in a Bash script or Dockerfile is not really different from a function call in your Python/Java/whatever code, only that your interface is not an API but an ABI wrapped inside a POSIX CLI. So the CLI takes on the role of the function signature.
The only problem is that a CLI is typically a very soft and error-prone interface. It might forgive errors, it might be inconsistent etc. etc. This is certainly fine when you can iterate quickly on the command line. But for real programming? Not so much. For such purposes, proper (and properly typed) function signatures were invented. Whether or not you call matching/verifying function calls against function signatures type checking or linting is certainly up to you. :)
As for your project: Cool that you're working on this, and that you're using Zig! I'll visit again in a few months. :)
https://gitlab.com/stavros/parachute
Unfortunately, it doesn't seem to work, failing to find the `cli.command()` function (a group function) after I decorate `cli()` with @tui...
That did, indeed, fix it!
what I envisioned is a similar experience for the CLI tools we've come to know and love
not sure anyone neeeeeeds that, but no-one neeeeded an IDE at first too
My tool uPlaybook[0] is kind of a CookieCutter [1] / Ansible [2] mashup, and the playbooks typically would have a number of "slots" you can configure to control the templating, like project name, license, if you want to "git init", that sort of thing.
It currently auto-generates a argparse interface, or it can interactively ask you those questions. But I've been working on a Textual UI as well. I chose argparse over Click largely because I want to work with minimal dependencies, and the Textual UI would be an optional dependency.
Going to have to check this guy out.
[0] https://github.com/linsomniac/uplaybook [1] https://cookiecutter.readthedocs.io/en/stable/ [2] https://www.ansible.com/
[0] https://github.com/Textualize/textual/discussions/228
[1] https://github.com/chapmanjacobd/library
But, also, “What is old is new again”.
Back in the days of the mainframe and 3270 terminals, all of the commands were pretty much like this. There really was no command line. Rather, it was a screen of fields filled in by the operator and sent wholesale to the system.
Of course it did not end there. Most every Unix system had some kind of, effectively, “curses” based, full screen administration TUI. They were all pretty good for basic and intermediate tasks. I recall doing a lot of disk operations (partition, raid/striping, etc) just following prompts on these things.
Unix System V actually had a rather nice form and menu package you could use from scripts to do your own TUI just like the admin console they shipped.
Anyway, nice project. Just always interesting to watch stuff come around again.
So here's a simple attempt at taking the output of `black --help` and turning it into a python `argparse` script. You could feed the `--help` or man page for pretty much any command into GPT-4 with this sort of prompt and get an argparse script. It probably doesn't hurt that GPT-4 is already familiar with the argument syntax for all the popular cli tools.
You could then imagine executing the generated code against a faux-argparse library which instantiates the data structures you need to render a Trogon UI. Probably best to do this in an appropriate sandbox.
For example, there might be a frequency option whose value can be either annual or monthly. If this was communicated correctly in a man page then it's still possible for someone to typo that as monttly.
They'd pick it up if the error reporting is good, but having the options in a tui should prevent such issues.