summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--3rdparty/lua-linenoise/linenoise.c9
-rw-r--r--plugins/console/init.lua14
2 files changed, 22 insertions, 1 deletions
diff --git a/3rdparty/lua-linenoise/linenoise.c b/3rdparty/lua-linenoise/linenoise.c
index 670a71c2b22..fc8ae19e079 100644
--- a/3rdparty/lua-linenoise/linenoise.c
+++ b/3rdparty/lua-linenoise/linenoise.c
@@ -101,6 +101,14 @@ static int l_historyadd(lua_State *L)
return handle_ln_ok(L);
}
+static int l_preloadbuffer(lua_State *L)
+{
+ const char *line = luaL_checkstring(L, 1);
+ linenoisePreloadBuffer(line);
+
+ return handle_ln_ok(L);
+}
+
static int l_historysetmaxlen(lua_State *L)
{
int len = luaL_checkinteger(L, 1);
@@ -168,6 +176,7 @@ luaL_Reg linenoise_funcs[] = {
{ "clearscreen", l_clearscreen },
{ "setcompletion", l_setcompletion},
{ "addcompletion", l_addcompletion },
+ { "preload", l_preloadbuffer },
/* Aliases for more consistent function names */
{ "addhistory", l_historyadd },
diff --git a/plugins/console/init.lua b/plugins/console/init.lua
index 3e5487c7b60..151af204400 100644
--- a/plugins/console/init.lua
+++ b/plugins/console/init.lua
@@ -13,6 +13,7 @@ function console.startplugin()
local conth = emu.thread()
local started = false
local ln = require("linenoise")
+ local preload = false
print(" _/ _/ _/_/ _/ _/ _/_/_/_/");
print(" _/_/ _/_/ _/ _/ _/_/ _/_/ _/ ");
print(" _/ _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/ ");
@@ -76,14 +77,25 @@ function console.startplugin()
ln.historyadd(cmd)
local func, err = load(cmd)
if not func then
- print("error: ", err)
+ if err:match("<eof>") then
+ print("incomplete command")
+ ln.preload(cmd)
+ preload = true
+ else
+ print("error: ", err)
+ preload = false
+ end
else
+ preload = false
local status
status, err = pcall(func)
if not status then
print("error: ", err)
end
end
+ if not preload then
+ ln.historyadd(cmd)
+ end
end
conth:start(scr)
started = true