Last active
December 1, 2015 23:19
-
-
Save Zero9o1o/420d5a357f349072c6fd to your computer and use it in GitHub Desktop.
monitor program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local arg = {...} | |
local Monitor = peripheral.wrap(arg[1]) | |
local textScale = tonumber(arg[2]) or 1 | |
local cursorX, cursorY = 1, 1 | |
local function monitorWriteLine( ... ) -- writes a line and moves cursor down one | |
local text = arg[1] | |
local lineInd = arg[2] or 0 | |
local lineInc = arg[3] or 1 | |
local cursorCurrentX, cursorCurrentY = Monitor.getCursorPos() | |
cursorNewPosX = tonumber(cursorX) + tonumber(lineInd) | |
cursorNewPosY = tonumber(cursorCurrentY) + tonumber(lineInc) | |
Monitor.write(text) | |
Monitor.setCursorPos(cursorNewPosX, cursorNewPosY) | |
return true | |
end | |
local function monitorClear( ... ) -- Clears the monitor and resets the cursor position | |
Monitor.clear() | |
Monitor.setCursorPos(cursorX, cursorY) | |
return true | |
end | |
local function fileSave( ... ) -- saves data to a file | |
local fileName = arg[1] | |
local data = arg[2] | |
local file = fs.open(fileName, "w") | |
file.write(tostring(data)) | |
file.close() | |
return true | |
end | |
local function fileLoad( ... ) -- reads data from a file | |
local fileName = arg[1] | |
local file = fs.open(fileName, "r") | |
local data = file.readAll() | |
file.close() | |
return data | |
end | |
local function buttonLoad( ... ) -- loads buttons from file | |
end | |
local function buttonSave( ... ) -- saves all buttons to file | |
end | |
local function buttonAdd( ... ) -- adds a button | |
local buttonPosX = arg[1] | |
local buttonPosY = arg[2] | |
local buttonWidth = arg[3] or 0 | |
local buttonHeight = arg[4] or 0 | |
local buttonText = arg[5] or " " | |
local buttonColorPrimary = colors.green | |
local buttonColorSecondary = colors.red | |
local funkyMathA = buttonHeight - 1 | |
local funkyMathB = buttonWidth - 1 | |
if funkyMathA < 0 then | |
funkyMathA = 0 | |
end | |
if funkyMathB < 0 then | |
funkyMathB = 0 | |
end | |
-- Monitor.setCursorPos(buttonPosX, buttonPosY) | |
if Monitor.isColor() then -- for advance screens | |
Monitor.setBackgroundColor(buttonColorPrimary) | |
for a = 0, funkyMathA do | |
local funkyMathC = buttonPosY + a | |
Monitor.setCursorPos(buttonPosX, funkyMathC) | |
for c = 0, funkyMathB do | |
Monitor.write(" ") | |
end | |
end | |
Monitor.setBackgroundColor(colors.black) | |
else -- for non advance screens | |
print("Wat trying to make buttons") | |
print("on a black and white screen?") | |
print("How does one even?") | |
end | |
return true | |
end | |
if textScale < 0.5 then | |
if textScale > 5 then | |
Monitor.setTextScale(textScale) | |
else | |
print("Improper text scale") | |
print(textScale) | |
end | |
else | |
print("Improper text scale") | |
print(textScale) | |
end | |
monitorClear() | |
while true do | |
local event, par1, par2, par3 = os.pullEvent() | |
--[[if event == "monitor_touch" then | |
monitorClear() | |
monitorWriteLine("Event: " .. event) | |
monitorWriteLine("Side: " .. par1) | |
monitorWriteLine("X coord: " .. par2) | |
monitorWriteLine("Y coord: " .. par3) | |
else--]]if event == "key" then | |
if par1 == keys.q then | |
print("Quiting program") | |
monitorClear() | |
return | |
elseif par1 == keys.up then | |
Monitor.scroll(-1) | |
elseif par1 == keys.down then | |
Monitor.scroll(1) | |
elseif par1 == keys.b then | |
buttonAdd(9, 9) | |
buttonAdd(10, 10, 2, 2) | |
end | |
else | |
print(event) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment