mirror of
https://github.com/holub/mame
synced 2025-10-05 08:41:31 +03:00
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)
This commit is contained in:
parent
e51076bd41
commit
463eddd02b
@ -36,13 +36,14 @@ ln.setcompletion(function(c, str, pos)
|
|||||||
yield()
|
yield()
|
||||||
ln.addcompletion(c, status:match("([^\x01]*)\x01(.*)"))
|
ln.addcompletion(c, status:match("([^\x01]*)\x01(.*)"))
|
||||||
end)
|
end)
|
||||||
return ln.linenoise('\x1b[1;36m[MAME]\x1b[0m> ')
|
return ln.linenoise('$PROMPT')
|
||||||
]]
|
]]
|
||||||
local keywords = {
|
local keywords = {
|
||||||
'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for',
|
'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for',
|
||||||
'function', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat',
|
'function', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat',
|
||||||
'return', 'then', 'true', 'until', 'while'
|
'return', 'then', 'true', 'until', 'while'
|
||||||
}
|
}
|
||||||
|
local cmdbuf = ""
|
||||||
|
|
||||||
-- Main completion function. It evaluates the current sub-expression
|
-- Main completion function. It evaluates the current sub-expression
|
||||||
-- to determine its type. Currently supports tables fields, global
|
-- 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_stop(function() consolebuf = nil end)
|
||||||
|
|
||||||
emu.register_periodic(function()
|
emu.register_periodic(function()
|
||||||
|
local prompt = "\x1b[1;36m[MAME]\x1b[0m> "
|
||||||
if consolebuf and (#consolebuf > lastindex) then
|
if consolebuf and (#consolebuf > lastindex) then
|
||||||
local last = #consolebuf
|
local last = #consolebuf
|
||||||
print("\n")
|
print("\n")
|
||||||
@ -225,15 +227,20 @@ return ln.linenoise('\x1b[1;36m[MAME]\x1b[0m> ')
|
|||||||
return
|
return
|
||||||
elseif started then
|
elseif started then
|
||||||
local cmd = conth.result
|
local cmd = conth.result
|
||||||
preload = false
|
if cmd == "" then
|
||||||
local func, err = load(cmd)
|
if cmdbuf ~= "" then
|
||||||
|
print("Incomplete command")
|
||||||
|
cmdbuf = ""
|
||||||
|
end
|
||||||
|
else
|
||||||
|
cmdbuf = cmdbuf .. "\n" .. cmd
|
||||||
|
local func, err = load(cmdbuf)
|
||||||
if not func then
|
if not func then
|
||||||
if err:match("<eof>") then
|
if err:match("<eof>") then
|
||||||
print("incomplete command")
|
prompt = "\x1b[1;36m[MAME]\x1b[0m>> "
|
||||||
ln.preload(cmd)
|
|
||||||
preload = true
|
|
||||||
else
|
else
|
||||||
print("error: ", err)
|
print("error: ", err)
|
||||||
|
cmdbuf = ""
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local status
|
local status
|
||||||
@ -241,12 +248,12 @@ return ln.linenoise('\x1b[1;36m[MAME]\x1b[0m> ')
|
|||||||
if not status then
|
if not status then
|
||||||
print("error: ", err)
|
print("error: ", err)
|
||||||
end
|
end
|
||||||
|
cmdbuf = ""
|
||||||
end
|
end
|
||||||
if not preload then
|
|
||||||
ln.historyadd(cmd)
|
ln.historyadd(cmd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
conth:start(scr)
|
conth:start(scr:gsub("$PROMPT", prompt))
|
||||||
started = true
|
started = true
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user