1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 01:57:09 +03:00
mal/lua/readline.lua
Joel Martin c9de2e82ed Tests: add testing Dockerfile. Impl fixes.
- tests/docker/Dockerfile: specifies full docker image containing all
  tools/languages (except matlab).
- tests/docker-build.sh: build above image.
- tests/docker-run.sh: launch above image.
    Example: ./tests/docker-run.sh make test^js^step2
- Various fixes across multiple languages:
    - Unicode fixes for bash and R on Ubuntu Utopic
    - readline history fixes for when ~/.mal-history is not available
      or readable/writable. No fatal errors.
    - fixes to work with perl 5.20 (and still perl 5.18)
2015-03-11 22:22:35 -05:00

42 lines
890 B
Lua

local LN = require('linenoise')
local M = {}
local history_loaded = false
local history_file = os.getenv("HOME") .. "/.mal-history"
M.raw = false
function M.readline(prompt)
if not history_loaded then
history_loaded = true
xpcall(function()
for line in io.lines(history_file) do
LN.historyadd(line)
end
end, function(exc)
return true -- ignore the error
end)
end
if M.raw then
io.write(prompt); io.flush();
line = io.read()
else
line = LN.linenoise(prompt)
end
if line then
LN.historyadd(line)
xpcall(function()
local f = io.open(history_file, "a")
f:write(line.."\n")
f:close()
end, function(exc)
return true -- ignore the error
end)
end
return line
end
return M