mirror of
https://github.com/pesde-pkg/tooling.git
synced 2025-01-10 00:09:09 +00:00
fix(lib): progress bar interfering with warns
* Fixed overlapping warns and progress bar. * Removed unnecessary `resume` and `stop` bar methods.
This commit is contained in:
parent
f377116271
commit
2f79159f95
2 changed files with 19 additions and 36 deletions
|
@ -11,7 +11,6 @@ local net = require("@lune/net")
|
||||||
local process = require("@lune/process")
|
local process = require("@lune/process")
|
||||||
local stdio = require("@lune/stdio")
|
local stdio = require("@lune/stdio")
|
||||||
local serde = require("@lune/serde")
|
local serde = require("@lune/serde")
|
||||||
local task = require("@lune/task")
|
|
||||||
|
|
||||||
local pathfs = require("../lune_packages/pathfs")
|
local pathfs = require("../lune_packages/pathfs")
|
||||||
local dirs = require("../lune_packages/dirs")
|
local dirs = require("../lune_packages/dirs")
|
||||||
|
@ -116,21 +115,19 @@ end
|
||||||
local function makeConditionalBar()
|
local function makeConditionalBar()
|
||||||
local function makeConditional(fn: (ProgressBar.ProgressBarImpl) -> ())
|
local function makeConditional(fn: (ProgressBar.ProgressBarImpl) -> ())
|
||||||
return function(bar: ProgressBar.ProgressBarImpl)
|
return function(bar: ProgressBar.ProgressBarImpl)
|
||||||
local _ = _G.interactive and task.spawn(fn, bar)
|
local _ = _G.interactive and fn(bar)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
next = makeConditional(bar.nextStage),
|
next = makeConditional(bar.nextStage),
|
||||||
pause = makeConditional(bar.pause),
|
stop = makeConditional(bar.stop),
|
||||||
resume = makeConditional(bar.resume),
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.interactive = false
|
_G.interactive = false
|
||||||
function installTool(tool: ToolId, installPath: pathfs.Path)
|
function installTool(tool: ToolId, installPath: pathfs.Path): number
|
||||||
local barFns = makeConditionalBar()
|
local barFns = makeConditionalBar()
|
||||||
barFns.next(bar)
|
|
||||||
|
|
||||||
local toolAlias = toolAliasOrDefault(tool)
|
local toolAlias = toolAliasOrDefault(tool)
|
||||||
local client = Github.new(
|
local client = Github.new(
|
||||||
|
@ -142,7 +139,7 @@ function installTool(tool: ToolId, installPath: pathfs.Path)
|
||||||
}) :: Option<Github.Config>
|
}) :: Option<Github.Config>
|
||||||
)
|
)
|
||||||
|
|
||||||
barFns.next(bar)
|
barFns.next(bar) -- fetch
|
||||||
local releases = client:queueTransactions({ "FetchReleases" })[1]:unwrap() :: GithubReleases
|
local releases = client:queueTransactions({ "FetchReleases" })[1]:unwrap() :: GithubReleases
|
||||||
local assets = tool.version:match({
|
local assets = tool.version:match({
|
||||||
Some = function(version: string)
|
Some = function(version: string)
|
||||||
|
@ -152,7 +149,7 @@ function installTool(tool: ToolId, installPath: pathfs.Path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
barFns.pause(bar)
|
barFns.stop(bar)
|
||||||
return error(`No release found for version {version}`)
|
return error(`No release found for version {version}`)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -161,7 +158,7 @@ function installTool(tool: ToolId, installPath: pathfs.Path)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
barFns.next(bar)
|
barFns.next(bar) -- locate
|
||||||
-- TODO: Use index type fn in solver v2
|
-- TODO: Use index type fn in solver v2
|
||||||
local matchingAsset: {
|
local matchingAsset: {
|
||||||
name: string,
|
name: string,
|
||||||
|
@ -186,14 +183,14 @@ function installTool(tool: ToolId, installPath: pathfs.Path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
barFns.next(bar) -- download
|
||||||
|
-- task.delay(0.1, barFns.next, bar) -- download
|
||||||
|
|
||||||
local binaryPath: pathfs.Path
|
local binaryPath: pathfs.Path
|
||||||
if matchingAsset == nil then
|
if matchingAsset == nil then
|
||||||
barFns.pause(bar)
|
stdio.write("\x1b[2K\x1b[0G")
|
||||||
warn("Pesde could not find a matching binary for your system")
|
warn("Pesde could not find a matching binary for your system")
|
||||||
warn("Will now attempt to download all binaries and find a matching one")
|
warn("Will now attempt to download all binaries and find a matching one")
|
||||||
barFns.resume(bar)
|
|
||||||
|
|
||||||
barFns.next(bar)
|
|
||||||
|
|
||||||
for _, asset in assets do
|
for _, asset in assets do
|
||||||
local decompressedPath = downloadAndDecompress(asset)
|
local decompressedPath = downloadAndDecompress(asset)
|
||||||
|
@ -214,12 +211,13 @@ function installTool(tool: ToolId, installPath: pathfs.Path)
|
||||||
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.pause(bar)
|
barFns.stop(bar)
|
||||||
error(`No matching binary found in {decompressedPath}`)
|
error(`No matching binary found in {decompressedPath}`)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
barFns.next(bar)
|
barFns.next(bar) -- install
|
||||||
|
|
||||||
-- Maintain multiple versions of a tool, and avoid downloading
|
-- Maintain multiple versions of a tool, and avoid downloading
|
||||||
-- the binary for a version again if it's already there
|
-- the binary for a version again if it's already there
|
||||||
local toolDir = Option.from(installPath:parent()):unwrap()
|
local toolDir = Option.from(installPath:parent()):unwrap()
|
||||||
|
@ -250,14 +248,11 @@ function installTool(tool: ToolId, installPath: pathfs.Path)
|
||||||
-- ...
|
-- ...
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- Stop the progress bar and clean it up from stdout
|
barFns.stop(bar)
|
||||||
bar:stop()
|
|
||||||
task.cancel(bar.thread :: thread)
|
|
||||||
stdio.write("\x1b[2K\x1b[0G")
|
|
||||||
|
|
||||||
-- NOTE: This is equivalent to `0o755` or `rwxr-xr-x`
|
-- NOTE: This is equivalent to `0o755` or `rwxr-xr-x`
|
||||||
chmod(installPath, 0b10101010011)
|
chmod(installPath, 0b10101010011)
|
||||||
runTool(installPath)
|
return runTool(installPath)
|
||||||
end
|
end
|
||||||
|
|
||||||
type LibExports = {
|
type LibExports = {
|
||||||
|
@ -321,7 +316,7 @@ return setmetatable(
|
||||||
return lib.runTool(toolInstallPath)
|
return lib.runTool(toolInstallPath)
|
||||||
end
|
end
|
||||||
|
|
||||||
bar:start()
|
bar:start() -- init
|
||||||
local ok, err = pcall(
|
local ok, err = pcall(
|
||||||
lib.installTool,
|
lib.installTool,
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,11 +52,6 @@ function ProgressBar.start(self: ProgressBarImpl): ()
|
||||||
|
|
||||||
self.thread = task.spawn(function()
|
self.thread = task.spawn(function()
|
||||||
while not self.finished do
|
while not self.finished do
|
||||||
if self.currentStageIndex == #self.stages then
|
|
||||||
self:stop()
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
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(
|
||||||
|
@ -69,21 +64,14 @@ function ProgressBar.start(self: ProgressBarImpl): ()
|
||||||
task.wait(0.1)
|
task.wait(0.1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
stdio.write("\n")
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ProgressBar.stop(self: ProgressBarImpl): ()
|
function ProgressBar.stop(self: ProgressBarImpl): ()
|
||||||
|
-- Trigger upvalue, kill thread and clean progress bar remnant
|
||||||
self.finished = true
|
self.finished = true
|
||||||
end
|
task.cancel(self.thread :: thread)
|
||||||
|
stdio.write("\x1b[2K\x1b[0G")
|
||||||
function ProgressBar.pause(self: ProgressBarImpl): ()
|
|
||||||
local _ = self.thread and coroutine.yield(self.thread)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ProgressBar.resume(self: ProgressBarImpl): ()
|
|
||||||
local _ = self.thread and coroutine.resume(self.thread)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ProgressBar.nextStage(self: ProgressBarImpl): ()
|
function ProgressBar.nextStage(self: ProgressBarImpl): ()
|
||||||
|
|
Loading…
Reference in a new issue