I’m trying to create a shell (nothing serious just messing around) and want to read the arrow keys in raw mode to avoid control characters being printed to the screen, and actually be able to use them to go back and edit a line before I hit enter. It’s probably possible to do with termios but is there an easier way of doing this? Or is it perhaps easy to do with termios? It just seems like a rather large subject that has to be studied in full.
I’m reading in lines from stdin in a loop and call fork > execvp with an argument vector that I create from the input string.
By far the easiest approach would be to use the
readlinelibrary which offers everything and more than what you’re mentioning. It should be fairly easy to make your shell behave like a full-blown bash (line editing, command history) with relative ease.