Advertisement
LDDestroier

Monc Beta

Apr 26th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. tArg = {...}
  2.  
  3. textscale = 0.5
  4.  
  5. function displayHelp()
  6.     print("monc <monitor>")
  7.     print("monc <monitor> <program>")
  8.     print("monc <monitor> -s <textscale>")
  9.     print("monc <monitor> -s <textscale> <program>")
  10. end
  11.  
  12. function setMonFuncs()
  13.     if not monIsInUse then
  14.         oldRedirect = term.redirect
  15.         term.redirect = function( object )
  16.             oldRedirect(object)
  17.             oldRedirect(term.native())
  18.         end
  19.        
  20.         monIsInUse = true
  21.     end
  22. end
  23.  
  24. function setRegFuncs()
  25.     if monIsInUse == true then
  26.         term.redirect = oldRedirect
  27.         monIsInUse = false
  28.     end
  29. end
  30.  
  31. if tArg[1] ~= nil then
  32.  
  33.     Allsides = peripheral.getNames()
  34.  
  35.     mon = nil
  36.     monitorName = tArg[1]
  37.     if monitorName == "exit" then
  38.         setRegFuncs()
  39.         return
  40.     end
  41.     if peripheral.getType(monitorName) == "monitor" then
  42.         mon = peripheral.wrap(monitorName)
  43.         mon.setCursorPos(term.getCursorPos())
  44.     else
  45.         error("no such monitor as " .. monitorName)
  46.     end
  47.  
  48.     if tArg[2] == "-s" then
  49.         if type(tonumber(tArg[3])) == "number" then
  50.             if tonumber(tArg[3]) >= 0.5 and tonumber(tArg[3]) <= 5 then
  51.                 progpos = 4
  52.                 argpos = 5
  53.                 mon.setTextScale(tonumber(tArg[3]))
  54.             else
  55.                 error("invalid text scale, use 0.5-5")
  56.             end
  57.             if tArg[4] == nil then
  58.                 setMonFuncs()
  59.                 return
  60.             end
  61.         else
  62.             progpos = 2
  63.             argpos = 3
  64.             mon.setTextScale(textscale)
  65.         end
  66.     else
  67.         progpos = 2
  68.         argpos = 3
  69.         mon.setTextScale(textscale)
  70.     end
  71.    
  72.     if tArg[progpos] ~= nil then
  73.         program = tArg[progpos]
  74.         if tArg[progpos] == "exit" then
  75.             setRegFuncs()
  76.             return
  77.         else
  78.             if tArg[argpos] ~= nil then
  79.                 arguments = ""
  80.                 for a = argpos, #tArg do
  81.                     arguments = arguments .. " " .. tArg[a]
  82.                 end
  83.             end
  84.         end
  85.        
  86.         if arguments ~= nil and arguments ~= "" then
  87.             setMonFuncs()
  88.             shell.run(program .. " " .. arguments)
  89.             setRegFuncs()
  90.         else
  91.             setMonFuncs()
  92.             shell.run(program)
  93.             setRegFuncs()
  94.         end
  95.     else
  96.         setMonFuncs()
  97.     end
  98. else
  99.     error("no monitor given")
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement