Last Comment Bug 418034 - [PATCH] Rhino shell improvement - better line editing
: [PATCH] Rhino shell improvement - better line editing
Status: RESOLVED FIXED
:
Product: Rhino
Classification: Components
Component: Compiler (show other bugs)
: other
: x86 Linux
: -- normal (vote)
: ---
Assigned To: Norris Boyd
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-02-16 21:12 PST by Matthieu Riou
Modified: 2008-03-18 08:13 PDT (History)
2 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---


Attachments
Patch to rely on JLine for a better shell (1.27 KB, patch)
2008-02-16 21:15 PST, Matthieu Riou
no flags Details | Diff | Splinter Review
JLine hooks (1.70 KB, patch)
2008-02-16 21:17 PST, Matthieu Riou
no flags Details | Diff | Splinter Review

Description Matthieu Riou 2008-02-16 21:12:50 PST
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b3pre) Gecko/2008020507 Firefox/3.0b3pre
Build Identifier: 

This is the first version of a patch to improve the Rhino shell by adding line editing, history and completion. It relies on the JLine library to work but the dependency is optional at runtime.

A bit more about the implementation itself. Instead of relying only on reflection, which worked but led to a rather ugly code, I've added a new file that includes all the JLine code. The classes contained in that file are only loaded if JLine is found in the classpath. The drawback is that JLine is required for compilation but I don't think it's a big problem, I've just modified a bit the Ant scripts.

On the plus side it allowed me to implement a custom completor (the interface that handles completion in JLine) and add completion for all Rhino shell functions (load, print, spawn, ...).

Let me know how it goes...

Reproducible: Always
Comment 1 Matthieu Riou 2008-02-16 21:15:57 PST
Created attachment 303815 [details] [diff] [review]
Patch to rely on JLine for a better shell

A separate file must be added in addition to this patch.
Comment 2 Matthieu Riou 2008-02-16 21:17:53 PST
Created attachment 303816 [details] [diff] [review]
JLine hooks

Copy this file in toolsrc/org/mozilla/javascript/tools/shell.
Comment 3 Norris Boyd 2008-03-14 13:12:35 PDT
I finally got a chance to try this out. Works great from the command line on Unix and Windows. Doesn't work so well from the Eclipse console: on Unix the entered text is printed out when enter is pressed, so that the text is effectively repeated. And on Windows the shell terminates before accepting any input. 

Perhaps the thing to do is just provide a command-line switch to disable this that could be used from within Eclipse. It'd be better to detect if you're running in an Eclipse console, but I don't know if that's possible. 

Ideas?
Comment 4 Matthieu Riou 2008-03-14 19:21:22 PDT
Actually I was seeing it as an opt-in feature, if JLine is in your classpath then it uses it, otherwise just don't use Jline. I'd be surprised if folks who run this into an Eclipse console were using JLine already. Or you think that an additional option is necessary?
Comment 5 Norris Boyd 2008-03-15 12:55:24 PDT
Well, the problem is that if you load all the source into Eclipse then you need JLine to compile. I suppose another option is to exclude JLine from the source list, or to make it so ShellLine will compile without JLine. I'll look at the latter on my flight Monday if I have a chance.
Comment 6 Norris Boyd 2008-03-18 08:13:55 PDT
I changed ShellLine to just use reflection and I've now committed the changes.

Thanks for contributing this; it makes the console much more pleasant to use! If I get more time to play with this I may explore completion for object/property chains starting with global variables (e.g. java.lang.Str^I)

Note You need to log in before you can comment on or make changes to this bug.