From f081cc88bec10ac157295538827f1a1292c4880c Mon Sep 17 00:00:00 2001 From: mcplayer3 Date: Sun, 21 Sep 2025 20:53:32 +1000 Subject: [PATCH] Add files via upload --- halyde/apps/res.lua | 96 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 halyde/apps/res.lua diff --git a/halyde/apps/res.lua b/halyde/apps/res.lua new file mode 100644 index 0000000..b1db0db --- /dev/null +++ b/halyde/apps/res.lua @@ -0,0 +1,96 @@ +local component = require("component") +local gpu = component.gpu +local shell = require("shell") + +local args = {...} + +local maxX, maxY = gpu.maxResolution() +local curX, curY = gpu.getResolution() + +local function setRes() + if not(args[1] == "-x" or args[1] == "-y") then + print("\x1b[91mUnknown argument. \x1b[39mTry running \x1b[92m\"help res\"") + return + end + + local lastarg = "" + local x, y + for i = 1, 3, 2 do + if args[i] == "-x" then + if lastarg ~= "x" then + x = tonumber(args[i + 1]) + lastarg = "x" + else + print("\x1b[91mValue \"x\" was set more than once. \x1b[39mTry running \x1b[92m\"help res\"") + return + end + elseif args[i] == "-y" then + if lastarg ~= "y" then + y = tonumber(args[i + 1]) + lastarg = "y" + else + print("\x1b[91mValue \"y\" was set more than once. \x1b[39mTry running \x1b[92m\"help res\"") + return + end + end + end + + if x then + if x > maxX then + print("\x1b[91mGPU does not support x higher than " .. maxX) + return + end + end + if y then + if y > maxY then + print("\x1b[91mGPU does not support y higher than " .. maxY) + return + end + end + + if x and not(y) then + gpu.setResolution(x, curY) + print("Successfully set X resolution from \x1b[93m" .. curX .. "\x1b[39m to \x1b[92m" .. x .. "\x1b[39m.") + return + elseif not(x) and y then + gpu.setResolution(curX, y) + print("Successfully set Y resolution from \x1b[93m" .. curY .. "\x1b[39m to \x1b[92m" .. y .. "\x1b[39m.") + return + else + gpu.setResolution(x, y) + print("Successfully set resolution from \x1b[93m" .. curX .. "x" .. curY .. "\x1b[39m to \x1b[92m" .. x .. "x" .. y .. "\x1b[39m.") + return + end +end + +local function getRes(val) + if val == "x" then + print("Current X resolution: \x1b[93m" .. curX) + print("Maximum supported X resolution: \x1b[92m" .. maxX) + elseif val == "y" then + print("Current Y resolution: \x1b[93m" .. curY) + print("Maximum supported Y resolution: \x1b[92m" .. maxY) + else + print("Current resolution: \x1b[93m" .. curX .. "x" .. curY) + print("Maximum supported resolution: \x1b[92m" .. maxX .. "x" .. maxY) + end +end + +if #args == 0 then + getRes() + return +end + +if not(#args == 1) then + setRes() + return +end + +local axis = args[1] +if axis == "-x" then + getRes("x") +elseif axis == "-y" then + getRes("y") +else + print("\x1b[91mUnknown argument. \x1b[39mTry running \x1b[92m\"help res\"") +end \ No newline at end of file