diff options
author | 2018-02-07 16:32:17 -0600 | |
---|---|---|
committer | 2018-02-07 16:32:17 -0600 | |
commit | 463eddd02b4b285f239cb6aed98836c3292a1564 (patch) | |
tree | 6f125e5eeb8351d1416bb8b13952220033ad2c2a /plugins/console | |
parent | e51076bd41718fda9ff07bcb98afe5761792d153 (diff) |
plugins/console: make the console behave like the docs, unlike the official lua console if you are in a block, entering a newline on a blank line gets you out (nw)
Diffstat (limited to 'plugins/console')
-rw-r--r-- | plugins/console/init.lua | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/plugins/console/init.lua b/plugins/console/init.lua index 0c503adbaa5..3cb75f55528 100644 --- a/plugins/console/init.lua +++ b/plugins/console/init.lua @@ -36,13 +36,14 @@ ln.setcompletion(function(c, str, pos) yield() ln.addcompletion(c, status:match("([^\x01]*)\x01(.*)")) end) -return ln.linenoise('\x1b[1;36m[MAME]\x1b[0m> ') +return ln.linenoise('$PROMPT') ]] local keywords = { 'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while' } + local cmdbuf = "" -- Main completion function. It evaluates the current sub-expression -- to determine its type. Currently supports tables fields, global @@ -209,6 +210,7 @@ return ln.linenoise('\x1b[1;36m[MAME]\x1b[0m> ') emu.register_stop(function() consolebuf = nil end) emu.register_periodic(function() + local prompt = "\x1b[1;36m[MAME]\x1b[0m> " if consolebuf and (#consolebuf > lastindex) then local last = #consolebuf print("\n") @@ -225,28 +227,33 @@ return ln.linenoise('\x1b[1;36m[MAME]\x1b[0m> ') return elseif started then local cmd = conth.result - preload = false - local func, err = load(cmd) - if not func then - if err:match("<eof>") then - print("incomplete command") - ln.preload(cmd) - preload = true - else - print("error: ", err) + if cmd == "" then + if cmdbuf ~= "" then + print("Incomplete command") + cmdbuf = "" end else - local status - status, err = pcall(func) - if not status then - print("error: ", err) + cmdbuf = cmdbuf .. "\n" .. cmd + local func, err = load(cmdbuf) + if not func then + if err:match("<eof>") then + prompt = "\x1b[1;36m[MAME]\x1b[0m>> " + else + print("error: ", err) + cmdbuf = "" + end + else + local status + status, err = pcall(func) + if not status then + print("error: ", err) + end + cmdbuf = "" end - end - if not preload then ln.historyadd(cmd) end end - conth:start(scr) + conth:start(scr:gsub("$PROMPT", prompt)) started = true end) end |