From: Mark A. <mar...@rw...> - 2004-11-05 14:52:40
|
Hi Jython developers, reading the FAQ and searching the archives confirmed that I'm not the only one searching for command history and completion. As Russell Tokuyama stated on 2004-07-08, it would be nice to update the FAQ and give a hint on how to accomplish this. Below you will find a new FAQ-entry proposal that needs to be verified and posted to the FAQ by someone who knows the password. PSF members: please help! My proposed solution uses a small wrapper around Java Readline (available soon from my homepage) to make it as compatible as possible to CPython. In addition, it would be VERY COOL if Jython itself could be modified to be able to switch console classes on runtime so that editing the registry file would not be necessary any longer. Is there anyone working on Jython 2.2 / 2.3 (?) who would like to work together on this issue? Thanks a lot, Mark 2.8. How can I use command-line history and command completion with Jython? When using CPython you can use the module rlcompleter to let Python load the GNU Readline Library for command-line history and command completion. By wrapping the Java Readline library you can have the same functionality with Jython, too, if running on Unix. 1. Get and install the Java Readline library. With debian this is just done with 'apt-get install libreadline-java', which installs the java library as well as the (native) GNU Readline library. You could also build everything from source or install the RPM package from http://sourceforge.net/projects/java-readline 2. Modify your Jython 'registry' file to have the following presets: # Setting this to the name of different console class, new console # features can be enabled. Readline support is such an example python.console=org.python.util.ReadlineConsole python.console.readlinelib=GnuReadline 3. Now Jython won't start unless you make sure that it finds the Java Readline classes in the $CLASSPATH. In addition, Java needs to find the native libraries libreadline.so and the JNI wrapper libJavaReadline.so, so both should be in your $LD_LIBRARY_PATH or ldconfig. 4. Copy the module 'rlcompleter.py' from CPython to Jython 5. Add the module 'readline.py' from http://www-users.rwth-aachen.de/mark.asbach/download/readline.py 6. Run Jython. In the commandline enter: from rlcompleter import readline readline.parse_and_bind("tab: complete") 7. Have fun PLEASE NOTE THAT BY LINKING TO THE GNU READLINE LIBRARY YOUR PROJECTS SOFTWARE LICENSE MUST BE COMPATIBLE WITH THE GNU PUBLIC LICENSE (GPL). As a workaround you might want to install libeditline and edit python.console.readlinelib appropriately. References: 2.4. Why no command-line history in Jython? 2.6. Where's the registry file? http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html http://www.python.org/doc/2.3/lib/module-rlcompleter.html |