mirror of
https://github.com/pesde-pkg/tooling.git
synced 2025-01-10 00:09:09 +00:00
feat(lib): make ProgressBar:nextStage
return a result
This commit is contained in:
parent
8a074d0406
commit
7bf8063366
1 changed files with 5 additions and 2 deletions
|
@ -3,8 +3,10 @@
|
||||||
local task = require("@lune/task")
|
local task = require("@lune/task")
|
||||||
local stdio = require("@lune/stdio")
|
local stdio = require("@lune/stdio")
|
||||||
|
|
||||||
|
local Result = require("../../lune_packages/result")
|
||||||
local Option = require("../../lune_packages/option")
|
local Option = require("../../lune_packages/option")
|
||||||
type Option<T> = Option.Option<T>
|
type Option<T> = Option.Option<T>
|
||||||
|
type Result<T, E> = Result.Result<T, E>
|
||||||
|
|
||||||
-- FORMAT: {SPINNER} {MESSAGE} {BAR} {STAGE}
|
-- FORMAT: {SPINNER} {MESSAGE} {BAR} {STAGE}
|
||||||
local SPINNERS = { "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
|
local SPINNERS = { "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
|
||||||
|
@ -79,15 +81,16 @@ function ProgressBar.stop(self: ProgressBarImpl): ()
|
||||||
stdio.write("\x1b[2K\x1b[0G")
|
stdio.write("\x1b[2K\x1b[0G")
|
||||||
end
|
end
|
||||||
|
|
||||||
function ProgressBar.nextStage(self: ProgressBarImpl): ()
|
function ProgressBar.nextStage(self: ProgressBarImpl): Result<nil, string>
|
||||||
local inc = self.currentStageIndex + 1
|
local inc = self.currentStageIndex + 1
|
||||||
if inc > #self.stages then
|
if inc > #self.stages then
|
||||||
-- TODO: Make this a result
|
-- TODO: Make this a result
|
||||||
self.finished = true
|
self.finished = true
|
||||||
return error("Out of stage bounds")
|
return Result.Err("OutOfBounds - Attempted to advance past last stage")
|
||||||
end
|
end
|
||||||
|
|
||||||
self.currentStageIndex = inc
|
self.currentStageIndex = inc
|
||||||
|
return Result.Ok(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
return ProgressBar
|
return ProgressBar
|
||||||
|
|
Loading…
Reference in a new issue