mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-06 07:20:30 +00:00
Add a scale subcommand to monitor.lua (#623)
This commit is contained in:
parent
8063059764
commit
e0e194099c
@ -1,6 +1,8 @@
|
||||
local function printUsage()
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <name> <program> <arguments>")
|
||||
print("Usage:")
|
||||
print(" " .. programName .. " <name> <program> <arguments>")
|
||||
print(" " .. programName .. " scale <name> <scale>")
|
||||
return
|
||||
end
|
||||
|
||||
@ -10,6 +12,23 @@ if #tArgs < 2 then
|
||||
return
|
||||
end
|
||||
|
||||
if tArgs[1] == "scale" then
|
||||
local sName = tArgs[2]
|
||||
if peripheral.getType(sName) ~= "monitor" then
|
||||
print("No monitor named " .. sName)
|
||||
return
|
||||
end
|
||||
|
||||
local nRes = tonumber(tArgs[3])
|
||||
if nRes == nil or nRes < 0.5 or nRes > 5 then
|
||||
print("Invalid scale: " .. nRes)
|
||||
return
|
||||
end
|
||||
|
||||
peripheral.call(sName, "setTextScale", nRes)
|
||||
return
|
||||
end
|
||||
|
||||
local sName = tArgs[1]
|
||||
if peripheral.getType(sName) ~= "monitor" then
|
||||
print("No monitor named " .. sName)
|
||||
|
@ -67,10 +67,25 @@ shell.setCompletionFunction("rom/programs/label.lua", completion.build(
|
||||
))
|
||||
shell.setCompletionFunction("rom/programs/list.lua", completion.build(completion.dir))
|
||||
shell.setCompletionFunction("rom/programs/mkdir.lua", completion.build({ completion.dir, many = true }))
|
||||
|
||||
local complete_monitor_extra = { "scale" }
|
||||
shell.setCompletionFunction("rom/programs/monitor.lua", completion.build(
|
||||
{ completion.peripheral, true },
|
||||
completion.program
|
||||
function(shell, text, previous)
|
||||
local choices = completion.peripheral(shell, text, previous, true)
|
||||
for _, option in pairs(completion.choice(shell, text, previous, complete_monitor_extra, true)) do
|
||||
choices[#choices + 1] = option
|
||||
end
|
||||
return choices
|
||||
end,
|
||||
function(shell, text, previous)
|
||||
if previous[2] == "scale" then
|
||||
return completion.peripheral(shell, text, previous, true)
|
||||
else
|
||||
return completion.program(shell, text, previous)
|
||||
end
|
||||
end
|
||||
))
|
||||
|
||||
shell.setCompletionFunction("rom/programs/move.lua", completion.build(
|
||||
{ completion.dirOrFile, true },
|
||||
completion.dirOrFile
|
||||
|
@ -3,6 +3,22 @@ local capture = require "test_helpers".capture_program
|
||||
describe("The monitor program", function()
|
||||
it("displays its usage when given no arguments", function()
|
||||
expect(capture(stub, "monitor"))
|
||||
:matches { ok = true, output = "Usage: monitor <name> <program> <arguments>\n", error = "" }
|
||||
:matches {
|
||||
ok = true,
|
||||
output =
|
||||
"Usage:\n" ..
|
||||
" monitor <name> <program> <arguments>\n" ..
|
||||
" monitor scale <name> <scale>\n",
|
||||
error = "",
|
||||
}
|
||||
end)
|
||||
|
||||
it("changes the text scale with the scale command", function()
|
||||
local r = 1
|
||||
stub(peripheral, "call", function(s, f, t) r = t end)
|
||||
stub(peripheral, "getType", function() return "monitor" end)
|
||||
expect(capture(stub, "monitor", "scale", "left", "0.5"))
|
||||
:matches { ok = true, output = "", error = "" }
|
||||
expect(r):equals(0.5)
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user