class AnsiSys::Lexer
Constants
- CODE_EQUIVALENT
- PARAMETER_AND_LETTER
Control Sequence Introducer and following code
Attributes
buffer[R]
Public Class Methods
new(csis = ["\x1b["])
click to toggle source
csis is an Array of Code Sequence Introducers which can be e[, x9B, or both
# File lib/ansisys.rb, line 64 def initialize(csis = ["\x1b["]) # CSI can also be "\x9B" @code_start_re = Regexp.union(*(CODE_EQUIVALENT.keys + csis)) @buffer = '' end
Public Instance Methods
lex!()
click to toggle source
returns array of tokens while deleting the tokenized part from buffer
# File lib/ansisys.rb, line 75 def lex! r = Array.new @buffer.gsub!(/(?:\r\n|\n\r)/, "\n") while @code_start_re =~ @buffer r << [:string, $`] unless $`.empty? if CODE_EQUIVALENT.has_key?($&) CODE_EQUIVALENT[$&].each do |c| r << [:code, c] end @buffer = $' else csi = $& residual = $' if PARAMETER_AND_LETTER =~ residual r << [:code, $&] @buffer = $' else @buffer = csi + residual return r end end end r << [:string, @buffer] unless @buffer.empty? @buffer = '' return r end
push(string)
click to toggle source
add the String (clear text with some or no escape sequences) to buffer
# File lib/ansisys.rb, line 70 def push(string) @buffer += string end