summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpportunity <[email protected]>2020-01-19 10:38:00 +0800
committerOpportunity <[email protected]>2020-01-19 13:01:09 +0800
commit64e5558f64182191e39037f3bbce9a1b7bdf3a5b (patch)
tree677f83c93366eb51f0d588787aa14d3938044e1e
parentb22274761d5370abfcb868b001d72f0456e4a34d (diff)
narrow mode
-rw-r--r--xmake/core/base/option.lua51
1 files changed, 36 insertions, 15 deletions
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index e03c4dc1d..4fa61ad12 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -55,6 +55,12 @@ function option._translate(menu)
return true
end
+function option._modenarrow()
+ -- show menu in narrow mode?
+ local width = os.getwinsize().width
+ return width > 0 and width < 60
+end
+
-- get the top context
function option._context()
@@ -609,6 +615,8 @@ function option.show_main()
-- print tasks
if main.tasks then
+ local narrow = option._modenarrow()
+
-- make task categories
local categories = {}
for taskname, taskinfo in pairs(main.tasks) do
@@ -651,7 +659,7 @@ function option.show_main()
for taskname, taskinfo in pairs(category.tasks) do
-- init the task line
- local taskline = string.format(" %s%s",
+ local taskline = string.format(narrow and " %s%s" or " %s%s",
taskinfo.shortname and (taskinfo.shortname .. ", ") or " ",
taskname)
table.insert(tablecontent, {taskline, taskinfo.description or ""})
@@ -661,7 +669,7 @@ function option.show_main()
-- set table styles
tablecontent.style = {"${color.menu.main.task.name}"}
tablecontent.width = {nil, "auto"}
- tablecontent.sep = " "
+ tablecontent.sep = narrow and " " or " "
-- print table
io.write(text.table(tablecontent))
@@ -697,6 +705,9 @@ function option.show_options(options, taskname)
end
end
+ -- narrow mode?
+ local narrow = option._modenarrow()
+
-- print header
local tablecontent = {}
table.insert(tablecontent, {})
@@ -723,40 +734,38 @@ function option.show_options(options, taskname)
table.insert(tablecontent, {})
else
- -- init the option info
- local option_info
-
-- append the shortname
local shortname = opt[1]
local name = opt[2]
local mode = opt[3]
local default = opt[4]
+
+ local title1, title2
+ local kvplaceholder = mode == "kv" and ((type(default) == "boolean") and "[y|n]" or(name and name:upper() or "XXX"))
if shortname then
if mode == "kv" then
- option_info = " -" .. shortname .. " " .. (name and name:upper() or "XXX")
+ title1 = "-" .. shortname .. " " .. kvplaceholder
else
- option_info = " -" .. shortname
+ title1 = "-" .. shortname
end
- else
- option_info = " "
end
-- append the name
if name then
- local leading = (shortname and "," or " ") .. (mode:startswith("k") and " --" or " ")
+ local leading = mode:startswith("k") and "--" or " "
local kv
if mode == "k" then
kv = name
elseif mode == "kv" then
- kv = (name .. "=" .. ((type(default) == "boolean") and "[y|n]" or name:upper()))
+ kv = name .. "=" .. kvplaceholder
elseif mode == "vs" then
kv = name .. " ..."
else
kv = name
end
- option_info = option_info .. leading .. kv
+ title2 = leading .. kv
elseif mode == "v" or mode == "vs" then
- option_info = option_info .. " ..."
+ title2 = " ..."
end
-- get description
@@ -801,14 +810,26 @@ function option.show_options(options, taskname)
end
-- insert row
- table.insert(tablecontent, {option_info, desp_strs})
+ if narrow then
+ if title1 then
+ table.insert(tablecontent, {{" " .. title1, " " .. title2 }, desp_strs})
+ else
+ table.insert(tablecontent, {{" " .. title2 }, desp_strs})
+ end
+ else
+ if title1 then
+ table.insert(tablecontent, {" " .. title1 .. ", " .. title2 , desp_strs})
+ else
+ table.insert(tablecontent, {" " .. title2 , desp_strs})
+ end
+ end
end
end
-- set table styles
tablecontent.style = {"${color.menu.option.name}"}
tablecontent.width = {nil, "auto"}
- tablecontent.sep = " "
+ tablecontent.sep = narrow and " " or " "
-- print table
io.write(text.table(tablecontent))