Advertisement
Guest User

cleanTerm

a guest
Jul 31st, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. -----------Clean Terminal API---------
  2.  
  3. --This api is used to display text
  4. --cleanly to the terminal
  5.  
  6.  
  7. ---------------Functions---------------
  8.  
  9.  
  10. --Used to print a title, call at
  11. --start
  12. --
  13. --param label: The text to display
  14. --param color: The int color
  15. function printTitle(label, color)
  16.  
  17.   --Since its the title, clear
  18.   clearTerminal()
  19.  
  20.   --Make sure we have a color--
  21.   if(color == nil) then
  22.     color = colors.yellow
  23.   end
  24.  
  25.   local withDash = "-"
  26.   local size = term.getSize()
  27.    
  28.   size = size - string.len(label)
  29.   size = size / 2
  30.  
  31.   --Add left dashes--
  32.   for i = 1, size do
  33.     withDash = withDash .. "-"
  34.   end  
  35.  
  36.   --Add label--
  37.   withDash = withDash .. label
  38.  
  39.   --Add right dashes--
  40.   for i = 1, size do
  41.     withDash = withDash .. "-"
  42.   end
  43.  
  44.   --Print the title--
  45.   printLineWithColor(withDash, color)
  46.  
  47. end
  48.  
  49. --Used to print info with title
  50. --
  51. --param label: The title
  52. --param labelColor: Title color
  53. --param info: The important info
  54. --param infoColor: The info colors
  55. --param newLine: bool to newLine at end
  56. function printInfo(label, labelColor, info, infoColor, newLine)
  57.  
  58.   --Print the title
  59.   printLineWithColor(label, labelColor)
  60.    
  61.   --Indent info
  62.   infoPrint = "  " .. info
  63.   --Print
  64.   printLineWithColor(infoPrint, infoColor)
  65.  
  66.   --New Line
  67.   if(newLine ~= nil and newLine == true) then
  68.     print("\n")
  69.   end  
  70. end
  71.  
  72. --Used to print a line with color
  73. --
  74. --param line: The string to print
  75. --param color: The int color
  76. function printLineWithColor(line, color)
  77.   term.setTextColor(color)
  78.   print(line)
  79.   term.setTextColor(colors.white)
  80. end
  81.  
  82. --Used to clear the terminal
  83. function clearTerminal()
  84.   term.clear()
  85.   term.setCursorPos(1, 1)
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement