Class: CodeRay::Scanners::Term

Inherits:
Scanner
  • Object
show all
Includes:
CodeRay::Streamable
Defined in:
lib/term.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) scan_tokens(tokens, options)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/term.rb', line 12

def scan_tokens (tokens, options)
  prev = nil

  until eos?
    line = scan(/.*?\n/)
    if line =~ /^(\$)(.*)/
      tokens << [$1, :prompt]
      tokens << [$2 + "\n", :command]
    elsif prev =~ /\\$/
      tokens << [line, :command]
    else
      tokens << [line, :output]
    end
    prev = line
  end

  return tokens
end