Textualize / trogon

Easily turn your Click CLI into a powerful terminal application
MIT License
2.5k stars 54 forks source link

In-tool command history support #66

Open shtrom opened 1 year ago

shtrom commented 1 year ago

This module is insanely useful in the case of complex command lines.

One aspect that I think would make it even better is some sort of history support. Not shell history like #12, but actual built-in history within TUI where you can recall commands built in previous runs of the TUI, and either re-edit them or re-run them verbatim.

If editing a command, it would be good to also be able to have the option to either overwrite the previous history entry, or create a new one.

This would offer the ability of recalling oft-used recipes or templates without having to rebuild them from scratch each item. One could even foresee named templates in addition to just historical entries.

daneah commented 1 month ago

I will share a way that we ended up doing this outside the confines of Trogon, for what it's worth, perhaps to inspire further ideas:

Our organization has a data warehouse where we log user events. I hooked the Typer application I built into that system so that it logs each command users run, including the full command string. This is helpful to me to understand usage and audience and so on.

I ended up adding a history command to my Typer application—because the application knows the current user, and because it knows how to query the data warehouse, it's able to present the most recent commands a user has run.

I could see abstracting this all to some kind of pluggable persistence layer for command history. That way it could be a file on the file system, or a data warehouse query, or any arbitrary API call. Finding some way to thread this through from the Click app to Trogon would be a trick, of course, and would require some amount of "by convention"...not sure I like all that but just off the top of my head, here!