mirror of
https://github.com/kanaka/mal.git
synced 2024-09-21 02:27:10 +03:00
dbac60df00
- 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.
33 lines
814 B
Python
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
|