aboutsummaryrefslogtreecommitdiff
path: root/lua/readline.lua
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2015-01-08 23:25:40 -0600
committerJoel Martin <github@martintribe.org>2015-01-08 23:25:40 -0600
commit9d42904e47c50c5ff2306da04993b2a32bc9cd16 (patch)
treee1b2d46a232e6573dc2c185967ebe988be3db973 /lua/readline.lua
parentfd888612ca589d7e1a46c36fc3fe12aed126f6a8 (diff)
downloadmal-9d42904e47c50c5ff2306da04993b2a32bc9cd16.tar.gz
mal-9d42904e47c50c5ff2306da04993b2a32bc9cd16.zip
Lua: all steps and self-hosting.
Also some misc docs/TODO updates.
Diffstat (limited to 'lua/readline.lua')
-rw-r--r--lua/readline.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/lua/readline.lua b/lua/readline.lua
new file mode 100644
index 0000000..a75f4ff
--- /dev/null
+++ b/lua/readline.lua
@@ -0,0 +1,26 @@
+local LN = require('linenoise')
+
+local M = {}
+
+local history_loaded = false
+local history_file = os.getenv("HOME") .. "/.mal-history"
+
+function M.readline(prompt)
+ if not history_loaded then
+ history_loaded = true
+ for line in io.lines(history_file) do
+ LN.historyadd(line)
+ end
+ end
+
+ line = LN.linenoise(prompt)
+ if line then
+ LN.historyadd(line)
+ local f = io.open(history_file, "a")
+ f:write(line.."\n")
+ f:close()
+ end
+ return line
+end
+
+return M