local w,h = term.getSize() sX,sY,eX,eY = 4,6,w - 4, h - 3Is there a way to do this?
Text Wrapping?
Started by H4X0RZ, Jul 23 2013 05:57 AM
2 replies to this topic
#1
Posted 23 July 2013 - 05:57 AM
I want to cut a a big line of text into some smaler lines which fits into this screen size:
#2
Posted 23 July 2013 - 06:14 AM
Requires a bit of effort, but can be done.
This basically searches through each grouping of nonspace characters and space characters (a word, basically), then adds to the current line in the loop. If the length of the line is greater than the limit given, throw the current line in our table of wrapped lines, and clear the current line.
After using this function, all you need to do is write the given lines manually to the screen.
Example:
function wrapText(text, limit)
local lines = {}
local curLine = ''
for word in text:gmatch('%S+%s*') do
curLine = curLine .. word
if #curLine + #word >= limit then
lines[#lines + 1] = curLine
curLine = ''
end
end
return lines
end
This basically searches through each grouping of nonspace characters and space characters (a word, basically), then adds to the current line in the loop. If the length of the line is greater than the limit given, throw the current line in our table of wrapped lines, and clear the current line.
After using this function, all you need to do is write the given lines manually to the screen.
Example:
local text = 'some really really really long text that needs to be wrapped severely' local wrapped = wrapText(text, 15) print(table.concat(wrapped, '\n'))
#3
Posted 23 July 2013 - 06:19 AM
Thank you very much !
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users











