• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Searching pattern to implement command history

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest, Looks like I have to do JNI to do this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic