[HN Gopher] Show HN: Trogon - An automatic TUI for command line ...
___________________________________________________________________
Show HN: Trogon - An automatic TUI for command line apps
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...
Author : willm
Score : 146 points
Date : 2023-05-21 13:36 UTC (9 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| cies wrote:
| if man pages and `--help` output were more formal definitions of
| CLIs, we could make a tool that creates a browsable version of
| every CLI command that has man pages and/or `--help` text.
| Orangeair wrote:
| > Command line apps reward repeated use, but they lack in
| discoverability.
|
| The biggest thing preventing me from learning more CLI explained
| in one sentence, I'll definitely be looking into this.
| casey2 wrote:
| Lack in discoverability compared to what? GUI apps? Web
| browsers? LOL. Those are intentionally designed to make you use
| them inefficiently.
| jlundberg wrote:
| I highly recommend:
|
| 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.
| bregma wrote:
| Ah, yes. In English we used to spell that R-T-F-M.
| d0mine wrote:
| Can it generate bash completion scripts? eg: $
| . <(fab --print-completion-script zsh)
|
| to enable autocomplete for _fab_ in zsh shell.
| codethief wrote:
| No idea about Trogon but Typer[0], which is based on the Click
| library that Trogon leverages, does provide autocompletion.
|
| [0]: https://typer.tiangolo.com/
| simonw wrote:
| This inspired be to look into how Click handles this without
| Typer, and it turns out it's a supported feature there too:
| https://click.palletsprojects.com/en/8.1.x/shell-completion/
|
| I got it working for my sqlite-utils tool in zsh by running
| this: eval
| "$(_SQLITE_UTILS_COMPLETE=zsh_source sqlite-utils)"
| hprotagonist wrote:
| How easy is it to get this to compose nicely with typer, which
| also sits on top of click? like, if i expose the command group to
| the decorator or something, will that work?
| willm wrote:
| Not too hard by the looks of it.
|
| https://twitter.com/renan_r_santoss/status/16603059638391029...
| hprotagonist wrote:
| daaaang.
|
| ok, we're cooking with gas now!
| eviks wrote:
| Is there a similar tool with GUI that would obviate the need to
| typecheck argument values and make selection an easy toggle from
| a structured list with help/tooltips right where you need them
| instead of in an inconvenient separate --help document?
| codethief wrote:
| While we're building Swagger/OpenAPI for CLIs, could we also
| please create typed/type-safe CLIs? I want to invoke command line
| tools like I invoke functions in my favorite programming
| language.
| kej wrote:
| Isn't this the main selling point of PowerShell?
| grayhatter wrote:
| they are typed... I've yet to come across a cli that doesn't,
| at the very least pretend, like it's following posix. So all of
| it's parameters should be strings.
| codethief wrote:
| Saying that all parameters are strings isn't really saying
| much. In the same way one could say that any function is
| typed because each of its parameters is expected to be a byte
| string.
|
| 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.
| david2ndaccount wrote:
| For various reasons, I use the stdlib argparse library. Will this
| work with that?
| vaughan wrote:
| I want to use terminal, but everytime I type something I get
| presented with an adjacent form I can alternatively use. A cli
| command builder gui. Best of both worlds. Also should be web-
| based. And all output should be a searchable, sortable, groupable
| datagrid. Terminals really fall down in this department. I can't
| believe there isn't a terminal that does this yet. Like a Python
| notebook I guess.
| zokier wrote:
| Have you seen PowerShell ISE? Its not exactly what you want,
| and its UX definitely could be improved but lot of the
| functionality is there. See this screenshot for example
| https://ibb.co/T4pDJnw
| eiiot wrote:
| Does anyone know what terminal is being used in the demo? It
| looks really clean.
| willm wrote:
| ITerm2 on MacOS
| stavros wrote:
| This looks interesting, I love Textual so I tried this with one
| of the apps I wrote:
|
| 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...
| simonw wrote:
| Try @tui() instead of @tui - that might fix it.
| stavros wrote:
| Thanks Simon, I can't believe I looked _twice_ to make sure I
| wasn 't calling it wrong, and still didn't see it.
|
| That did, indeed, fix it!
| dr_kiszonka wrote:
| Looks very nice! Does it also support default "apps" like, e.g.,
| ls?
| willm wrote:
| Not currently, but I think it will in the future.
| russellendicott wrote:
| I love anything TUI related. I spent a lot of time last year
| making a TUI-over-the-wire protocol with a TUI browser.
|
| 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
| willm wrote:
| My interest is piqued! You might want to join our Discord
| server to discuss TUI related things.
| fbdab103 wrote:
| Significantly harder problem, but what would be of most interest
| for me is for a program to offer this interface to an unannotated
| program (which will always be the majority). `trogon ffmpeg` or
| what have you. Theoretically, command line help is structured in
| a way it should be possible to parse, but I have no doubt there
| are many many non-compliant implementations that exist. I suppose
| you could lean on man files when they exist.
| willm wrote:
| That is a tricky problem indeed.
|
| I'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.
| em-bee wrote:
| there is a large collection of annotations for autosuggestion
| of commandline arguments for fish and other shells that
| should be usable too.
| pmarreck wrote:
| I hate to be the broken record here but I bet chatgpt could
| read the man pages for any commandline app and develop a
| schema in the given format for it.
|
| In fact I'd love to try to do that
| gigatexal wrote:
| Will you're a legend. I've been loving all the work you and the
| team are doing on textualize. And thanks for doing a lot of dev
| in the open for us noobs to level up.
| willm wrote:
| Cheers! Glad you like our stuff.
| nonethewiser wrote:
| This makes perfect sense and the "why" is spot on.
| brap wrote:
| I think the most important piece here is standardizing a schema
| format for command line programs.
|
| 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...
| d0mine wrote:
| Command-line interface description language http://docopt.org/
| hprotagonist wrote:
| with, infamously, no spec.
| fbdab103 wrote:
| I believe something of this nature was proposed in the Oilshell
| under the name Shellac[0]. A shell-agnostic autocompletion
| format so that the world could finally move on from writing
| bespoke completion protocols for every new shell language.
|
| [0] https://github.com/oilshell/oil/wiki/Shellac-Protocol-
| Propos...
| tuchsen wrote:
| Ah I'm reminded of that one xkcd. https://xkcd.com/927/
|
| 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.
| willm wrote:
| I think so to! The schema has possibilities beyond just this
| tool.
| bee_rider wrote:
| Is this what the Click library that Torgon uses provides?
| alex_hirner wrote:
| > schema
|
| 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.
| simonw wrote:
| This is really fun. I have an experimental branch of my sqlite-
| utils CLI tool (which has dozens of sub-commands) running with
| this now and it really did only take 6 lines of code - I'm
| treating Trogon as an optional dependency because people using my
| package as a Python library rather than a CLI tool may not want
| the extra installed components:
|
| https://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...
| hprotagonist wrote:
| man i'm installing that this instant ...
| simonw wrote:
| I've now released this as `sqlite-utils` 3.32: https://sqlite-
| utils.datasette.io/en/stable/changelog.html#v...
|
| To install: pipx install sqlite-utils
|
| Then add the trogon dependency - this command ensures it gets
| added to the correct virtual environment:
| sqlite-utils install trogon
|
| Then run this: sqlite-utils tui
|
| Screenshot in the docs: https://sqlite-
| utils.datasette.io/en/stable/cli.html#cli-tui
___________________________________________________________________
(page generated 2023-05-21 23:00 UTC)