feat: infer command line interactivity from the process context (#8)

* chore: update lockfiles

* feat: guess whether command was invoked non-interactively

Previously, it was made possible to control the interactivity status of the
progress bar by setting `_G.interactive`. However, this was not
automatically inferred from the context the process was started from,
and was expected to be manually set by the library invoker.

Non-interactivity status is now inferred automatically based on the
context the command was called from.

* feat: introduce `PESDE_TOOLING_FORCE_INTERACTIVE` override

This environment variable allows overriding the result of the
interactivity status guess by setting it to any non-empty value.

* fix: accidentally forcing users to set env var to get noninteractivity

* style: apply `stylua` formatter
This commit is contained in:
Erica Marigold 2025-04-19 09:36:12 +01:00 committed by GitHub
parent 1746737697
commit 65cc1720ac
Signed by: DevComp
GPG key ID: B5690EEEBB952194
11 changed files with 113 additions and 55 deletions

View file

@ -50,25 +50,25 @@ resolved_ty = "standard"
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/pesde-pkg/index" index_url = "https://github.com/pesde-pkg/index"
[graph."jiwonz/luau_path@0.1.1 luau"] [graph."jiwonz/luau_path@0.1.3 luau"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/luau_path@0.1.1 luau".dependencies] [graph."jiwonz/luau_path@0.1.3 luau".dependencies]
"jiwonz/luau_disk@0.1.4 luau" = "luau_disk" "jiwonz/luau_disk@0.1.4 luau" = "luau_disk"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/daimond113/pesde-index" index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies]
luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"]
[graph."jiwonz/pathfs@0.3.2 lune"] [graph."jiwonz/pathfs@0.3.2 lune"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/pathfs@0.3.2 lune".dependencies] [graph."jiwonz/pathfs@0.3.2 lune".dependencies]
"corecii/greentea@0.4.11 lune" = "greentea" "corecii/greentea@0.4.11 lune" = "greentea"
"jiwonz/luau_path@0.1.1 luau" = "luau_path" "jiwonz/luau_path@0.1.3 luau" = "luau_path"
[graph."jiwonz/pathfs@0.3.2 lune".pkg_ref] [graph."jiwonz/pathfs@0.3.2 lune".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"

View file

@ -50,25 +50,25 @@ resolved_ty = "standard"
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/pesde-pkg/index" index_url = "https://github.com/pesde-pkg/index"
[graph."jiwonz/luau_path@0.1.1 luau"] [graph."jiwonz/luau_path@0.1.3 luau"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/luau_path@0.1.1 luau".dependencies] [graph."jiwonz/luau_path@0.1.3 luau".dependencies]
"jiwonz/luau_disk@0.1.4 luau" = "luau_disk" "jiwonz/luau_disk@0.1.4 luau" = "luau_disk"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/daimond113/pesde-index" index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies]
luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"]
[graph."jiwonz/pathfs@0.3.2 lune"] [graph."jiwonz/pathfs@0.3.2 lune"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/pathfs@0.3.2 lune".dependencies] [graph."jiwonz/pathfs@0.3.2 lune".dependencies]
"corecii/greentea@0.4.11 lune" = "greentea" "corecii/greentea@0.4.11 lune" = "greentea"
"jiwonz/luau_path@0.1.1 luau" = "luau_path" "jiwonz/luau_path@0.1.3 luau" = "luau_path"
[graph."jiwonz/pathfs@0.3.2 lune".pkg_ref] [graph."jiwonz/pathfs@0.3.2 lune".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"

View file

@ -50,25 +50,25 @@ resolved_ty = "standard"
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/pesde-pkg/index" index_url = "https://github.com/pesde-pkg/index"
[graph."jiwonz/luau_path@0.1.1 luau"] [graph."jiwonz/luau_path@0.1.3 luau"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/luau_path@0.1.1 luau".dependencies] [graph."jiwonz/luau_path@0.1.3 luau".dependencies]
"jiwonz/luau_disk@0.1.4 luau" = "luau_disk" "jiwonz/luau_disk@0.1.4 luau" = "luau_disk"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/daimond113/pesde-index" index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies]
luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"]
[graph."jiwonz/pathfs@0.3.2 lune"] [graph."jiwonz/pathfs@0.3.2 lune"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/pathfs@0.3.2 lune".dependencies] [graph."jiwonz/pathfs@0.3.2 lune".dependencies]
"corecii/greentea@0.4.11 lune" = "greentea" "corecii/greentea@0.4.11 lune" = "greentea"
"jiwonz/luau_path@0.1.1 luau" = "luau_path" "jiwonz/luau_path@0.1.3 luau" = "luau_path"
[graph."jiwonz/pathfs@0.3.2 lune".pkg_ref] [graph."jiwonz/pathfs@0.3.2 lune".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"

View file

@ -50,25 +50,25 @@ resolved_ty = "standard"
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/pesde-pkg/index" index_url = "https://github.com/pesde-pkg/index"
[graph."jiwonz/luau_path@0.1.1 luau"] [graph."jiwonz/luau_path@0.1.3 luau"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/luau_path@0.1.1 luau".dependencies] [graph."jiwonz/luau_path@0.1.3 luau".dependencies]
"jiwonz/luau_disk@0.1.4 luau" = "luau_disk" "jiwonz/luau_disk@0.1.4 luau" = "luau_disk"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/daimond113/pesde-index" index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies]
luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"]
[graph."jiwonz/pathfs@0.3.2 lune"] [graph."jiwonz/pathfs@0.3.2 lune"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/pathfs@0.3.2 lune".dependencies] [graph."jiwonz/pathfs@0.3.2 lune".dependencies]
"corecii/greentea@0.4.11 lune" = "greentea" "corecii/greentea@0.4.11 lune" = "greentea"
"jiwonz/luau_path@0.1.1 luau" = "luau_path" "jiwonz/luau_path@0.1.3 luau" = "luau_path"
[graph."jiwonz/pathfs@0.3.2 lune".pkg_ref] [graph."jiwonz/pathfs@0.3.2 lune".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"

View file

@ -50,25 +50,25 @@ resolved_ty = "standard"
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/pesde-pkg/index" index_url = "https://github.com/pesde-pkg/index"
[graph."jiwonz/luau_path@0.1.1 luau"] [graph."jiwonz/luau_path@0.1.3 luau"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/luau_path@0.1.1 luau".dependencies] [graph."jiwonz/luau_path@0.1.3 luau".dependencies]
"jiwonz/luau_disk@0.1.4 luau" = "luau_disk" "jiwonz/luau_disk@0.1.4 luau" = "luau_disk"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/daimond113/pesde-index" index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies]
luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"]
[graph."jiwonz/pathfs@0.3.2 lune"] [graph."jiwonz/pathfs@0.3.2 lune"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/pathfs@0.3.2 lune".dependencies] [graph."jiwonz/pathfs@0.3.2 lune".dependencies]
"corecii/greentea@0.4.11 lune" = "greentea" "corecii/greentea@0.4.11 lune" = "greentea"
"jiwonz/luau_path@0.1.1 luau" = "luau_path" "jiwonz/luau_path@0.1.3 luau" = "luau_path"
[graph."jiwonz/pathfs@0.3.2 lune".pkg_ref] [graph."jiwonz/pathfs@0.3.2 lune".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"

View file

@ -50,25 +50,25 @@ resolved_ty = "standard"
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/pesde-pkg/index" index_url = "https://github.com/pesde-pkg/index"
[graph."jiwonz/luau_path@0.1.1 luau"] [graph."jiwonz/luau_path@0.1.3 luau"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/luau_path@0.1.1 luau".dependencies] [graph."jiwonz/luau_path@0.1.3 luau".dependencies]
"jiwonz/luau_disk@0.1.4 luau" = "luau_disk" "jiwonz/luau_disk@0.1.4 luau" = "luau_disk"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/daimond113/pesde-index" index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies]
luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"]
[graph."jiwonz/pathfs@0.3.2 lune"] [graph."jiwonz/pathfs@0.3.2 lune"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/pathfs@0.3.2 lune".dependencies] [graph."jiwonz/pathfs@0.3.2 lune".dependencies]
"corecii/greentea@0.4.11 lune" = "greentea" "corecii/greentea@0.4.11 lune" = "greentea"
"jiwonz/luau_path@0.1.1 luau" = "luau_path" "jiwonz/luau_path@0.1.3 luau" = "luau_path"
[graph."jiwonz/pathfs@0.3.2 lune".pkg_ref] [graph."jiwonz/pathfs@0.3.2 lune".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"

View file

@ -50,25 +50,25 @@ resolved_ty = "standard"
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/pesde-pkg/index" index_url = "https://github.com/pesde-pkg/index"
[graph."jiwonz/luau_path@0.1.1 luau"] [graph."jiwonz/luau_path@0.1.3 luau"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/luau_path@0.1.1 luau".dependencies] [graph."jiwonz/luau_path@0.1.3 luau".dependencies]
"jiwonz/luau_disk@0.1.4 luau" = "luau_disk" "jiwonz/luau_disk@0.1.4 luau" = "luau_disk"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/daimond113/pesde-index" index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies]
luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"]
[graph."jiwonz/pathfs@0.3.2 lune"] [graph."jiwonz/pathfs@0.3.2 lune"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/pathfs@0.3.2 lune".dependencies] [graph."jiwonz/pathfs@0.3.2 lune".dependencies]
"corecii/greentea@0.4.11 lune" = "greentea" "corecii/greentea@0.4.11 lune" = "greentea"
"jiwonz/luau_path@0.1.1 luau" = "luau_path" "jiwonz/luau_path@0.1.3 luau" = "luau_path"
[graph."jiwonz/pathfs@0.3.2 lune".pkg_ref] [graph."jiwonz/pathfs@0.3.2 lune".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"

View file

@ -50,25 +50,25 @@ resolved_ty = "standard"
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/pesde-pkg/index" index_url = "https://github.com/pesde-pkg/index"
[graph."jiwonz/luau_path@0.1.1 luau"] [graph."jiwonz/luau_path@0.1.3 luau"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/luau_path@0.1.1 luau".dependencies] [graph."jiwonz/luau_path@0.1.3 luau".dependencies]
"jiwonz/luau_disk@0.1.4 luau" = "luau_disk" "jiwonz/luau_disk@0.1.4 luau" = "luau_disk"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/daimond113/pesde-index" index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies]
luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"]
[graph."jiwonz/pathfs@0.3.2 lune"] [graph."jiwonz/pathfs@0.3.2 lune"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/pathfs@0.3.2 lune".dependencies] [graph."jiwonz/pathfs@0.3.2 lune".dependencies]
"corecii/greentea@0.4.11 lune" = "greentea" "corecii/greentea@0.4.11 lune" = "greentea"
"jiwonz/luau_path@0.1.1 luau" = "luau_path" "jiwonz/luau_path@0.1.3 luau" = "luau_path"
[graph."jiwonz/pathfs@0.3.2 lune".pkg_ref] [graph."jiwonz/pathfs@0.3.2 lune".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"

View file

@ -50,25 +50,25 @@ resolved_ty = "standard"
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/pesde-pkg/index" index_url = "https://github.com/pesde-pkg/index"
[graph."jiwonz/luau_path@0.1.1 luau"] [graph."jiwonz/luau_path@0.1.3 luau"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/luau_path@0.1.1 luau".dependencies] [graph."jiwonz/luau_path@0.1.3 luau".dependencies]
"jiwonz/luau_disk@0.1.4 luau" = "luau_disk" "jiwonz/luau_disk@0.1.4 luau" = "luau_disk"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"
index_url = "https://github.com/daimond113/pesde-index" index_url = "https://github.com/daimond113/pesde-index"
[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] [graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies]
luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.4", index = "https://github.com/pesde-pkg/index" }, "standard"]
[graph."jiwonz/pathfs@0.3.2 lune"] [graph."jiwonz/pathfs@0.3.2 lune"]
resolved_ty = "standard" resolved_ty = "standard"
[graph."jiwonz/pathfs@0.3.2 lune".dependencies] [graph."jiwonz/pathfs@0.3.2 lune".dependencies]
"corecii/greentea@0.4.11 lune" = "greentea" "corecii/greentea@0.4.11 lune" = "greentea"
"jiwonz/luau_path@0.1.1 luau" = "luau_path" "jiwonz/luau_path@0.1.3 luau" = "luau_path"
[graph."jiwonz/pathfs@0.3.2 lune".pkg_ref] [graph."jiwonz/pathfs@0.3.2 lune".pkg_ref]
ref_ty = "pesde" ref_ty = "pesde"

View file

@ -30,6 +30,7 @@ local ProgressBar = require("./utils/progress")
local compression = require("./compression") local compression = require("./compression")
local eq = require("./utils/eq") local eq = require("./utils/eq")
local manifest = require("./manifest") local manifest = require("./manifest")
local sys = require("./utils/sys")
export type ToolId = { export type ToolId = {
alias: Option<string>, alias: Option<string>,
@ -165,8 +166,13 @@ local function getGithubToken(): Option<string>
end) end)
end end
local function isInteractive(): boolean
return process.env.PESDE_TOOLING_FORCE_INTERACTIVE ~= nil
or (sys.isTTY("stdout") and process.env.TERM ~= "dumb" and process.env.CI == nil)
end
-- Initialize the shared global progress bar state -- Initialize the shared global progress bar state
_G.interactive = nil _G.interactive = isInteractive() or nil
local barFns local barFns
function installTool(tool: ToolId, installPath: pathfs.Path): number function installTool(tool: ToolId, installPath: pathfs.Path): number

View file

@ -0,0 +1,52 @@
--> Non-exhaustive set of util functions for Linux systems
local process = require("@lune/process")
local ResultExt = require("./ext/result")
local fs = require("../../lune_packages/pathfs").fs
local Result = require("../../lune_packages/result")
local Option = require("../../lune_packages/option")
local sys = {}
sys.consts = {
S_IFMT = 0xF000,
S_IFCHR = 0x2000,
}
export type StdioFd = "stdin" | "stdout" | "stderr"
local STDIO_FD_LOOKUP: { [StdioFd]: number } = {
stdin = 0,
stdout = 1,
stderr = 2,
}
function sys.isCharacterDevice(mode: number)
return bit32.band(mode, sys.consts.S_IFMT) == sys.consts.S_IFCHR
end
function sys.isTTY(fd: number | StdioFd): boolean
if process.os ~= "linux" then
-- idk about windows and macOS :p
return true
end
local inputFd: number = if typeof(fd) == "string" then STDIO_FD_LOOKUP[fd] else fd
local statFd = fs.readFile("/proc/self/stat")
local pid = assert(string.match(statFd, "^%S+%s+%S+%s+%S+%s+(%S+)"), "Could not get current process PID")
local stdoutFdMode = ResultExt.ok(
Result.try(process.spawn, "stat", { "-L", "-c", "%f", `/proc/{pid}/fd/{inputFd}` })
)
:andThen(function(child: process.SpawnResult)
if not child.ok then
return Option.None
end
return Option.from(tonumber(child.stdout, 16))
end)
return stdoutFdMode:isSomeAnd(sys.isCharacterDevice)
end
return sys