summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTitanSnow <[email protected]>2017-04-30 16:27:44 +0800
committerTitanSnow <[email protected]>2017-04-30 16:27:44 +0800
commitd60de990ac2b66c0f0a3d1956e14368a8ee82007 (patch)
treed8aee4cd6675ff03e4b3c8f0b81dd602d049e3a8
parentc4befb68350f0c2cc25e4cfe3834a9b1f0ca66f8 (diff)
soft-wrap tasklist
-rw-r--r--xmake/core/base/option.lua69
1 files changed, 36 insertions, 33 deletions
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index 09cb148f6..352e64cc0 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -874,6 +874,38 @@ function option.show_menu(task)
end
end
+function get_linelen(st)
+ local poss = string.find(string.reverse(st), "\n")
+ if not poss then return (#st) end
+ local start_pos, _ = poss
+ return start_pos - 1
+end
+function inwidth_append(dst, st, padding, width, remain_width)
+ function get_lastspace(st)
+ local poss = string.find(string.reverse(st), "[%s-]")
+ if not poss then return (#st) end
+ local start_pos, _ = poss
+ return (#st) - start_pos + 1
+ end
+ if padding >= width then
+ return dst .. st
+ end
+ local white_padding = string.rep(" ", padding)
+ if remain_width == nil then remain_width = width - get_linelen(dst) end -- because of colored string, it's wrong sometimes
+ if remain_width <= 0 then
+ return inwidth_append(dst .. "\n" .. white_padding, st, padding, width, width - padding)
+ end
+ if (#st) <= remain_width then
+ return dst .. st
+ end
+ local lastspace = get_lastspace(string.sub(st, 1, remain_width))
+ if lastspace + 1 > (#st) then
+ return dst .. st
+ else
+ return inwidth_append(dst .. string.sub(st, 1, lastspace) .. "\n" .. white_padding, string.ltrim(string.sub(st, lastspace + 1)), padding, width, width - padding)
+ end
+end
+
-- show the main menu
function option.show_main()
@@ -953,6 +985,9 @@ function option.show_main()
-- the padding spaces
local padding = 42
+ -- get width of console
+ local console_width = os.getwinsize()["width"]
+
-- print tasks
for taskname, taskinfo in pairs(categorytask) do
@@ -977,7 +1012,7 @@ function option.show_main()
-- append the task description
if taskinfo.description then
- taskline = taskline .. taskinfo.description
+ taskline = inwidth_append(taskline, taskinfo.description, padding + 1 - 18, console_width, console_width - padding - 1 + 18)
end
-- print task line
@@ -1046,38 +1081,6 @@ function option.show_options(options)
-- append color
option_info = "${green}" .. option_info .. "${clear}"
- function get_linelen(st)
- local poss = string.find(string.reverse(st), "\n")
- if not poss then return (#st) end
- local start_pos, _ = poss
- return start_pos - 1
- end
- function inwidth_append(dst, st, padding, width, remain_width)
- function get_lastspace(st)
- local poss = string.find(string.reverse(st), "[%s-]")
- if not poss then return (#st) end
- local start_pos, _ = poss
- return (#st) - start_pos + 1
- end
- if padding >= width then
- return dst .. st
- end
- local white_padding = string.rep(" ", padding)
- if remain_width == nil then remain_width = width - get_linelen(dst) end -- because of colored string, it's wrong sometimes
- if remain_width <= 0 then
- return inwidth_append(dst .. "\n" .. white_padding, st, padding, width, width - padding)
- end
- if (#st) <= remain_width then
- return dst .. st
- end
- local lastspace = get_lastspace(string.sub(st, 1, remain_width))
- if lastspace + 1 > (#st) then
- return dst .. st
- else
- return inwidth_append(dst .. string.sub(st, 1, lastspace) .. "\n" .. white_padding, string.ltrim(string.sub(st, lastspace + 1)), padding, width, width - padding)
- end
- end
-
-- get width of console
local console_width = os.getwinsize()["width"]