Commit | Line | Data |
---|---|---|
a751ce67 JM |
1 | #import os, readline as pyreadline |
2 | # | |
3 | #histfile = os.path.expanduser("~/.mal-history") | |
4 | # | |
5 | #def init(): | |
6 | # try: | |
7 | # with open(histfile, "r") as hf: | |
8 | # for line in hf.readlines(): | |
9 | # pyreadline.add_history(line.rstrip("\r\n")) | |
10 | # pass | |
11 | # except IOError: | |
12 | # #print("Could not open %s" % histfile) | |
13 | # pass | |
14 | # | |
15 | #def readline(prompt="user> "): | |
16 | # try: | |
17 | # line = raw_input(prompt) | |
18 | # pyreadline.add_history(line) | |
19 | # with open(histfile, "a") as hf: | |
20 | # hf.write(line + "\n") | |
21 | # except IOError: | |
22 | # pass | |
23 | # except EOFError: | |
24 | # return None | |
25 | # return line | |
26 | ||
27 | import os | |
28 | def readline(prompt): | |
29 | res = '' | |
30 | os.write(1, prompt) | |
31 | while True: | |
32 | buf = os.read(0, 255) | |
33 | if not buf: raise EOFError() | |
34 | res += buf | |
35 | if res[-1] == '\n': return res[:-1] | |
36 |