mirror of
https://github.com/pesde-pkg/tooling.git
synced 2025-01-10 08:19:10 +00:00
feat(lib): add a touch of color to progress bar
Also moves bar stopping logic for errors into pcall handler.
This commit is contained in:
parent
2f79159f95
commit
202dc85147
2 changed files with 12 additions and 6 deletions
|
@ -149,7 +149,6 @@ function installTool(tool: ToolId, installPath: pathfs.Path): number
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
barFns.stop(bar)
|
|
||||||
return error(`No release found for version {version}`)
|
return error(`No release found for version {version}`)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -211,7 +210,6 @@ function installTool(tool: ToolId, installPath: pathfs.Path): number
|
||||||
local decompressedPath = downloadAndDecompress(matchingAsset):unwrap()
|
local decompressedPath = downloadAndDecompress(matchingAsset):unwrap()
|
||||||
binaryPath = decompressedPath:join(aliasPath)
|
binaryPath = decompressedPath:join(aliasPath)
|
||||||
if not pathfs.isFile(binaryPath) then
|
if not pathfs.isFile(binaryPath) then
|
||||||
barFns.stop(bar)
|
|
||||||
error(`No matching binary found in {decompressedPath}`)
|
error(`No matching binary found in {decompressedPath}`)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -328,6 +326,9 @@ return setmetatable(
|
||||||
)
|
)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
|
-- Cleanup progress bar in case of error
|
||||||
|
makeConditionalBar().stop(bar)
|
||||||
|
|
||||||
stdio.ewrite(`{ERROR_PREFIX} Failed to install {tool}\n`)
|
stdio.ewrite(`{ERROR_PREFIX} Failed to install {tool}\n`)
|
||||||
stdio.ewrite(` - {err}\n`)
|
stdio.ewrite(` - {err}\n`)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -55,10 +55,15 @@ function ProgressBar.start(self: ProgressBarImpl): ()
|
||||||
for _, spinner in SPINNERS do
|
for _, spinner in SPINNERS do
|
||||||
local stage = self.stages[self.currentStageIndex]
|
local stage = self.stages[self.currentStageIndex]
|
||||||
stdio.write(
|
stdio.write(
|
||||||
`\x1b[2K\x1b[0G{spinner} {stage.message}{string.rep(" ", MAX_MESSAGE_LENGTH - #stage.message)} [{string.rep(
|
`\x1b[2K\x1b[0G{stdio.color("cyan")}{spinner} {stage.message}{stdio.color("reset")}{string.rep(
|
||||||
BAR,
|
" ",
|
||||||
self.currentStageIndex
|
MAX_MESSAGE_LENGTH - #stage.message
|
||||||
)}{string.rep(" ", TOTAL_BAR_LENGTH - (BAR_LENGTH * self.currentStageIndex))}] {self.currentStageIndex} / {#self.stages}`
|
)} [{stdio.style("dim")}{string.rep(BAR, self.currentStageIndex)}{string.rep(
|
||||||
|
" ",
|
||||||
|
TOTAL_BAR_LENGTH - (BAR_LENGTH * self.currentStageIndex)
|
||||||
|
)}{stdio.style("reset")}] {stdio.style("bold")}{self.currentStageIndex} / {#self.stages}{stdio.style(
|
||||||
|
"reset"
|
||||||
|
)}`
|
||||||
)
|
)
|
||||||
|
|
||||||
task.wait(0.1)
|
task.wait(0.1)
|
||||||
|
|
Loading…
Reference in a new issue