I am struggling to create a simple linux shell. I can simply create to learn how to use basic system calls.
Scenario : the user types in a command clicks a tab (so that the shell automatically completes its command), the autocomplete command issues (or sentences), enters a user click, the evals command and executes.
As in bash.
I figured out how to make assessments, convert the team to tokens, execute it using pipes, etc. What I cannot understand is the input part. Namely, these keystrokes.
I know what my options are:
getc() - get each character separately, save it in the buffer. It is impossible to figure out how to get keystrokes, because it pauses until it sees "\ n" or Ctrl + D. Kinda is expensive, as there will be 1 getc () for each character in the command. Also, I have to deal with buffer reallocation, amortization ... boo ...scanf("%s") - worries too much about buffer overflows. I can not get these keystrokes, which I did not. Pauses executionread() (from unistd.h) - maybe something I don’t want. But I saw people here who said that it was a real pain to use it for this. I checked. It.getline() - unable to get keystrokes.
I looked at the bash source code to see how it works with input, and OH MY GOD. There are 450 lines of code dedicated to this simple thing (input.c file).
Are there really no simpler solutions than this? I do not want to use ncurses, I do not care about portability, I just do not want to achieve one goal: to receive user input and knowing when he pressed the tab key. Do it elegantly with minimal effort.
source share