views:

575

answers:

5

I'm working on a command line application for Solaris, written in Java6. I'd like to be able to scroll through a history of previous commands using the up and down arrows like many Unix tools allow (shells, VIM command mode prompt, etc).

Is there any standard way of achieving this, or do I have to roll my own?

+4  A: 

Yes, use the GNU readline library.

Pat Notz
By this answer I meant that there is a standard way...
Pat Notz
I don't give downvotes unless the answer is "bad", but I'm surprised that this is accepted answer given the GPL factor.
Jason S
+3  A: 

I think you are looking for something like JLine but I've never used it so cannot attest to its quality.

She can apparently deal with autocompletion and command line history, and the last release was recently (feb this year) so it's by no means dead.

SCdF
+2  A: 

ledit is great on linux for that sort of thing. It's probably easily compiled on solaris.

Clarification: ledit wraps the call to your other command line app, and can even be passed a file to persistently store your history.

Here's the homepage: http://cristal.inria.fr/~ddr/ledit/

TREE
+1  A: 

There is a SourceForge project, http://java-readline.sourceforge.net/, that provides JNI-based bindings to GNU readline. I've played around with it (not used in an actual project), and it certainly covers all of the functionality.

rjray
A: 

warning: GNU readline is GPL-poisoned:

Readline is free software, distributed under the terms of the GNU General Public License, version 2. This means that if you want to use Readline in a program that you release or distribute to anyone, the program must be free software and have a GPL-compatible license. If you would like advice on making your license GPL-compatible, contact [email protected].

For those of us in the commercial world, even if we're not developing commercial applications, this is a show-stopper.

Anyway, the wikipedia page lists several alternatives, including JLine, which sounds promising.

Just as an aside: I work for a company that designs medical products. We make zero (0) dollars off of PC software. Nearly all our software runs on the embedded systems that we design (and we don't make any money off sales/upgrades of this software, only the products themselves); sometimes we do have software diagnostic tools that can run on the end-users' PCs. (design/manufacture/test software that's not released to customers I would think might be possible to use GPL libraries but I'm not sure) Medical products have fairly tight controls; you basically have to prove to the FDA that it's safe for users, it's not like the end user can decide "oh, I don't like this software, I'll just tweak it or use company XYZ's aftermarket replacement" -- that would leave device manufacturers open to a huge liability.

Jason S
gee, thanks for the anonymous no-comment -1....
Jason S