class BBS::FrameBuffer::Wrap
The word-wrap of FrameBuffer.wrap_ansi: it reads the text a token at a time (an escape sequence, a word or a run of blanks) and breaks the line before the word that would not fit, starting the next line with the style that was active.
Constants
- TOKEN
-
One token: a CSI sequence (first group), a word (second) or a run of whitespace (third).
Public Class Methods
Source
# File lib/bbs/frame_buffer/wrap.rb, line 15 def initialize(width) @width = width end
Wraps to lines of width visible characters.
Public Instance Methods
Source
# File lib/bbs/frame_buffer/wrap.rb, line 21 def lines(text) @lines = [] @line = +'' @visible = 0 @sgr = nil text.scan(TOKEN) { |seq, word, blank| seq ? escape(seq) : add(word || blank, blank) } @lines << @line.rstrip unless @line.empty? @lines.empty? ? [''] : @lines end
The lines of text, an Array of Strings with trailing spaces removed; [''] for no text.