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:
Erica Marigold 2024-12-13 18:04:42 +00:00
parent 2f79159f95
commit 202dc85147
Signed by: DevComp
GPG key ID: 429EF1C337871656
2 changed files with 12 additions and 6 deletions

View file

@ -149,7 +149,6 @@ function installTool(tool: ToolId, installPath: pathfs.Path): number
end
end
barFns.stop(bar)
return error(`No release found for version {version}`)
end,
@ -211,7 +210,6 @@ function installTool(tool: ToolId, installPath: pathfs.Path): number
local decompressedPath = downloadAndDecompress(matchingAsset):unwrap()
binaryPath = decompressedPath:join(aliasPath)
if not pathfs.isFile(binaryPath) then
barFns.stop(bar)
error(`No matching binary found in {decompressedPath}`)
end
end
@ -328,6 +326,9 @@ return setmetatable(
)
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(` - {err}\n`)
return 1

View file

@ -55,10 +55,15 @@ function ProgressBar.start(self: ProgressBarImpl): ()
for _, spinner in SPINNERS do
local stage = self.stages[self.currentStageIndex]
stdio.write(
`\x1b[2K\x1b[0G{spinner} {stage.message}{string.rep(" ", MAX_MESSAGE_LENGTH - #stage.message)} [{string.rep(
BAR,
self.currentStageIndex
)}{string.rep(" ", TOTAL_BAR_LENGTH - (BAR_LENGTH * self.currentStageIndex))}] {self.currentStageIndex} / {#self.stages}`
`\x1b[2K\x1b[0G{stdio.color("cyan")}{spinner} {stage.message}{stdio.color("reset")}{string.rep(
" ",
MAX_MESSAGE_LENGTH - #stage.message
)} [{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)