2022 Dec 29
Today I’m working on fleshing out some implementations of CLI history using the different packages.
dialoguer
seems sort of limited. It really easily handles adding history, but it takes away (doesn’t implement) certain features that are in stdin added by the terminal you’re using (option/command + backspace or left/right navigation) and it always outputs a “:” and you can’t change that default. It’s more for specific input prompts like selection prompts, etc than it is for just a CLI.
I’m realizing you mainly have 3 options for CLI UX:
Use Rust’s native
std::io::stdin
To do anything beyond Rust’s native stdin, you must:
- Implement all normal CLI features, e.g. . Someone can fact check me on this, but from what I could find, there isn’t really a way to just override or extend particular features of stdin, mainly because stdin only reads lines of input (using however the terminal—the one you’re already using the run the program—implements inputting text), as opposed to individual key presses or bytes.
- This will likely require using a dependency like
console
unless you want to implement the different windows vs. unix stuff with a lot of unsafe rust + libc
- This will likely require using a dependency like
- Implement all normal CLI features, e.g. . Someone can fact check me on this, but from what I could find, there isn’t really a way to just override or extend particular features of stdin, mainly because stdin only reads lines of input (using however the terminal—the one you’re already using the run the program—implements inputting text), as opposed to individual key presses or bytes.
Split your program into a daemon program + RPC CLI, and leave CLI features to be implemented by the terminal you’re using to run the program(s).
- My personal choice would be to leave it how it is, and if we wanted to add more advanced CLI features, should switch to daemon + RPC (as opposed to current interactive mode)
GPT is failing me. It’s great at generating ideas, or for giving you some code for something very common, but once you are asking for something that is relatively less common, it starts to actually waste your time. Both github copilot and ChatGPT have given me blatantly incorrect code/answers to some questions when asking about termion and console.