Humble Debugger
Humble Debugger

Reputation: 4595

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't get up-arrow command history to work. Any pointers ?

Upvotes: 1

Views: 2426

Answers (5)

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145269

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.

Upvotes: 1

Phil Miller
Phil Miller

Reputation: 38118

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.

Upvotes: 3

laslowh
laslowh

Reputation: 8604

As long as the GNU license is not a problem for you, I would strongly consider GNU Readline

Upvotes: 1

Dave Rager
Dave Rager

Reputation: 8150

Have a look at the GNU Readline library. It can provide input history support.

Upvotes: 0

Foon
Foon

Reputation: 6448

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)

Upvotes: 5

Related Questions