summaryrefslogtreecommitdiff
path: root/xmake/plugins/lua/xmake.lua
diff options
context:
space:
mode:
authorTitanSnow <[email protected]>2017-05-10 13:46:07 +0800
committerTitanSnow <[email protected]>2017-05-10 13:46:07 +0800
commit81814d7fa83419d0f23d8c76226c2f7f16aaa63c (patch)
tree387d056c189ff85cd54ffd30b98ed391a3ac55b0 /xmake/plugins/lua/xmake.lua
parent74084408890a446c97376d80f2b342fbab96191e (diff)
save/load replhistory
Diffstat (limited to 'xmake/plugins/lua/xmake.lua')
-rw-r--r--xmake/plugins/lua/xmake.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua
index 1c6b2bf27..bef62203b 100644
--- a/xmake/plugins/lua/xmake.lua
+++ b/xmake/plugins/lua/xmake.lua
@@ -34,6 +34,8 @@ task("lua")
-- imports
import("core.base.option")
import("core.sandbox.sandbox")
+ import("core.project.history")
+ import("lib.readline")
-- list all scripts?
if option.get("list") then
@@ -56,8 +58,28 @@ task("lua")
import("scripts." .. name).main(unpack(option.get("arguments") or {}))
end
else
+ -- clear history
+ readline.clear_history()
+
+ -- load history
+ local replhistory = history.load("replhistory") or {}
+ for _, ln in ipairs(replhistory) do
+ readline.add_history(ln)
+ end
+
-- enter interactive mode
sandbox.interactive()
+
+ -- save to history
+ local entries = readline.get_history_state().entries
+ if #entries > #replhistory then
+ for i = #replhistory+1, #entries do
+ history.save("replhistory", entries[i].line)
+ end
+ end
+
+ -- clear history
+ readline.clear_history()
end
end)