Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- [Program] Mirror
- @version 1.0, 2015-04-12
- @author TheOddByte
- --]]
- local version = "1.0"
- local w, h = term.getSize()
- local args = { ... }
- if #args < 1 then
- error( "Usage: " .. shell.getRunningProgram() .. " <redirect/restore>", 0 )
- end
- --# Find and make sure there are any monitors attached
- local monitors = { peripheral.find("monitor") }
- if #monitors == 0 then
- error( "No monitors attached", 0 )
- end
- --# Create a backup of the term api
- native = native or {}
- if not native.term then
- native.term = {}
- for k, v in pairs( term ) do
- native.term[k] = v
- end
- native.os = {}
- for k, v in pairs( os ) do
- native.os[k] = v
- end
- end
- --# Some settings you can change
- local settings = {
- clear = true;
- monitorClick = true;
- }
- local command = args[1]:lower()
- if command == "redirect" then
- --# Scale the monitors to match the terminal
- for i = 1, #monitors do
- for scale = 1, 5, 0.5 do
- monitors[i].setTextScale( scale )
- local width, height = monitors[i].getSize()
- if width < w or height < h then
- monitors[i].setTextScale( scale - 0.5 )
- break
- end
- end
- end
- --# Redirect the term api to do the
- --# same stuff on the monitors
- for name, _ in pairs( monitors[1] ) do
- term[name] = function( ... )
- for i = 1, #monitors do
- monitors[i][name]( unpack( arg ) )
- end
- if native.term[name] then
- return native.term[name]( unpack( arg ) )
- end
- end
- end
- if settings.monitorClick then
- os.pullEvent = function( filter )
- local e = { native.os.pullEvent( filter ) }
- if e[1] == "monitor_touch" then
- e[1] = "mouse_click"
- e[2] = 1
- end
- return unpack( e )
- end
- end
- term.clear()
- term.setCursorPos( 1, 1 )
- print( "Mirror " .. version .. " - " .. #monitors .. " monitors wrapped" )
- elseif command == "restore" then
- --# Restore apis to normal
- for k, v in pairs( native.term ) do
- term[k] = v
- end
- for k, v in pairs( native.os ) do
- os[k] = v
- end
- if settings.clear then
- for i = 1, #monitors do
- monitors[i].setBackgroundColor( colors.black )
- monitors[i].setCursorPos( 1, 1 )
- monitors[i].clear()
- end
- end
- else
- printError( "Invalid command: " .. command .. "\nUsage: " .. shell.getRunningProgram() .. " <redirect/restore>" )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement