3

That is,it should support up/down arrow keys and ctrl-r to reverse searching. WHere should I start?

4
  • Do you want all of SSH features, or just the ability to have command history? Commented Aug 2, 2011 at 1:17
  • 2
    If you mean that you want the nice line-editing features, investigate the GNU readline library, which supplies these features to many of the programs you see them in. Commented Aug 2, 2011 at 1:19
  • those items are not ssh features, they are features of the shell (bash/tcsh/zsh), which likely uses readline to implement them. Commented Aug 2, 2011 at 1:20
  • @Alan ,I only need those mentioned features. Commented Aug 2, 2011 at 1:26

1 Answer 1

1

The answer depends on how low-level you want to be. using readline or editline are the high-level answers. Next level down would be to use libncurses and call getch() to read keyboard input, and then handle the history/searching yourself.

Lowest level (for a terminal) is handling the actual input stream of bytes. The arrow keys send particular character sequences depending on your particular terminal. For example, a vt100 emulator will send ^[[A for "up-arrow", ^[[B for "down-arrow", and so forth. To read these, you'll need to set your terminal attributes to return input immediately and not wait for a newline; to do this use termios functions to disable canonical input mode. Then just read input a character at a time, and see if you get characters (27, 91, 65) and you know that's an up-arrow and respond accordingly.

This low level is tedious and fragile and won't work if you use a different terminal emulator (although you could use terminfo to get the appropriate input sequences for other terminals.)

If you're at a lower level than a terminal (serial line, X window, bitmap display, whatever), then the answers change again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.