2022 Dec 27
From what I’ve found, using
std::io::stdin()
you are only able to read and handle input by lines. For something like supporting up/down arrows to use a history of commands/inputs, you need to handle individual bytes and/or key presses.To get access to a byte-by-byte input stream, there’s a crate called
termion
`, however it only works on Unix based systems.There’s a crate
dialoguer
that helps build CLIs that handles a lot of stuff for you. However in lightning/bitcoin it seems people are generally reluctant to add dependencies. So if we want to just build the necessary pieces ourselves, dialoguer is built onconsole
, which exposes the lower level interfaces. Any lower than that is usinglibc
.- I am kind of curious what is the mindset behind dependencies. It seems like some are added, but most of the time (from the little that I’ve seen) when the idea is brought up it’s face with a lot of reluctance. Is it mainly because it can be a security risk? Or that it can add unnecessary bloat or complexity to what is meant to be lightweight?
Default stdin doesn’t handle much besides typing, backspace (including option + command/ctrl), and enter. So any arrow keys do not work.
Learned about Mac stage manager. Pretty nice.