xXm0dzXx

mah simple light manager

Dec 16th, 2012
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. --- xXm0dzXx Default Programming API ---
  2. -- All my programs will have this :DD --
  3. ----------------------------------------
  4.  
  5. local x,y = term.getSize()
  6.  
  7. local function cPrint( txt ) --Version 2.0 of cPrint
  8. local function printC( text )
  9. x2,y2 = term.getCursorPos()
  10. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  11. write(text.. "\n")
  12. end
  13.  
  14. if type(txt) == "string" then
  15. printC( txt )
  16. elseif type(txt) == "table" then
  17. for i=1,#txt do
  18. printC( txt[i] )
  19. end
  20. end
  21. end
  22.  
  23. local function lPrint( txt )
  24. local x2, y2 = term.getCursorPos()
  25. term.setCursorPos( (x-(#txt))+1, y2 )
  26. write( text )
  27. end
  28.  
  29. local drawingBoard = {
  30. ["A"] = colors.white,
  31. ["B"] = colors.orange,
  32. ["C"] = colors.magenta,
  33. ["D"] = colors.lightBlue,
  34. ["E"] = colors.yellow,
  35. ["F"] = colors.lime,
  36. ["G"] = colors.pink,
  37. ["H"] = colors.gray,
  38. ["I"] = colors.lightGray,
  39. ["J"] = colors.cyan,
  40. ["K"] = colors.purple,
  41. ["L"] = colors.blue,
  42. ["M"] = colors.brown,
  43. ["N"] = colors.green,
  44. ["O"] = colors.red,
  45. ["P"] = colors.black,
  46. }
  47.  
  48. local function advWrite( pos1, pos2, str )
  49. for i=1,#str do
  50. local symb = drawingBoard[ string.sub( str, i, i) ]
  51. term.setCursorPos( pos1 + (i-1) , pos2 )
  52. if symb then
  53. term.setBackgroundColour( symb )
  54. write(" ")
  55. end
  56. end
  57. end
  58.  
  59. local function setBG( col, colz )
  60. term.setBackgroundColour( col )
  61. term.clear()
  62. term.setCursorPos(1,1)
  63. term.setTextColour( colz )
  64. end
  65.  
  66. local function getLines( path )
  67. local tLines = {}
  68. local file = fs.open( path, "r" )
  69. if file then
  70. line = file.readLine()
  71. while line do
  72. tLines[ #tLines+1 ] = line
  73. line = file.readLine()
  74. end
  75. file.close()
  76. end
  77.  
  78. return tLines
  79. end
  80.  
  81. -- End of API --
  82.  
  83. local selection = 1
  84.  
  85. local function newButton( name, sel )
  86. if selection == sel then
  87. cPrint( "[ " ..name.. " ]" )
  88. else
  89. cPrint( name )
  90. end
  91. end
  92.  
  93. os.startTimer( 0 )
  94. while true do
  95. term.clear()
  96. term.setCursorPos(1,1)
  97. cPrint( "xXm0dzXx Light Control" )
  98. print( string.rep( "-", x ) )
  99. print()
  100. term.setTextColour( colors.green )
  101. newButton( "Turn on lights", 1 )
  102. newButton( "Turn off lights", 2 )
  103. print()
  104. term.setTextColour( colors.red )
  105. newButton( "Exit", 3 )
  106. term.setTextColour( colors.white )
  107. term.setCursorPos( y-1 )
  108. print( string.rep( "-", x ) )
  109. lPrint( textutils.formatTime( os.time() ) )
  110.  
  111. local event, key = os.pullEvent()
  112. if event == "key" then
  113. if key == keys.up then
  114. if selection ~= 1 then
  115. selection = selection -1
  116. end
  117. elseif key == keys.down then
  118. if selection ~= 3 then
  119. selection = selection +1
  120. end
  121. elseif key == keys.enter then
  122. if selection == 1 then
  123. rs.setOutput( "back", true )
  124. elseif selection == 2 then
  125. rs.setOutput( "back", false )
  126. elseif selection == 3 then
  127. term.clear()
  128. term.setCursorPos(1,1)
  129. print( "AWESOMEOS v1.0.43.34.5.5.63.365.346.53465..35356" )
  130. error()
  131. end
  132. end
  133. end
  134.  
  135. os.startTimer( 0 )
  136. end
Advertisement
Add Comment
Please, Sign In to add comment