diff options
author | 2023-03-08 03:18:21 +1100 | |
---|---|---|
committer | 2023-03-08 03:18:21 +1100 | |
commit | 6dea565343e81ab6b8c6da880ba166ba28235da8 (patch) | |
tree | 0b526ae232770a30a99ae6d1167388c0361307db /plugins/console/init.lua | |
parent | 3f99355acc73398b663f33f50f47df65895fc9f9 (diff) |
plugins/console: Fixed tab completion after linenoise update.
* Can now cycle through candidates by repeatedly pushing Tab.
* Also cleaned up Lua thread context object a little, and made it
possible to pass any Lua object as a status value.
Diffstat (limited to 'plugins/console/init.lua')
-rw-r--r-- | plugins/console/init.lua | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/plugins/console/init.lua b/plugins/console/init.lua index 3e10e17bc14..33f698fc0cb 100644 --- a/plugins/console/init.lua +++ b/plugins/console/init.lua @@ -43,8 +43,11 @@ function console.startplugin() local ln = require('linenoise') ln.setcompletion( function(c, str) + status = str yield() - ln.addcompletion(c, str) + for k, v in pairs(status) do + ln.addcompletion(c, v) + end end) local ret = ln.linenoise('$PROMPT') if ret == nil then @@ -191,11 +194,8 @@ function console.startplugin() return curstring, strs, expr:match("([%.:%w%(%)%[%]_]-)([:%.%[%(])" .. word .. "$") end - local function get_completions(line, endpos) + local function get_completions(line) matches = {} - local endstr = line:sub(endpos + 1, -1) - line = line:sub(1, endpos) - endstr = endstr or "" local start, word = line:match("^(.*[ \t\n\"\\'><=;:%+%-%*/%%^~#{}%(%)%[%].,])(.-)$") if not start then start = "" @@ -206,16 +206,18 @@ function console.startplugin() local str, strs, expr, sep = simplify_expression(line, word) contextual_list(expr, sep, str, word, strs) - if #matches > 1 then - print("\n") - for k, v in pairs(matches) do - print(v) - end - return "\x01" .. "-1" + if #matches == 0 then + return { line } elseif #matches == 1 then - return start .. matches[1] .. endstr .. "\x01" .. (#start + #matches[1]) + return { start .. matches[1] } + end + print("") + result = { } + for k, v in pairs(matches) do + print(v) + table.insert(result, start .. v) end - return "\x01" .. "-1" + return result end emu.register_start(function() @@ -249,7 +251,7 @@ function console.startplugin() -- ln.refresh() FIXME: how to replicate this now that the API has been removed? end if conth.yield then - conth:continue(get_completions(conth.result:match("([^\x01]*)\x01(.*)"))) + conth:continue(get_completions(conth.result)) return elseif conth.busy then return |