diff options
| author | ruki <[email protected]> | 2020-03-24 22:35:14 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-03-24 09:31:24 +0800 |
| commit | 5fd9b5d24e354dfc0588a04d40b4e08ab0c430c9 (patch) | |
| tree | 3264528462d204878abfd690375c0624d9dbcfbe | |
| parent | 5218660a642fc31120c34d8ede2de093011c57db (diff) | |
improve interactive prompt
| -rw-r--r-- | core/src/xmake/sandbox/interactive.c | 25 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua | 10 | ||||
| -rw-r--r-- | xmake/themes/dark/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/themes/default/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/themes/emoji/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/themes/plain/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/themes/powershell/xmake.lua | 6 |
7 files changed, 52 insertions, 13 deletions
diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c index a72e8df01..6ee010e24 100644 --- a/core/src/xmake/sandbox/interactive.c +++ b/core/src/xmake/sandbox/interactive.c @@ -48,12 +48,6 @@ * macros */ -// interactive prompt -#define LUA_PROMPT "> " - -// continuation prompt -#define LUA_PROMPT2 ">> " - // buffer size for prompt #define LUA_PROMPT_BUFSIZE 4096 @@ -185,11 +179,11 @@ static tb_size_t xm_sandbox_readline(tb_char_t* data, tb_size_t maxn, tb_char_t } // read and push input line -static tb_int_t xm_sandbox_pushline(lua_State* lua) +static tb_int_t xm_sandbox_pushline(lua_State* lua, tb_char_t const* prompt2) { // read line tb_char_t data[LUA_PROMPT_BUFSIZE]; - tb_size_t size = xm_sandbox_readline(data, sizeof(data), LUA_PROMPT2); + tb_size_t size = xm_sandbox_readline(data, sizeof(data), prompt2); if (size) { // split line '\0' @@ -213,10 +207,21 @@ static tb_int_t xm_sandbox_loadline(lua_State* lua, tb_int_t top) // clear stack lua_settop(lua, top); + // get prompt strings from arg1(sandbox_scope) + lua_pushstring(lua, "$interactive_prompt"); + lua_gettable(lua, 1); + tb_char_t const* prompt = lua_tostring(lua, -1); + lua_pop(lua, 1); + + lua_pushstring(lua, "$interactive_prompt2"); + lua_gettable(lua, 1); + tb_char_t const* prompt2 = lua_tostring(lua, -1); + lua_pop(lua, 1); + // read first line tb_int_t status; tb_char_t data[LUA_PROMPT_BUFSIZE]; - tb_size_t size = xm_sandbox_readline(data + 7, sizeof(data) - 7, LUA_PROMPT); + tb_size_t size = xm_sandbox_readline(data + 7, sizeof(data) - 7, prompt); if (size) { // split line '\0' @@ -254,7 +259,7 @@ static tb_int_t xm_sandbox_loadline(lua_State* lua, tb_int_t top) if (!xm_sandbox_incomplete(lua, status)) break; // get more input - if (!xm_sandbox_pushline(lua)) return -1; + if (!xm_sandbox_pushline(lua, prompt2)) return -1; // cancel multi-line input? if (!tb_strcmp(lua_tostring(lua, -1), "q")) diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua index 2440af74b..308112df3 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua @@ -28,10 +28,11 @@ local try = require("sandbox/modules/try") local catch = require("sandbox/modules/catch") local utils = require("base/utils") local table = require("base/table") -local history = require("project/history") +local colors = require("base/colors") local dump = require("base/dump") local option = require("base/option") local scheduler = require("base/scheduler") +local history = require("project/history") -- print variables for interactive mode function sandbox_core_sandbox._interactive_dump(...) @@ -88,13 +89,16 @@ function sandbox_core_sandbox.interactive() end -- register dump function for interactive mode - instance._PUBLIC["$interactive_dump"] = sandbox_core_sandbox._interactive_dump + local public_scope = instance._PUBLIC + public_scope["$interactive_dump"] = sandbox_core_sandbox._interactive_dump + public_scope["$interactive_prompt"] = colors.translate("${color.interactive.prompt}${text.interactive.prompt} ") + public_scope["$interactive_prompt2"] = colors.translate("${color.interactive.prompt2}${text.interactive.prompt2} ") -- disable scheduler scheduler:enable(false) -- enter interactive mode with this new sandbox - sandbox.interactive(instance._PUBLIC) + sandbox.interactive(public_scope) -- enable scheduler scheduler:enable(true) diff --git a/xmake/themes/dark/xmake.lua b/xmake/themes/dark/xmake.lua index cf2a340f0..e01758d37 100644 --- a/xmake/themes/dark/xmake.lua +++ b/xmake/themes/dark/xmake.lua @@ -72,3 +72,9 @@ theme("dark") set_color("menu.main.task.name", "magenta") set_color("menu.option.name", "green") set_color("menu.usage", "cyan") + + -- interactive mode + set_text("interactive.prompt", "xmake>") + set_text("interactive.prompt2", "xmake>>") + set_color("interactive.prompt", "green bright") + set_color("interactive.prompt2", "green") diff --git a/xmake/themes/default/xmake.lua b/xmake/themes/default/xmake.lua index 010fa6760..26da87369 100644 --- a/xmake/themes/default/xmake.lua +++ b/xmake/themes/default/xmake.lua @@ -72,3 +72,9 @@ theme("default") set_color("menu.main.task.name", "magenta") set_color("menu.option.name", "green") set_color("menu.usage", "cyan") + + -- interactive mode + set_text("interactive.prompt", "xmake>") + set_text("interactive.prompt2", "xmake>>") + set_color("interactive.prompt", "green bright") + set_color("interactive.prompt2", "green") diff --git a/xmake/themes/emoji/xmake.lua b/xmake/themes/emoji/xmake.lua index 7eb4b85ed..91abd8180 100644 --- a/xmake/themes/emoji/xmake.lua +++ b/xmake/themes/emoji/xmake.lua @@ -72,3 +72,9 @@ theme("emoji") set_color("menu.main.task.name", "magenta") set_color("menu.option.name", "green") set_color("menu.usage", "cyan") + + -- interactive mode + set_text("interactive.prompt", "xmake>") + set_text("interactive.prompt2", "xmake>>") + set_color("interactive.prompt", "green bright") + set_color("interactive.prompt2", "green") diff --git a/xmake/themes/plain/xmake.lua b/xmake/themes/plain/xmake.lua index c7c61516b..b47bfaea0 100644 --- a/xmake/themes/plain/xmake.lua +++ b/xmake/themes/plain/xmake.lua @@ -72,3 +72,9 @@ theme("plain") set_color("menu.main.task.name", "") set_color("menu.option.name", "") set_color("menu.usage", "") + + -- interactive mode + set_text("interactive.prompt", "xmake>") + set_text("interactive.prompt2", "xmake>>") + set_color("interactive.prompt", "") + set_color("interactive.prompt2", "") diff --git a/xmake/themes/powershell/xmake.lua b/xmake/themes/powershell/xmake.lua index 7cfbf1ec1..710800a3a 100644 --- a/xmake/themes/powershell/xmake.lua +++ b/xmake/themes/powershell/xmake.lua @@ -72,3 +72,9 @@ theme("powershell") set_color("menu.main.task.name", "cyan bright") set_color("menu.option.name", "green bright") set_color("menu.usage", "cyan") + + -- interactive mode + set_text("interactive.prompt", "xmake>") + set_text("interactive.prompt2", "xmake>>") + set_color("interactive.prompt", "green bright") + set_color("interactive.prompt2", "green") |
