diff options
| author | ruki <[email protected]> | 2020-05-31 16:23:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-31 16:23:03 +0800 |
| commit | be4e9c0603d410b6cb7706645f555b49d66b9096 (patch) | |
| tree | c8e326f7d555b00f168c0d274d5fa8939dcd46a6 | |
| parent | d7cc9758d1f7beb92a7898a556cb4ecc62e34d32 (diff) | |
improve progress without scroll
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/utils/progress.lua | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index 0440667b0..ff84a01ce 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -185,7 +185,7 @@ function sandbox_utils.clearline() if not emptychars then -- get left width - local width = os.getwinsize()["width"] - 1 + local width = os.getwinsize()["width"] if not width or width <= 0 then width = 64 end diff --git a/xmake/modules/private/utils/progress.lua b/xmake/modules/private/utils/progress.lua index dbcc69a55..fb713f2bb 100644 --- a/xmake/modules/private/utils/progress.lua +++ b/xmake/modules/private/utils/progress.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.base.object") +import("core.base.colors") import("core.theme.theme") -- make back characters @@ -109,7 +110,16 @@ function show(progress, format, ...) cprint(progress_prefix .. format, progress, ...) else utils.clearline() - cprintf(progress_prefix .. format, progress, ...) + local msg = vformat(progress_prefix .. format, progress, ...) + local msg_plain = colors.translate(msg, {plain = true}) + local maxwidth = os.getwinsize().width + if #msg_plain <= maxwidth then + cprintf(msg) + else + -- windows width is too small? strip this message and disable colors + local partlen = math.floor(maxwidth / 2) - 3 + printf(msg_plain:sub(1, partlen) .. "..." .. msg_plain:sub(#msg_plain - partlen)) + end if math.floor(progress) == 100 then print("") _g.showing_without_scroll = false |
