Advertisement
SkyCrafter0

(cc)advTermLibrary

Jul 18th, 2019
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. local advTerm = {}
  2. --Ultime Studios AdvTerm Library
  3. --Includes: Write(v2), Clear(v2), ClearWrite(v1)
  4.  
  5. function advTerm.ClearWrite(str)
  6.   --termClearWrite v1
  7.   terminalClear()
  8.   terminalWrite(str)
  9. end
  10.  
  11. function advTerm.write(str)
  12.   -- terminalWrite v2
  13.   currentX = 1
  14.   currentY = 1
  15.   xLimit, yLimit = term.getSize()
  16.  
  17.   -- Checking string length, checking screen if full or need new line.
  18.   local strLength = string.len(str)
  19.   currentX = currentX + strLength
  20.   if strLength <= xLimit then --Check if string is too long for the screen
  21.     term.clear()
  22.     term.setCursorPos(1,1)
  23.     term.write("TermAPI Terminal Write error 1")
  24.     term.setCursorPos(1,2)
  25.     term.write("Requested string too long to print")
  26.     error('',0)
  27.   end
  28.   if currentX + strLength > xLimit then
  29.     currentY = currentY + 1
  30.   end
  31.   if currentY > yLimit then
  32.     terminalClear()
  33.     term.setCursorPos(1,1)
  34.     currentX = 1
  35.     curentY = 1
  36.   end
  37.   -- Correcting for X axis
  38.   local charX = currentX - strLength
  39.   if charX <= 1 then
  40.     charX = 1
  41.   end
  42.   -- Setting cursorpos with corrected X and Y.
  43.   term.setCursorPos(charX, currentY)
  44.   -- Write new text
  45.   term.write(str)
  46. end
  47.  
  48. function advTerm.Clear()
  49.   -- terminalClear v2
  50.   term.clear()
  51.   term.setCursorPos(1,1)
  52.   --comment out rest of function if 'terminalWrite' not present
  53.   currentX = 1
  54.   currentY = 1
  55. end
  56.  
  57. return advTerm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement