From ad0f2197a31be2f0947ea0e8aca9e4c6bdadd77d Mon Sep 17 00:00:00 2001 From: mcplayer3 Date: Tue, 23 Sep 2025 19:34:00 +1000 Subject: [PATCH] Add resolution command (#40) --- halyde/apps/helpdb/res.txt | 9 +++ halyde/apps/res.lua | 96 +++++++++++++++++++++++++++++++ halyde/config/generate/shell.json | 2 +- 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 halyde/apps/helpdb/res.txt create mode 100644 halyde/apps/res.lua diff --git a/halyde/apps/helpdb/res.txt b/halyde/apps/helpdb/res.txt new file mode 100644 index 0000000..cf5b667 --- /dev/null +++ b/halyde/apps/helpdb/res.txt @@ -0,0 +1,9 @@ +Usage: res [FLAGS] +Gets or sets the current resolution. + + FLAGS* Specifies extra options when executing the command. + [no flags] Displays the current and maximum resolution. + -x [number*] Displays the current and maximum resolution on the x-axis. + A new x-axis resolution can be specified as a number. + -y [number*] Displays the current and maximum resolution on the y-axis. + A new y-axis resolution can be specified as a number. \ No newline at end of file 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 diff --git a/halyde/config/generate/shell.json b/halyde/config/generate/shell.json index 3c7e373..33b0ae4 100644 --- a/halyde/config/generate/shell.json +++ b/halyde/config/generate/shell.json @@ -1 +1 @@ -{"prompt":"\u001b[92m%s > \u001b[0m","aliases":{"move":"mv","copy":"cp","ag":"argentum","rename":"mv","..":"cd ..","man":"help","del":"rm","delete":"rm","ren":"mv","remove":"rm","list":"ls","wget":"download","dir":"ls","ps":"lscor","poweroff":"shutdown","restart":"reboot"},"splashMessages":["Made by John Haly- I mean Cerulean Blue.","Welcome! Type \"help\" to get started.","Also try KOCOS!","Welcome back, Commander. We have no idea what we're doing.","99.9% bug-free. The remaining 0.1% are features.","0 days since last error.","Everything is fine. The fire is decorative.","Please don't feed the background processes.","Also has fetch!","Anything red is no man's land. Trust me.","Machine...","Abort, Retry, Fail?","What's the deal with /argentum/store?","So cutting-edge you can't hold it in your hand.","Americans are the reason you see colors on-screen. I'm talking about ANSI escape codes, not politics.","Shoutout to Ponali!"],"path":["/halyde/apps/"],"startupMessage":"\n │\n │ %s\n │ %s\n │\n ","defaultWorkingDirectory":"/home/"} +{"prompt":"\u001b[92m%s > \u001b[0m","aliases":{"move":"mv","copy":"cp","ag":"argentum","rename":"mv","..":"cd ..","man":"help","del":"rm","delete":"rm","ren":"mv","remove":"rm","list":"ls","wget":"download","dir":"ls","ps":"lscor","poweroff":"shutdown","restart":"reboot","resolution":"res"},"splashMessages":["Made by John Haly- I mean Cerulean Blue.","Welcome! Type \"help\" to get started.","Also try KOCOS!","Welcome back, Commander. We have no idea what we're doing.","99.9% bug-free. The remaining 0.1% are features.","0 days since last error.","Everything is fine. The fire is decorative.","Please don't feed the background processes.","Also has fetch!","Anything red is no man's land. Trust me.","Machine...","Abort, Retry, Fail?","What's the deal with /argentum/store?","So cutting-edge you can't hold it in your hand.","Americans are the reason you see colors on-screen. I'm talking about ANSI escape codes, not politics.","Shoutout to Ponali!"],"path":["/halyde/apps/"],"startupMessage":"\n │\n │ %s\n │ %s\n │\n ","defaultWorkingDirectory":"/home/"}