From 65cc1720ac557c1bdeeccb35965c31ecfbde3f76 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sat, 19 Apr 2025 09:36:12 +0100 Subject: [PATCH] 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 --- bins/argon/pesde.lock | 12 ++++---- bins/asphalt/pesde.lock | 12 ++++---- bins/blink/pesde.lock | 12 ++++---- bins/darklua/pesde.lock | 12 ++++---- bins/luau-lsp/pesde.lock | 12 ++++---- bins/rojo/pesde.lock | 12 ++++---- bins/selene/pesde.lock | 12 ++++---- bins/stylua/pesde.lock | 12 ++++---- bins/zap/pesde.lock | 12 ++++---- toolchainlib/src/init.luau | 8 ++++- toolchainlib/src/utils/sys.luau | 52 +++++++++++++++++++++++++++++++++ 11 files changed, 113 insertions(+), 55 deletions(-) create mode 100644 toolchainlib/src/utils/sys.luau diff --git a/bins/argon/pesde.lock b/bins/argon/pesde.lock index 97455af..b07d211 100644 --- a/bins/argon/pesde.lock +++ b/bins/argon/pesde.lock @@ -50,25 +50,25 @@ resolved_ty = "standard" ref_ty = "pesde" 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" -[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" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/daimond113/pesde-index" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies] +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"] resolved_ty = "standard" [graph."jiwonz/pathfs@0.3.2 lune".dependencies] "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] ref_ty = "pesde" diff --git a/bins/asphalt/pesde.lock b/bins/asphalt/pesde.lock index cfaf005..2b6ddcd 100644 --- a/bins/asphalt/pesde.lock +++ b/bins/asphalt/pesde.lock @@ -50,25 +50,25 @@ resolved_ty = "standard" ref_ty = "pesde" 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" -[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" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/daimond113/pesde-index" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies] +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"] resolved_ty = "standard" [graph."jiwonz/pathfs@0.3.2 lune".dependencies] "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] ref_ty = "pesde" diff --git a/bins/blink/pesde.lock b/bins/blink/pesde.lock index fd1f400..8552f86 100644 --- a/bins/blink/pesde.lock +++ b/bins/blink/pesde.lock @@ -50,25 +50,25 @@ resolved_ty = "standard" ref_ty = "pesde" 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" -[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" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/daimond113/pesde-index" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies] +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"] resolved_ty = "standard" [graph."jiwonz/pathfs@0.3.2 lune".dependencies] "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] ref_ty = "pesde" diff --git a/bins/darklua/pesde.lock b/bins/darklua/pesde.lock index f63e65e..5578adf 100644 --- a/bins/darklua/pesde.lock +++ b/bins/darklua/pesde.lock @@ -50,25 +50,25 @@ resolved_ty = "standard" ref_ty = "pesde" 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" -[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" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/daimond113/pesde-index" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies] +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"] resolved_ty = "standard" [graph."jiwonz/pathfs@0.3.2 lune".dependencies] "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] ref_ty = "pesde" diff --git a/bins/luau-lsp/pesde.lock b/bins/luau-lsp/pesde.lock index 8c7d76f..66542f8 100644 --- a/bins/luau-lsp/pesde.lock +++ b/bins/luau-lsp/pesde.lock @@ -50,25 +50,25 @@ resolved_ty = "standard" ref_ty = "pesde" 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" -[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" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/daimond113/pesde-index" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies] +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"] resolved_ty = "standard" [graph."jiwonz/pathfs@0.3.2 lune".dependencies] "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] ref_ty = "pesde" diff --git a/bins/rojo/pesde.lock b/bins/rojo/pesde.lock index cbbbdb3..6a8f22f 100644 --- a/bins/rojo/pesde.lock +++ b/bins/rojo/pesde.lock @@ -50,25 +50,25 @@ resolved_ty = "standard" ref_ty = "pesde" 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" -[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" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/daimond113/pesde-index" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies] +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"] resolved_ty = "standard" [graph."jiwonz/pathfs@0.3.2 lune".dependencies] "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] ref_ty = "pesde" diff --git a/bins/selene/pesde.lock b/bins/selene/pesde.lock index decdf82..0e96a59 100644 --- a/bins/selene/pesde.lock +++ b/bins/selene/pesde.lock @@ -50,25 +50,25 @@ resolved_ty = "standard" ref_ty = "pesde" 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" -[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" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/daimond113/pesde-index" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies] +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"] resolved_ty = "standard" [graph."jiwonz/pathfs@0.3.2 lune".dependencies] "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] ref_ty = "pesde" diff --git a/bins/stylua/pesde.lock b/bins/stylua/pesde.lock index bbad32b..ff54535 100644 --- a/bins/stylua/pesde.lock +++ b/bins/stylua/pesde.lock @@ -50,25 +50,25 @@ resolved_ty = "standard" ref_ty = "pesde" 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" -[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" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/daimond113/pesde-index" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies] +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"] resolved_ty = "standard" [graph."jiwonz/pathfs@0.3.2 lune".dependencies] "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] ref_ty = "pesde" diff --git a/bins/zap/pesde.lock b/bins/zap/pesde.lock index 6cad88c..2d850ae 100644 --- a/bins/zap/pesde.lock +++ b/bins/zap/pesde.lock @@ -50,25 +50,25 @@ resolved_ty = "standard" ref_ty = "pesde" 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" -[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" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref] ref_ty = "pesde" index_url = "https://github.com/daimond113/pesde-index" -[graph."jiwonz/luau_path@0.1.1 luau".pkg_ref.dependencies] -luau_disk = [{ name = "jiwonz/luau_disk", version = "^0.1.2", index = "https://github.com/pesde-pkg/index" }, "standard"] +[graph."jiwonz/luau_path@0.1.3 luau".pkg_ref.dependencies] +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"] resolved_ty = "standard" [graph."jiwonz/pathfs@0.3.2 lune".dependencies] "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] ref_ty = "pesde" diff --git a/toolchainlib/src/init.luau b/toolchainlib/src/init.luau index 515dfc3..bbbcd6e 100644 --- a/toolchainlib/src/init.luau +++ b/toolchainlib/src/init.luau @@ -30,6 +30,7 @@ local ProgressBar = require("./utils/progress") local compression = require("./compression") local eq = require("./utils/eq") local manifest = require("./manifest") +local sys = require("./utils/sys") export type ToolId = { alias: Option, @@ -165,8 +166,13 @@ local function getGithubToken(): Option 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 -_G.interactive = nil +_G.interactive = isInteractive() or nil local barFns function installTool(tool: ToolId, installPath: pathfs.Path): number diff --git a/toolchainlib/src/utils/sys.luau b/toolchainlib/src/utils/sys.luau new file mode 100644 index 0000000..9fbc839 --- /dev/null +++ b/toolchainlib/src/utils/sys.luau @@ -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