Forte40

Panel, CC terminal redirection to parts of the screen

Aug 22nd, 2013
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. -- http://pastebin.com/aibwRhj1
  2.  
  3. local mainTerm = term.current()
  4.  
  5. function setTerm(t)
  6.   mainTerm = t
  7. end
  8.  
  9. function redirect()
  10.   term.redirect(mainTerm)
  11. end
  12.  
  13. function new(x, y, w, h, textColor, backgroundColor, blink)
  14.   -- get term size for relative positioning
  15.   local width, height = term.getSize()
  16.   if type(x) == "table" then
  17.     -- named parameters passed in
  18.     local o = x
  19.     x = o.x or 1
  20.     y = o.y or 1
  21.     w = o.w or width
  22.     h = o.h or height
  23.     textColor = o.textColor or colors.white
  24.     backgroundColor = o.backgroundColor or colors.black
  25.     blink = o.blink ~= nil and o.blink or true
  26.   end
  27.   -- translate negative values to distance from end
  28.   if x < 0 then
  29.     x = width + x + 1
  30.   end
  31.   if y < 0 then
  32.     y = height + y + 1
  33.   end
  34.   if w < 0 then
  35.     w = width + w + 1
  36.   end
  37.   if h < 0 then
  38.     h = height + h + 1
  39.   end
  40.   if textColor == nil then
  41.     textColor = colors.white
  42.   end
  43.   if backgroundColor == nil then
  44.     backgroundColor = colors.black
  45.   end
  46.   if blink == nil then
  47.     blink = true
  48.   end
  49.   local win = window.create(mainTerm, x, y, w, h)
  50.   win.setTextColor(textColor)
  51.   win.setBackgroundColor(backgroundColor)
  52.   win.setCursorBlink(blink)
  53.   win.redirect = function()
  54.     term.redirect(win)
  55.   end
  56.   return win
  57. end
Advertisement
Add Comment
Please, Sign In to add comment