diff options
| author | Joel Martin <github@martintribe.org> | 2014-03-24 16:32:24 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-03-24 16:32:24 -0500 |
| commit | 3169070063b2cb877200117ebb384269d73bcb93 (patch) | |
| tree | 23de3db1ea5c37afd21a45b6ed7771f56a08c0c4 /python/mal_readline.py | |
| download | mal-3169070063b2cb877200117ebb384269d73bcb93.tar.gz mal-3169070063b2cb877200117ebb384269d73bcb93.zip | |
Current state of mal for Clojure West lighting talk.
Diffstat (limited to 'python/mal_readline.py')
| -rw-r--r-- | python/mal_readline.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/python/mal_readline.py b/python/mal_readline.py new file mode 100644 index 0000000..e8cf957 --- /dev/null +++ b/python/mal_readline.py @@ -0,0 +1,24 @@ +import os, readline as pyreadline + +history_loaded = False +histfile = os.path.expanduser("~/.mal-history") + +def readline(prompt="user> "): + if not history_loaded: + 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 = raw_input(prompt) + pyreadline.add_history(line) + with open(histfile, "a") as hf: + hf.write(line + "\n") + return line + except EOFError: + return None |
