Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Screenshare program by MKlegoman357
- local args = {...}
- local side = args[1] or "right"
- local textScale = tonumber(args[2]) or 1
- local program = {select(3, ...)}
- local name = fs.getName(shell.getRunningProgram())
- if args[1] == "?" or args[1] == "help" then
- print("Usage:")
- print(name, " [side] [text scale] [program] [arg1] [arg2] ...")
- error("", 0)
- end
- if peripheral.getType(side) ~= "monitor" then
- error("No monitor on \"" .. side .. "\" side!", 0)
- end
- local function clamp (n, min, max)
- return n > max and max or n < min and min or n
- end
- local function clear ()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- end
- program[1] = program[1] or "shell"
- local prevTerm = term.current()
- local mon = peripheral.wrap(side)
- mon.setTextScale(textScale)
- local termW, termH = term.getSize()
- local monW, monH = mon.getSize()
- local width = termW < monW and termW or monW
- local height = termH < monH and termH or monH
- local termWin = window.create(prevTerm, clamp((termW - width) / 2, 1, math.huge), clamp((termH - height) / 2, 1, math.huge), width, height, true)
- local monWin = window.create(mon, clamp((monW - width) / 2, 1, math.huge), clamp((monH - height) / 2, 1, math.huge), width, height, true)
- local redirect = {}
- for name in pairs(term.native()) do
- redirect[name] = function (...)
- termWin[name](...)
- return monWin[name](...)
- end
- end
- redirect.isColor = function ()
- return termWin.isColor() and monWin.isColor()
- end
- redirect.isColour = function ()
- return termWin.isColour() and monWin.isColour()
- end
- local pull = coroutine.yield
- local termX = (termW - width) / 2
- local termY = (termH - height) / 2
- coroutine.yield = function (...)
- while true do
- local event = {pull(...)}
- term.setCursorPos(1, 1)
- print("!", table.concat(event, "!"), "!---")
- if event[1] == "mouse_click" or event[1] == "mouse_drag" or event[1] == "mouse_scroll" then
- local x, y = event[3], event[4]
- if x >= termX and x <= termX + width - 1 and y >= termY and y <= termY + height - 1 then
- event[3] = event[3] - termX + 1
- event[4] = event[4] - termY + 1
- return unpack(event)
- end
- else
- return unpack(event)
- end
- end
- end
- term.setBackgroundColor(colors.white)
- term.clear()
- mon.setBackgroundColor(colors.white)
- mon.clear()
- term.redirect(redirect)
- clear()
- shell.run(unpack(program))
- term.redirect(prevTerm)
- coroutine.yield = pull
- clear()
- term.redirect(mon)
- clear()
- term.redirect(prevTerm)
Advertisement
Add Comment
Please, Sign In to add comment