Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArg = {...}
- local textscale = 0.5
- local monitorName, mon
- if not monIsInUse then monIsInUse = {} end
- if type(monIsInUse) ~= "table" then monIsInUse = {} end
- local function displayHelp()
- print("monc <monitor>")
- print("monc <monitor> <program>")
- print("monc <monitor> -s <textscale>")
- print("monc <monitor> -s <textscale> <program>")
- end
- local function setMonFuncs()
- if not monIsInUse[monitorName] then
- local msx,msy = mon.getSize()
- oldTermWrite = term.write
- term.write = function( text )
- oldTermWrite( text )
- mon.write( text )
- end
- oldCursorPos = term.setCursorPos
- term.setCursorPos = function( x, y )
- oldCursorPos( x, y )
- mon.setCursorPos( x, y )
- end
- oldClear = term.clear
- term.clear = function()
- oldClear()
- local cx,cy = mon.getCursorPos()
- for a = 1, msy do
- mon.setCursorPos(1,a)
- mon.write((" "):rep(msx))
- end
- mon.setCursorPos(cx,cy)
- --mon.clear()
- end
- oldBlink = term.setCursorBlink
- term.setCursorBlink = function( boolean )
- oldBlink( boolean )
- mon.setCursorBlink( boolean )
- end
- oldSetTextColor = term.setTextColour
- term.setTextColor = function( colour )
- oldSetTextColor( colour )
- mon.setTextColor( colour )
- end
- oldSetBackgroundColor = term.setBackgroundColour
- term.setBackgroundColor = function( bgcolu )
- oldSetBackgroundColor( bgcolu )
- mon.setBackgroundColor( bgcolu )
- end
- oldClearLine = term.clearLine
- term.clearLine = function()
- oldClearLine()
- local cx,cy = mon.getCursorPos()
- mon.setCursorPos(1,cy)
- mon.write((" "):rep(msx))
- mon.setCursorPos(cx,cy)
- end
- oldScroll = term.scroll
- term.scroll = function( scrnum )
- oldScroll(scrnum)
- mon.scroll(scrnum)
- end
- oldBlit = term.blit
- term.blit = function(text,t,b)
- oldBlit(text,t,b)
- mon.blit(text,t,b)
- end
- oldIsColor = term.isColor
- term.isColor = function()
- return oldIsColor() and mon.isColor()
- end
- term.setTextColour = term.setTextColor
- term.setBackgroundColour = term.setBackgroundColor
- monIsInUse[monitorName] = true
- end
- end
- local function setRegFuncs()
- if #monIsInUse > 0 then
- if monIsInUse[monitorName] == true then
- term.write = oldTermWrite
- term.setCursorPos = oldCursorPos
- term.clear = oldClear
- term.setCursorBlink = oldBlink
- term.setTextColor = oldSetTextColor
- term.setBackgroundColor = oldSetBackgroundColor
- term.setTextColour = oldSetTextColor
- term.setBackgroundColour = oldSetBackgroundColor
- term.blit = oldBlit
- term.isColor = oldIsColor
- monIsInUse[monitorName] = nil
- end
- end
- end
- if tArg[1] ~= nil then
- mon = nil
- monitorName = tArg[1]
- local mons = {peripheral.find("monitor")}
- if monitorName == "exit" then
- for a = 1, #mons do
- monitorName = mons[a]
- setRegFuncs()
- end
- return
- elseif monitorName == "list" then
- local allperiphs = peripheral.getNames()
- local monnames = {}
- for a = 1, #allperiphs do
- if peripheral.getType(allperiphs[a]) == "monitor" then
- table.insert(monnames,allperiphs[a])
- end
- end
- print("Monitors:")
- for a = 1, #monnames do
- print("+"..monnames[a])
- end
- return
- end
- if peripheral.getType(monitorName) == "monitor" then
- mon = peripheral.wrap(monitorName)
- mon.setCursorPos(term.getCursorPos())
- else
- error("no such monitor as " .. monitorName)
- end
- if tArg[2] == "-s" then
- if type(tonumber(tArg[3])) == "number" then
- if tonumber(tArg[3]) >= 0.5 and tonumber(tArg[3]) <= 5 then
- progpos = 4
- argpos = 5
- mon.setTextScale(tonumber(tArg[3]))
- else
- error("invalid text scale, use 0.5-5")
- end
- if tArg[4] == nil then
- setMonFuncs()
- return
- end
- else
- progpos = 2
- argpos = 3
- mon.setTextScale(textscale)
- end
- else
- progpos = 2
- argpos = 3
- mon.setTextScale(textscale)
- end
- if tArg[progpos] ~= nil then
- local program = tArg[progpos]
- local arguments
- if tArg[progpos] == "exit" then
- setRegFuncs()
- return
- else
- if tArg[argpos] ~= nil then
- arguments = ""
- for a = argpos, #tArg do
- arguments = arguments .. " " .. tArg[a]
- end
- end
- end
- if arguments ~= nil and arguments ~= "" then
- setMonFuncs()
- shell.run(program .. " " .. arguments)
- setRegFuncs()
- else
- setMonFuncs()
- shell.run(program)
- setRegFuncs()
- end
- else
- setMonFuncs()
- end
- else
- displayHelp()
- setRegFuncs()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement