summaryrefslogtreecommitdiff
path: root/xmake/modules/private/utils/progress.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-31 16:23:03 +0800
committerruki <[email protected]>2020-05-31 16:23:03 +0800
commitbe4e9c0603d410b6cb7706645f555b49d66b9096 (patch)
treec8e326f7d555b00f168c0d274d5fa8939dcd46a6 /xmake/modules/private/utils/progress.lua
parentd7cc9758d1f7beb92a7898a556cb4ecc62e34d32 (diff)
improve progress without scroll
Diffstat (limited to 'xmake/modules/private/utils/progress.lua')
-rw-r--r--xmake/modules/private/utils/progress.lua12
1 files changed, 11 insertions, 1 deletions
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