diff options
author | 2019-02-17 09:07:56 -0600 | |
---|---|---|
committer | 2019-02-17 09:07:56 -0600 | |
commit | 836abb0d63fc44fda201b76023612b1f5a21a8ac (patch) | |
tree | 19c3108559aeae9fae2e62bcece3ed5ab29459d7 | |
parent | 764f04c31727f1e377a6b8447a017f670ce22e8a (diff) |
plugins/console: command history (nw)
-rw-r--r-- | 3rdparty/linenoise/linenoise.c | 2 | ||||
-rw-r--r-- | 3rdparty/lua-linenoise/linenoise.c | 14 | ||||
-rw-r--r-- | plugins/console/init.lua | 12 |
3 files changed, 26 insertions, 2 deletions
diff --git a/3rdparty/linenoise/linenoise.c b/3rdparty/linenoise/linenoise.c index 3c63ffe4a96..2c5aac951b2 100644 --- a/3rdparty/linenoise/linenoise.c +++ b/3rdparty/linenoise/linenoise.c @@ -135,7 +135,7 @@ #include "linenoise.h" #include "utf8.h" -#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100 +#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 200 #define LINENOISE_MAX_LINE 4096 #define ctrl(C) ((C) - '@') diff --git a/3rdparty/lua-linenoise/linenoise.c b/3rdparty/lua-linenoise/linenoise.c index 768d455729d..aab7c1418ea 100644 --- a/3rdparty/lua-linenoise/linenoise.c +++ b/3rdparty/lua-linenoise/linenoise.c @@ -175,12 +175,26 @@ static int l_refresh(lua_State *L) return handle_ln_ok(L); } +static int l_historyget(lua_State *L) +{ + int len, i; + char **history = linenoiseHistory(&len); + lua_newtable(L); + for(i = 0; i < len; i++) + { + lua_pushstring(L, history[i]); + lua_rawseti(L, -2, i + 1); + } + return 1; +} + luaL_Reg linenoise_funcs[] = { { "linenoise", l_linenoise }, { "historyadd", l_historyadd }, { "historysetmaxlen", l_historysetmaxlen }, { "historysave", l_historysave }, { "historyload", l_historyload }, + { "historyget", l_historyget }, { "clearscreen", l_clearscreen }, { "setcompletion", l_setcompletion}, { "addcompletion", l_addcompletion }, diff --git a/plugins/console/init.lua b/plugins/console/init.lua index 3cb75f55528..52d54fdcc1a 100644 --- a/plugins/console/init.lua +++ b/plugins/console/init.lua @@ -18,6 +18,16 @@ function console.startplugin() local matches = {} local lastindex = 0 local consolebuf + _G.history = function (index) + local history = ln.historyget() + if index then + ln.preload(history[index]) + return + end + for num, line in ipairs(history) do + print(num, line) + end + end print(" _/ _/ _/_/ _/ _/ _/_/_/_/"); print(" _/_/ _/_/ _/ _/ _/_/ _/_/ _/ "); print(" _/ _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/ "); @@ -28,7 +38,7 @@ function console.startplugin() -- linenoise isn't thread safe but that means history can handled here -- that also means that bad things will happen if anything outside lua tries to use it -- especially the completion callback - ln.historysetmaxlen(10) + ln.historysetmaxlen(50) local scr = [[ local ln = require('linenoise') ln.setcompletion(function(c, str, pos) |