This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Searching pattern to implement command history Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Searching pattern to implement command history" Watch "Searching pattern to implement command history" New topic
Author

Searching pattern to implement command history

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

I have an existing jar file that implements a rudimentary shell interface to a framework. e.g. for comparison, refer to the "mysql" command line app that allows you to connect to MySql databases, query etc..

The problem is that this shell interface does not implement command history. I would like to write an adapter shell that provides command history and command completion like the facility in unix shells.

What pattern is applicable here ?

From a data structure perspective, a stack is probably what I need. Then I would just need to trap for arrow up and arrow down keys to cycle through the commands.

Now whenever I do an arrow up, I get a ^[[A and when I do a arrow down I get a [[B^ in the command line.

Regards,

Pho
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
This sounds a lot like a "decorator" to me. Your new shell provides the same interface as the underlying shell, forwarding some operations, and adding others.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
For those interested in "history patterns", take a look at Francis Andersons
paper on the subject ( http://jerry.cs.uiuc.edu/~plop/plop98/final_submissions/P63.pdf ).

Francis Anderson:
The patterns of time are fundamental to building accurate models that reflect
the real world. They are not easy, but without them, we are practicing, in the
wrong sense, a timeless way of building.



/Svend Rost

p.s. I agree with Frank.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Note that System.in is line-buffered. Nothing you can do in pure Java will arrange for those arrow keystrokes to be sent to your program without a subsequent "return."

Sucks, I know.


[Jess in Action][AskingGoodQuestions]
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

Ernest, Looks like I have to do JNI to do this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Searching pattern to implement command history
 
Similar Threads
Need unix shell script Help
Daemonizing & Recalling an App
mysql browser logic
Unix Tutorials
a linux file browsing program?