DrFair

Term API

Apr 11th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. w,h = term.getSize()
  2. col = { ["white"]=1, ["orange"]=2, ["magenta"]=4, ["lightblue"]=8, ["yellow"]=16, ["lime"]=32, ["pink"]=64, ["gray"]=128, ["lightgray"]=256, ["cyan"]=512, ["purple"]=1024, ["blue"]=2048, ["brown"]=4096, ["green"]=8192, ["red"]=16384, ["black"]=32768 }
  3.  
  4. function swrite( str, x, y, color )
  5. term.setCursorPos(x,y)
  6. term.setTextColor(col[color])
  7. term.write(str)
  8. end
  9.  
  10. function swritecenter( str, y, color )
  11. term.setCursorPos((w/2-#str/2)+1,y)
  12. term.setTextColor(col[color])
  13. term.write(str)
  14. end
  15.  
  16. function drawbox( str, x1, x2, y1, y2, strcol, color )
  17. term.setCursorPos(x1,y1)
  18. term.setBackgroundColor(col[color])
  19. term.setTextColor(col[strcol])
  20. local bw = x2-x1
  21. local bh = y2-y1
  22. local bstr = " "
  23. while #bstr < bw do
  24. bstr = bstr.." "
  25. end
  26. for i=1,bh do
  27. term.setCursorPos(x1,y1+i-1)
  28. term.write(bstr)
  29. end
  30. term.setCursorPos(x1+bw/2-#str/2,y1+bh/2)
  31. term.write(str)
  32. term.setBackgroundColor(col["black"])
  33. return { [1]=x1, [2]=x2, [3]=y1, [4]=y2 }
  34. end
  35.  
  36. function press( but, event )
  37. local e,pr1,pr2,pr3 = os.pullEvent()
  38. if e == event then
  39. if pr2 >= but[1] and pr2 < but[2] and pr3 >= but[3] and pr3 < but[4] then
  40. return true
  41. else
  42. return false
  43. end
  44. end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment