stefanofornari / bshconsole Goto Github PK
View Code? Open in Web Editor NEWA BeanShell console with history, vars/commands completion and more...
License: Apache License 2.0
A BeanShell console with history, vars/commands completion and more...
License: Apache License 2.0
jline 3.8.0 breaks BshConsole specs
bsh # a = {10, 20};
ret1: [I@27dc2c75
--> $4 = {10I, 20I} :int[]
bsh # print($4);
Unknown error: java.util.concurrent.ExecutionException: bsh.EvalError: Error in method invocation: Static method normalizeClassName(Class) not found in class'bsh.StringUtil' : at Line: 29 : in file: /bsh/commands/print.bsh : StringUtil .normalizeClassName ( arg .getClass ( ) )
Called from method: print/BlockNameSpace : at Line: 1 : in file: <unknown file> : print ( $4 )
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.
BshConsole v1.0.0 is not general available and can be downloaded from maven central here.
A few important note: BshConsole is based on the latest (HEAD/SNAPSHOT) of Beanshell 2.1.0; this has not been released yet and is currently (Aug 4th, 2018) available only building from source as a maven snapshot. This prevented to release a version of BshConsole. To overcome this problem, BshConsole uses a released version of a Beanshell snapshot from the fork https://github.com/stefanofornari/beanshell. You should be able to replace a fresh build of the Beanshell jar into /lib without any problem. If you encounter any issues, please open a ticket.
Next step
(see issue jline/jline3#302)
As reported by @nickl- when an exact match is found, an additional space is added to the completed text. This is undesirable in BeanShell.
The new modification does not recover from loop interruption and also doesn't stop the loop leaving orphan thread running.
To reproduce
bsh % a = 1;
bsh % while (true) a++;
(...)
So issues with the test dependencies.
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/interperon/git/beanshell/BshConsole/BshC/src/test/java/bsh/BugFreeBshConsoleInterpreter.java:[19,28] package ste.xtest.concurrent does not exist
[ERROR] /Users/interperon/git/beanshell/BshConsole/BshC/src/test/java/bsh/BugFreeBshConsoleInterpreter.java:[20,28] package ste.xtest.concurrent does not exist
[ERROR] /Users/interperon/git/beanshell/BshConsole/BshC/src/test/java/bsh/BugFreeBshConsoleInterpreter.java:[72,13] cannot find symbol
Found ste.test xtest 1.20.1-SNAPSHOT again but get compile error.
Could not find artifact ste.web:webtoolkitlib:jar:1.7.2 I have ste.web webtoolkit 1.9.2-SNAPSHOT so lets try that.
BUILD FAILURE
Tests run: 243, Failures: 2, Errors: 0, Skipped: 0
Ok lets try:
mvn install -DskipTest
Got xtest-1.20.1-SNAPSHOT.jar installed. Lets try again.
Now at least no build errors anymore but tests still fail
[ERROR] Failures:
[ERROR] BugFreeBshConsoleInterpreter.prompt_at_start:72 task expected to complete in 500 milliseconds, but it did not finished in 0 milliseconds
[ERROR] BugFreeBshConsoleInterpreter.prompt_at_start_failure:97 task expected to complete in 3000 milliseconds, but it did not finished in 0 milliseconds
[ERROR] Tests run: 12, Failures: 2, Errors: 0, Skipped: 1
You really can't expect us to consider the tests if the existing ones don't pass.
When the execution of a statement fails, it may throw the exception:
Unknown error: java.util.concurrent.ExecutionException: bsh.EvalError: Undefined argument: users : at Line: 1 : in file: : ( users )
This is just because the statement was executed in a asynchronous task and only the root cause should be displayed
Interrupting multi line now produces EOF exceptions again.
This is fixed in BeanShell upstream...
Welcome to bshell ${version}
bsh #
bsh # class A {
(...)
// Error: Parser Error: In file: <unknown> Encountered <EOF> at line 2, column 9.
bsh #
when a script is ran with source() the interpreter stuck not returning to the console.
Similarly to issue #27, when closing the console by typing ^D, we may get the following exception:
Exception in thread "Thread-3" java.io.IOError: java.io.InterruptedIOException: Command interrupted
at org.jline.terminal.impl.AbstractPosixTerminal.getSize(AbstractPosixTerminal.java:62)
at org.jline.terminal.Terminal.getWidth(Terminal.java:191)
at ste.beanshell.JLineConsole.status(JLineConsole.java:81)
at ste.beanshell.JLineConsole.on(JLineConsole.java:59)
at bsh.BshConsoleInterpreter.run(BshConsoleInterpreter.java:150)
at java.lang.Thread.run(Thread.java:748)
We should instead catch it.
bsh # print("
dkjhgdfk
^C
(...)
Unknown error: bsh.TokenMgrException: Lexical error at line 1, column 8. Encountered: <EOF> after : ""
The prompt is disappearing once deleting all chars of a line.
It resulted to be an issue with the way jline and beanshell manage the prompt and the input.
to reproduce:
bsh # a["10"] = 1;
expected:
// Error: Evaluation Error: Arrays may only be indexed by integer types.: Can't assign String to int : at Line: 2 : in file: : [ "one" ]
actual:
no message displayed
As opposed to exit the shell
I'd like to be able to provide a flexible and simple help system for 3rd party commands or added commands. This is how it should work:
bsh.help shall point to a directory where the help text of the various commands will be stored, one file per command. The help file shall be named [command name].txt and follow the resource conversion of turning package namespaces into subfolders (e.g. help file com/acme/app/show.txt is for command com.acme.app.show).
A new command help() shall be provided. This lists all help files and print them all on the console's output stream. If help() is used with one or more string arguments, the help files of the given commands shall be printed.
bsh.help shall default to /help
This should replace the use of bsh.help. which quite limited in the length and formatting of the text.
A first bunch of known issues have been fixed and the console is now ready for prime time.
Basic features are:
TODO:
(*) I am not sure yet which version of beanshell I can include. It cannot be a snapshot, therefore maybe it will be b06 until a not-snapshot of beanshell is tagged.
Heads up: beanshell/beanshell@014e83b made some changes to Interpreter, see if it affects you.
BshConsole v1.1.0 has been released, you can find it here.
What's new
Next step
This happens probably when the command takes a while to process, so when we ask for the prompt a wrong value is available. I need to find a more reliable way...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.