This is a simple way to use the text interface to Mathematica and get the advantages of the editing capabilities of the GNU readline. The Python script makes use of the builtin function raw_input(), which in Linux uses GNU readline.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import os,sys f1=os.popen('math ', 'w') f1.flush() while 1: sys.stdout.write('') try: line=raw_input() f1.writelines(line+'\n') f1.flush() except KeyboardInterrupt: f1.close() break sys.stdout.write('\n') sys.exit()
This works on an xterm under the Linux operating system. To use it, give the code a name e.g. "wolfram.py", and start the Python intepreter in the xterm. Type
from wolfram import * That's it. The arrow keys should now functional with the up and down invoking the history function.
The initial position of the cursor may be incorrect. If anyone knows a more solid way achieve GNU readline editing, I would be pleased to hear about it. Also, it would nice if the whole thing could be started directly from the command line of the xterm, i.e.