ChaddJackson12

Printer

Jan 1st, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 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("Printer V1.0!")
  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.   for k, v in pairs(Message) do
  60.     print(v)
  61.   end
  62.  
  63.   event, key = os.pullEvent()
  64.   if event == "char" then
  65.     if #Message > MaxLength then
  66.    
  67.     else
  68.       if Message[Line] then
  69.         if #Message[Line] > WidthLength then
  70.           Line = Line + 1
  71.           table.insert( Message, "" )
  72.         else
  73.           Message[Line] = Message[Line] .. key
  74.         end
  75.       else
  76.         table.insert(Message, "")
  77.       end
  78.     end
  79.   elseif event == "key" then
  80.     if key == 28 then
  81.       Line = Line + 1
  82.       table.insert(Message, "")
  83.     elseif key == 29 then
  84.       --term.setCursorBlink(false)
  85.       break
  86.     elseif key == 14 then
  87.       if #Message[Line] > 1 then
  88.         local x, y = term.getCursorPos()
  89.         local old = Message[Line]
  90.         Message[Line] = old:sub( 1, string.len( old ) - 1 )
  91.         term.setCursorPos( x-1, y )
  92.         write(" ")
  93.         term.setCursorPos(x, y)
  94.       else
  95.         table.remove(Message[Line], "")
  96.         Line = Line - 1
  97.       end
  98.     end
  99.   end
  100. end
  101. term.clear()
  102. term.setCursorPos(1, 1)
  103. drawGUI()
  104. drawInfo()
  105. write("Enter Message Name: ")
  106. Message = read()
  107. write("\nThis would be your message name: \n" .. Message)
Advertisement
Add Comment
Please, Sign In to add comment