I just implemented a shell in python only using the os
library's low level system calls, like fork()
and so on. And 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.
Thank you in advance :-)
from How to key press detection, low level style in python
No comments:
Post a Comment