| Author |
Searching pattern to implement command history
|
Pho Tek
Ranch Hand
Joined: Nov 05, 2000
Posts: 757
|
|
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: 6913
|
|
|
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.
|
A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
|
 |
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: 24057
|
|
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: 757
|
|
|
Ernest, Looks like I have to do JNI to do this.
|
 |
 |
|
|
subject: Searching pattern to implement command history
|
|
|