From b87438fbe8e8fe7b971fb1bd1dd4675ae3efbf64 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Wed, 10 May 2017 16:27:12 +0800 Subject: mv history storing into sandbox.lua --- .../modules/import/core/sandbox/sandbox.lua | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua index 5e24ec832..6ffb6b4f1 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua @@ -28,6 +28,7 @@ local sandbox_core_sandbox = sandbox_core_sandbox or {} -- load modules local sandbox = require("sandbox/sandbox") local raise = require("sandbox/modules/raise") +local history = require("project/history") -- enter interactive mode function sandbox_core_sandbox.interactive() @@ -47,8 +48,34 @@ function sandbox_core_sandbox.interactive() -- bind sandbox environment -- setfenv(0, instance._PUBLIC) + local enable_readline = os.versioninfo().features.readline + local replhistory + if enable_readline then + -- clear history + readline.clear_history() + + -- load history + replhistory = history.load("replhistory") or {} + for _, ln in ipairs(replhistory) do + readline.add_history(ln) + end + end + -- enter interactive mode with this new sandbox sandbox.interactive(instance._PUBLIC) + + if enable_readline then + -- save to history + local entries = readline.history_list() + 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 -- return module -- cgit v1.3.1