stefanofornari / BshConsole

A BeanShell console with history, vars/commands completion and more...
Apache License 2.0
2 stars 1 forks source link

Console magix... looks promising #1

Closed nickl- closed 6 years ago

nickl- commented 6 years ago

I been wanting to try jline... wasn't so much fun =/ I'm thinking that maybe jline3 is not quite there. Groovy as well as jShell seem to be using jline2 so maybe that is the better option. see jline/jline2 What do you think?

I really made a mess of things so not worth trying to roll a PR. Here are some things I worked out.

Sets the history file for persistence:

    lineReader.setVariable(
        LineReader.HISTORY_FILE,
        new File(System.getenv("HOME")+"/.bsh-console.hist"));

I added it just after lineReader build()

The only way I got the shell to react as expected is by using bsh.CommandLineReader interpreter input reader. It is package private but I'm sure we can make some accessor for it. It's the only way I seem to get a prompt back after pressing return on a blank line.

Interpreter bsh = new Interpreter(
    new CommandLineReader( new InputStreamReader(IN)),
    System.out, 
    System.err,
    true);

There are new methods available through Reflect for getting to the namespace variables and methods.

Reflect.getVariableNames(bsh.getNameSpace());
Reflect.getMethodNames(bsh.getNameSpace());

And then from there you can get to the variables via object (instance) or class (static) as well as the namespace

Reflect.getVariable(bsh.getNameSpace(), name);
Reflect.getVariable(object, name);
Reflect.getVariable(type, name);

To get to the class namespace once you have the instance

Reflect.getThisNS(object); // instance namespace
Reflect.getThisNS(type); // static namespace

But no idea where we're supposed to catch the completed name with jline, it just completes, adds the space no way how to prevent that space it even removes anything (like a dot . ) that you try to add after the completed variable name. No where I can find the completed word again it's now forgotten.

nickl- commented 6 years ago

I currently use hanslub42/rlwrap for readline support and it does have the possibility of doing completion which I attempted in java at some point but didn't have much joyce.

This is the command use

rlwrap -aiI -Cbsh -pBlue java -classpath bsh-2.1.0-SNAPSHOT.jar bsh.Interpreter
stefanofornari commented 6 years ago

Hi Nick,

thanks for the feedback and the code. Also rlwrap is a great hint. If I knew it before I would probably not started BshConsole. However now I am intrigued by using jline with completion and so on. But I agree there are a few issues, in particular with the prompt. If you are interested we can merge this into into the bsh main tree, at least after fixes a few major issues.

I would include for now the persistent history and maybe update the completion as you suggested (even if I have to admit I am not sure I've got it fully). I will do some work in the weekend.

Ste

On Tue, May 22, 2018 at 3:51 AM, Nick Lombard notifications@github.com wrote:

I currently use hanslub42/rlwrap http:///hanslub42/rlwrap for readline support and it does have the possibility of doing completion which I attempted in java at some point but didn't have much joyce.

This is the command use

rlwrap -aiI -Cbsh -pBlue java -classpath bsh-2.1.0-SNAPSHOT.jar bsh.Interpreter

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stefanofornari/BshConsole/issues/1#issuecomment-390837528, or mute the thread https://github.com/notifications/unsubscribe-auth/AACogs95FVwSx15A5_-rHK9jhdgTyUacks5t0280gaJpZM4UH2SN .

nickl- commented 6 years ago

@stefanofornari excuse the late response, time got away from me.

thanks for the feedback and the code.

Yw =)

Also rlwrap is a great hint. If I knew it before I would probably not started BshConsole. However now I am intrigued by using jline with completion and so on.

rlwrap is handy but I agree, jline seems way more fun! Albeit a bloody frustrating learning curve fumbling around in the dark, some documentation would be nice.

But I agree there are a few issues, in particular with the prompt. If you are interested we can merge this into into the bsh main tree, at least after fixes a few major issues.

That's an awesome idea, it will definitely gain more exposure there too but you are right: lets first sort out some of the most obvious issues. Like:

Found out how to is the biggest challenge... did you have a look at the demo? What a joke! it is impossible to see where jline ends and felix begins.They call that a demo???? More like showing off but gives no clue as to how you accomplish that. Where is that parser actually implemented and is it supposed to replace the line reader then? Who knows???

I would include for now the persistent history and maybe update the completion as you suggested (even if I have to admit I am not sure I've got it fully). I will do some work in the weekend.

Already makes a huge difference, nice work. If you can do me one favour... please fix the maven dependencies... use anything you like as long as maven knows where to get it. =) I managed to collect them all last time but forgot and did a hard reset now before pulling your changes... duh!

Tx

stefanofornari commented 6 years ago

I think we can close this.