I just implemented a Linux command shell in python using only the os
library's low level system calls, like fork()
and so on.
I was wondering how I can implement a key listener that will listen for key (UP|DOWN) to scroll through the history of my shell.
I want do do this without using any fancy libraries, but I am also wishing that this is not something super complicated. My code is just about 100 lines of code, so far, and I don't want to create a monster just to get a simple feature :D
My thoughts about the problem is, that it should be possible to create a child process with some kind of loop, that will listen for up ^[[A
and down ^[[B
, key press, and then somehow put the text into my input field, like a normal terminal.
So far the thing I am most interested in is the possibility of the key-listener. But next I will probably have to figure out how I will get that text into the input field. About that I am thinking that I probably have to use some of the stdin
features that sys
provides.
I'm only interested in making it work on Linux, and want to continue using low-level system calls, preferably not Python libraries that handle everything for me. This is a learning exercise.