« Return to Thread: How to make a single line text editor in a console application

How to make a single line text editor in a console application

by Dirkjan :: Rate this Message:

Reply to Author | View in Thread

Hello,

I a Jython console application, I would like to prompt the user to edit a predefined value. Like this:

Edit the default value >n5117l11-pr.deploy.properties

The user should then be able to accept the default by pressing enter or adapt it with cursor keys or something vi like.

In Python something like this can be done by importing the readline module, which will then change the behaviour of raw_input. You can then (ab-)use the history to get something into the buffer:

import readline
default ="This is the default text."
readline.set_history_length(1)
readline.add_history(default)
txt=raw_input("Enter a value. Press [arrow up] to get default.")
print txt

However, in Jython, the readline module is missing. I tried to compile the Java Readline as described on http://wiki.python.org/jython/ReadlineSetup. However on AIX, make complains about syntax errors in the make file. Also, I read somewhere that the readline for jython does not have any influence on raw_input.

Another idea i had, is to call vi from the script with os.system, but that gives an error "An error occurred while reading input"



 « Return to Thread: How to make a single line text editor in a console application