ChaddJackson12

Printer UPDATED

Jan 1st, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. --[[ Config ]]--
  2. -- Colors --
  3. topBar = colors.blue
  4. middleBar = colors.lightBlue
  5. bottomBar = colors.white
  6. textHeader = colors.white
  7. textBody = colors.black
  8.  
  9.  
  10. --[[ Functions ]]--
  11. -- GUI --
  12. function drawGUI()
  13.   x, y = term.getCursorPos()
  14.   term.setCursorPos(1, 1)
  15.   term.setBackgroundColor(topBar)
  16.   local w, h = term.getSize()
  17.   print(string.rep(" ", w))
  18.   print(string.rep(" ", w))
  19.   term.setBackgroundColor(middleBar)
  20.   print(string.rep(" ", w))
  21.   x2, y2 = term.getCursorPos()
  22.   i2 = h - y2
  23.   term.setBackgroundColor(bottomBar)
  24.   for i = 1, i2 do
  25.     print(string.rep(" ", w))
  26.   end
  27.   write(string.rep(" ", w))
  28.   term.setBackgroundColor(colors.black)
  29.   term.setCursorPos(x2, y2 + 1)
  30. end
  31.  
  32. function drawInfo()
  33.   term.setCursorPos(1, 2)
  34.   term.setBackgroundColor(topBar)
  35.   term.setTextColor(textHeader)
  36.   print("Advanced Printer")
  37.   w, h = term.getSize()
  38.   term.setBackgroundColor(middleBar)
  39.   print(string.rep("-", w))
  40.   term.setBackgroundColor(bottomBar)
  41.   term.setTextColor(textBody)
  42.   term.setCursorPos(1, 5)
  43. end
  44.  
  45. --[[ Interface ]]--
  46. -- Draw GUI & Information --
  47. drawGUI()
  48. drawInfo()
  49.  
  50. -- Receive User Input --
  51. MaxLength = 8
  52. WidthLength = 40
  53. Line = 1
  54. x, y = term.getCursorPos()
  55. Message = { }
  56. while true do
  57.   term.setCursorPos(x, y)
  58.   term.setCursorBlink(true)
  59.   w, h = term.getSize()
  60.   for k, v in pairs(Message) do
  61.     write(v .. string.rep(" ", w) .. "\n")
  62.   end
  63.   term.setCursorPos(x, y - 1)
  64.   event, key = os.pullEvent()
  65.   if event == "char" then
  66.     if #Message > MaxLength then
  67.    
  68.     else
  69.       if Message[Line] then
  70.         if #Message[Line] > WidthLength then
  71.           Line = Line + 1
  72.           table.insert( Message, "" )
  73.         else
  74.           Message[Line] = Message[Line] .. key
  75.         end
  76.       else
  77.         table.insert(Message, "")
  78.       end
  79.     end
  80.   elseif event == "key" then
  81.     if key == 28 then
  82.       table.insert( Message, "")
  83.       Line = Line + 1
  84.       --table.insert(Message, "")
  85.     elseif key == 29 then
  86.       --term.setCursorBlink(false)
  87.       break
  88.     elseif key == 14 then
  89.       if #Message[Line] > 0 then
  90.         local x, y = term.getCursorPos()
  91.         local old = Message[Line]
  92.         Message[Line] = old:sub( 1, string.len( old ) - 1 )
  93.         term.setCursorPos( x-1, y )
  94.         write(" ")
  95.         term.setCursorPos(x, y)
  96.       else
  97.        if Line ~= 1 then
  98.          Line = Line - 1
  99.          table.remove(Message, Line + 1)
  100.        end
  101.       end
  102.     end
  103.   end
  104. end
  105. term.clear()
  106. term.setCursorPos(1, 1)
  107. drawGUI()
  108. drawInfo()
  109. write("Enter Message Name: ")
  110. Message = read()
  111. write("\nThis would be your message name: \n" .. Message)
Advertisement
Add Comment
Please, Sign In to add comment