Advertisement
Guest User

screen

a guest
Nov 25th, 2012
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1. local term=term.native
  2. local screen={}
  3. screen.__index=term
  4. setmetatable(screen,screen)
  5. local w,h=term.getSize()
  6. local blink=true
  7. local color={}
  8. color.text=colors.white
  9. color.background=colors.black
  10. color[2^0]="1"
  11. color[2^1]="2"
  12. color[2^2]="3"
  13. color[2^3]="4"
  14. color[2^4]="5"
  15. color[2^5]="6"
  16. color[2^6]="7"
  17. color[2^7]="8"
  18. color[2^8]="9"
  19. color[2^9]="10"
  20. color[2^10]="11"
  21. color[2^11]="12"
  22. color[2^12]="13"
  23. color[2^13]="14"
  24. color[2^14]="15"
  25. color[2^15]="16"
  26. local vscreen={}
  27. vscreen.tcolor={}
  28. vscreen.text={}
  29. vscreen.bcolor={}
  30.  
  31. local function dtcolor() return 1 end
  32. local function dbcolor() return 32768 end
  33. local function dtext() return " " end
  34.  
  35. for y=0,h+1 do
  36.  vscreen.tcolor[y]={}
  37.  vscreen.text[y]={}
  38.  vscreen.bcolor[y]={}
  39.  vscreen.tcolor[y].__index=dtcolor
  40.  vscreen.text[y].__index=dtext
  41.  vscreen.bcolor[y].__index=dbcolor
  42.  setmetatable(vscreen.tcolor[y],vscreen.tcolor[y])
  43.  setmetatable(vscreen.text[y],vscreen.text[y])
  44.  setmetatable(vscreen.bcolor[y],vscreen.bcolor[y])
  45. end
  46.  
  47. screen.write=function(_sText)
  48.  local x,y=term.getCursorPos()
  49.  for i=1,_sText:len() do
  50.   vscreen.text[y][x+i-1]=_sText:sub(i,i)
  51.   vscreen.tcolor[y][x+i-1]=color.text
  52.   vscreen.bcolor[y][x+i-1]=color.background
  53.  end
  54.  term.write(_sText)
  55. end
  56.  
  57. screen.setTextColor=function(_nColor)
  58.  color.text=_nColor
  59.  term.setTextColor(_nColor)
  60. end
  61.  
  62. screen.setTextColour=function(_nColor)
  63.  color.text=_nColor
  64.  term.setTextColour(_nColor)
  65. end
  66.  
  67. screen.setBackgroundColor=function(_nColor)
  68.  color.background=_nColor
  69.  term.setBackgroundColor(_nColor)
  70. end
  71.  
  72. screen.setBackgroundColour=function(_nColor)
  73.  color.background=_nColor
  74.  term.setBackgroundColour(_nColor)
  75. end
  76.  
  77. screen.clear=function()
  78.  for y=1,h do
  79.   for x=1,w do
  80.    vscreen.text[y][x]=" "
  81.    vscreen.tcolor[y][x]=colors.text
  82.    vscreen.bcolor[y][x]=color.background
  83.   end
  84.  end
  85.  term.clear()
  86. end
  87.  
  88. screen.clearLine=function()
  89.   local x,y=term.getCursorPos()
  90.   for x=1,w do
  91.    vscreen.text[y][x]=" "
  92.    vscreen.tcolor[y][x]=color.text
  93.    vscreen.bcolor[y][x]=color.background
  94.   end
  95.  term.clearLine()
  96. end
  97.  
  98. screen.setCursorBlink=function(_bBlink)
  99.  blink=_bBlink
  100.  term.setCursorBlink(_bBlink)
  101. end
  102.  
  103. screen.scroll=function(n)
  104.  if n > 0 then
  105.   for i=1,n do
  106.    for y=1,h do
  107.     for x=1,w do
  108.      vscreen.tcolor[y][x]=vscreen.tcolor[y+1][x]
  109.      vscreen.bcolor[y][x]=vscreen.bcolor[y+1][x]
  110.      vscreen.text[y][x]=vscreen.text[y+1][x]
  111.     end
  112.    end
  113.   end
  114.  else
  115.   for i=n,-1 do
  116.    for y=h,1,-1 do
  117.     for x=1,w do
  118.      vscreen.tcolor[y][x]=vscreen.tcolor[y-1][x]
  119.      vscreen.bcolor[y][x]=vscreen.bcolor[y-1][x]
  120.      vscreen.text[y][x]=vscreen.text[y-1][x]
  121.     end
  122.    end
  123.   end
  124.  end
  125.  term.scroll(n)
  126. end
  127.  
  128. function get()
  129.  return screen
  130. end
  131.  
  132. function takeScreenshot(_sPath)
  133.  local xp,yp=term.getCursorPos()
  134.  local file=fs.open(_sPath,"w")
  135.  file.write("{\\rtf1{\\fonttbl{\\f0\\fnil\\fcharset0 Courier New;}}{\\colortbl;\\red240\\green240\\blue240;\\red235\\green136\\blue68;\\red195\\green84\\blue205;\\red102\\green137\\blue211;\\red222\\green222\\blue108;\\red65\\green205\\blue52;\\red216\\green129\\blue152;\\red67\\green67\\blue67;\\red153\\green153\\blue153;\\red40\\green118\\blue151;\\red123\\green47\\blue190;\\red37\\green49\\blue146;\\red81\\green48\\blue26;\\red59\\green81\\blue26;\\red179\\green49\\blue44;\\red30\\green27\\blue27;\\red0\\green0\\blue0;}\\sa0")
  136.  local bcolor
  137.  for y=1,h do
  138.   for x=1,w do
  139.    bcolor=color[vscreen.bcolor[y][x]]
  140.    if bcolor=="16" then
  141.     bcolor="17"
  142.    end
  143.    if y==yp and x==xp and blink then
  144.     if vscreen.text[y][x]==" " then
  145.      file.write("\\cf"..color[vscreen.tcolor[y][x]].."\\highlight"..bcolor.." _")
  146.     else
  147.      file.write("\\cf"..color[vscreen.tcolor[y][x]].."\\ul\\highlight"..bcolor.." "..vscreen.text[y][x].."\\ulnone")
  148.     end
  149.    else
  150.     file.write("\\cf"..color[vscreen.tcolor[y][x]].."\\highlight"..bcolor.." "..vscreen.text[y][x])
  151.    end
  152.   end
  153.   file.write("\\highlight0\\par")
  154.  end
  155.  file.write("}")
  156.  file.close()
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement