def wordWrap(szText)
lines = []
szText.each_line("\n").each do |l|
if l.gsub(/\e\
szText.each_line("\n").each do |l|
if l.gsub(/\e\[[^m]*m/,"").length > 80
l = l.gsub(/(.{1,80})(\s|\Z)/, "\\1\n")
end
lines << l
end
return lines.join+"\n"
end
[/code]
This wraps on the last space before the word that crosses over the boundary (marked with a constant 80 here) as an arbitrary example. A slight problem is encountered if the ANSI code is attached to the end or in the middle of a word, a wrap may occur one whitespace prior. Not a huge thing to me, since it's still wrapping before the end of the line, but something to still be worked out in it.
Thanks for all the help!
I've got a little function that looks a bit like this:
This is all part of a set of dynamic help file functions that wraps text in the file after it's been parsed. So if a block is encountered in the help file that says {ansi.color.cyan} for example, it'd insert the escape sequence in that spot. Seeing as how the escape sequence is a number of characters long, each character is counting toward that max of 80.
Any thoughts on how I could exclude an escape sequence match?
Thank you!