Advertisement
Guest User

m

a guest
Jan 28th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. monitor = peripheral.wrap("top")
  2.  
  3. function xwrite(text,x,y)
  4.   monitor.setCursorPos(x,y)
  5.   monitor.write(text)
  6. end
  7.  
  8. function writefit(text,xStart,yStart,xEnd)
  9.   local rowLength = xEnd-xStart
  10.   local restString = text
  11.         if text == nil then restString ="" end
  12.   local yline = 0  
  13.   local spacePos = 0
  14.   local printString = ""
  15.   local teststring = ""
  16.   while string.len(restString) > rowLength do
  17.      spacePos = rowLength
  18.      teststring = string.sub(restString,1,rowLength)
  19.      while string.find(teststring," ",spacePos) == nil and spacePos > 1 do
  20.        spacePos = spacePos-1
  21.      end
  22.      if spacePos == 1 then spacePos = rowLength end
  23.      printString = string.sub(restString,1,spacePos)
  24.      xwrite(printString,xStart,yStart+yline)
  25.      restString = string.sub(restString,spacePos+1)
  26.      yline = yline+1
  27.   end
  28.   xwrite(restString,xStart,yStart+yline)
  29.  
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement