Picocli: Command Line History Accessible via Up Arrow

Created on 7 Mar 2018  路  7Comments  路  Source: remkop/picocli

Is it possible to access previous command history using Picocli? Like how a regular terminal can toggle through previous commands using the up arrow?

If not, this would be an excellent feature to add!

shell

Most helpful comment

This is a good feature to add to a picocli-based interactive shell (#242). Nice idea!

All 7 comments

This is a good feature to add to a picocli-based interactive shell (#242). Nice idea!

Okay, is there some sort of a workaround for now? I'm not sure how to implement it.

Maybe capture raw input and append it to a list of previous commands before I send the input to CommandLine? In which case command line history is totally independent of picocli.

Yeah, it really would be nice to have this in-built.

The upcoming picocli 3.0 release will have a new class ParseResult which has the original input. An application could keep references to these ParseResult objects to maintain a history.

There鈥檚 work in progress (#293) to provide a command tokenizer which will be an important building block for an interactive shell. To be honest, I haven鈥檛 given this area much thought yet other than what is happening on #293. This may grow in the future.

I'll look into something for this at some point, hopefully this week because it is spring break here. It would probably be in the new picocli.interactive package, or the normal one?

Nice! picocli.interactive would be the right package.

With #497 there is now a new module picocli-jline2-shell where I plan to add functionality and documentation for building interactive shells with JLine 2 and picocli. As a starting point there will be a completer that dynamically completes the command in a JLine shell based on the picocli CommandSpec. Future interactive shell functionality should go into this module.

As for the topic of this ticket, JLine 2 includes some functionality for command line history, so I will close this ticket when I release the picocli-jline2 module, but feel free to re-open if this requires refinement.

Looks like I forgot to close this.
I believe that JLine has built-in support for navigating through the history of executed commands with the up/down arrow keys.

Was this page helpful?
0 / 5 - 0 ratings