1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00
mal/python/mal_readline.py
Joel Martin dbac60df00 All: move metadata, atoms, readline, conj to stepA.
- Move some of the more optional things (conj, readline) to stepA. All
  implementations pass step9 tests now.
- Move metadata and atoms to stepA.
- Update step9 and stepA diagrams.
2015-03-14 17:17:14 -05:00

33 lines
814 B
Python

import os, sys, readline as pyreadline
history_loaded = False
histfile = os.path.expanduser("~/.mal-history")
if sys.version_info[0] >= 3:
rl = input
else:
rl = raw_input
def readline(prompt="user> "):
global history_loaded
if not history_loaded:
history_loaded = True
try:
with open(histfile, "r") as hf:
for line in hf.readlines():
pyreadline.add_history(line.rstrip("\r\n"))
pass
except IOError:
#print("Could not open %s" % histfile)
pass
try:
line = rl(prompt)
pyreadline.add_history(line)
with open(histfile, "a") as hf:
hf.write(line + "\n")
except IOError:
pass
except EOFError:
return None
return line