Reputation: 169
So I have to write a basic shell in C for school, no pipes, no redirections, I just have to execute the binarys and code a few builtins.
I already did most of that, but now I would like to implement some keyboard shortcuts, like ctrl+L to clear the screen, up/down to navigate through commands history, ctrl+D to exit the shell and so on.
The problem is, I have no idea how to read input without the user pressing enter.
Also I should mention that I can only use a very limited panel of functions, the only function I can use to read input is the system call read().
If anyone has an idea it would be great
Upvotes: 1
Views: 58
Reputation: 158150
Generally use the readline
library to read input. It supports defining shortcuts, history, auto completion, ... and is meant for that purpose.
If you are not allowed to use it, I guess your teacher wants you to concentrate on important parts of the task rather than getting fancy.
If you just want to play around a bit, you may start your shell using the rlwrap
command:
rlwrap your_shell
rlwrap
can be used to add readline functionality to arbitrary commands which read from stdin.
Upvotes: 2