bashprintingtab-completion

How would one implement bash-like tab completion?


I'm trying to determine how the system prints characters to standard input -- that is, how it prints characters which the user can delete and which are considered input if the user hits "Enter."

I happen to be using C, but I would be very surprised if the solution were language-dependent.

Thanks for any insights! : D


Solution

  • Several people have pointed out that bash uses readline, which is true, but I think what you're really asking is how is it able to see what you've typed before you hit enter.

    The answer is that ttys (ie: terminals) can be switched into "raw mode", where input processing of the terminal is disabled, and then you'll see every character as it comes in. This also disables automatic echoing of typed characters.

    See this guide on Reading a single character from a file or a terminal for more info.