Up arrow based command history in console input (C++)
I am trying to build a console application that takes user input. I was able to use printf to keep the cursor in the same place, I could have used curses as well, but I can开发者_JAVA技巧't get up-arrow command history to work. Any pointers ?
I think you want readline (www.gnu.org/software/readline/ which seems to now redirect to the maintainer site at http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html)
In addition to the mentions of the readline library, I'll also mention the BSD-licensed editline
library and the rlwrap
command-line wrapper tool that runs any program with a readline-based history.
As long as the GNU license is not a problem for you, I would strongly consider GNU Readline
Have a look at the GNU Readline library. It can provide input history support.
In Windows the standard console windows provide up-arrow input history -- you don't have to do anything. For other standard Windows console services see the doskey
command quickhelp, and simply replace the word "command" with "line of input". It's a bit misleading, yes.
EDIT, added para: Possibly you're doing something that circumvents the standard services. I just noticed that the browser window title says "ncurses", which is not in your current question title. Perhaps that's it, but in that case, ask specifically for help with ncurses.
For *nix see the other answers.
Cheers & hth.
精彩评论