mirror of
https://github.com/holub/mame
synced 2025-10-04 16:34:53 +03:00
plugins/console: further improve completions by removing break chars from linenoise that hide the full type (nw)
This commit is contained in:
parent
feca994e2f
commit
65c3796e33
2
3rdparty/linenoise-ng/src/linenoise.cpp
vendored
2
3rdparty/linenoise-ng/src/linenoise.cpp
vendored
@ -1883,7 +1883,7 @@ static int cleanupCtrl(int c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// break characters that may precede items to be completed
|
// break characters that may precede items to be completed
|
||||||
static const char breakChars[] = " =+-/\\*?\"'`&<>;|@{([])}";
|
static const char breakChars[] = " =+-/\\*?\"'`&<>;|@{}";
|
||||||
|
|
||||||
// maximum number of completions to display without asking
|
// maximum number of completions to display without asking
|
||||||
static const size_t completionCountCutoff = 100;
|
static const size_t completionCountCutoff = 100;
|
||||||
|
@ -33,30 +33,26 @@ function console.startplugin()
|
|||||||
scr = scr .. "return ln.linenoise('\x1b[1;36m[MAME]\x1b[0m> ')"
|
scr = scr .. "return ln.linenoise('\x1b[1;36m[MAME]\x1b[0m> ')"
|
||||||
|
|
||||||
local function get_completions(str)
|
local function get_completions(str)
|
||||||
local function is_pair_iterable(t)
|
|
||||||
local mt = getmetatable(t)
|
|
||||||
return type(t) == 'table' or (mt and mt.__pairs)
|
|
||||||
end
|
|
||||||
local comps = ","
|
local comps = ","
|
||||||
local table = str:match("([(]?[%w.:()]-)[:.]?[%w_]*$")
|
local table = str:match("([(]?[%w.:()]-)[:.][%w_]*$")
|
||||||
local rest, last = str:match("(.-[:.]?)([%w_]*)$")
|
local rest, last = str:match("(.-[:.]?)([%w_]*)$")
|
||||||
local err
|
local err
|
||||||
if table == "" then
|
if table == "" or not table then
|
||||||
table = "_G"
|
table = "_G"
|
||||||
end
|
end
|
||||||
err, tablef = pcall(load("return " .. table))
|
err, tablef = pcall(load("return " .. table))
|
||||||
if (not err) or (not tablef) then
|
if (not err) or (not tablef) then
|
||||||
return comps
|
return comps
|
||||||
end
|
end
|
||||||
if is_pair_iterable(tablef) then
|
if type(tablef) == 'table' then
|
||||||
for k, v in pairs(tablef) do
|
for k, v in pairs(tablef) do
|
||||||
if k:match("^" .. last) then
|
if k:match("^" .. last) then
|
||||||
comps = comps .. "," .. rest .. k
|
comps = comps .. "," .. rest .. k
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local tablef = getmetatable(tablef)
|
if type(tablef) == "userdata" then
|
||||||
if is_pair_iterable(tablef) then
|
local tablef = getmetatable(tablef)
|
||||||
for k, v in pairs(tablef) do
|
for k, v in pairs(tablef) do
|
||||||
if k:match("^" .. last) then
|
if k:match("^" .. last) then
|
||||||
comps = comps .. "," .. rest .. k
|
comps = comps .. "," .. rest .. k
|
||||||
@ -74,6 +70,7 @@ function console.startplugin()
|
|||||||
return
|
return
|
||||||
elseif started then
|
elseif started then
|
||||||
local cmd = conth.result
|
local cmd = conth.result
|
||||||
|
preload = false
|
||||||
local func, err = load(cmd)
|
local func, err = load(cmd)
|
||||||
if not func then
|
if not func then
|
||||||
if err:match("<eof>") then
|
if err:match("<eof>") then
|
||||||
@ -82,10 +79,8 @@ function console.startplugin()
|
|||||||
preload = true
|
preload = true
|
||||||
else
|
else
|
||||||
print("error: ", err)
|
print("error: ", err)
|
||||||
preload = false
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
preload = false
|
|
||||||
local status
|
local status
|
||||||
status, err = pcall(func)
|
status, err = pcall(func)
|
||||||
if not status then
|
if not status then
|
||||||
|
Loading…
Reference in New Issue
Block a user