Advertisement
LegoStax

Text wrapping

Nov 29th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.59 KB | None | 0 0
  1. -- Text wrap w/ newline testing
  2. local w,h = term.getSize()
  3. local preprocess = "This is a thingy with derp because derpy took a crap in his toilet and forgot to flush^thanks to his mommy"
  4. local BUFFER = {}
  5. local add = ""
  6. for i = 1,preprocess:len() do
  7.     if string.sub(preprocess,i,i) == "^" then
  8.         table.insert(BUFFER,add)
  9.         add = ""
  10.     else
  11.         add = add .. string.sub(preprocess,i,i)
  12.     end
  13.     if add:len() == w or i == preprocess:len() then
  14.         table.insert(BUFFER,add)
  15.         add = ""
  16.     end
  17. end
  18. term.clear()
  19. term.setCursorPos(1,1)
  20. for i = 1,#BUFFER do
  21.     term.setCursorPos(1,i)
  22.     term.write(BUFFER[i])
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement