Class: Rouge::Formatters::Terminal256

Inherits:
Rouge::Formatter show all
Defined in:
lib/rouge/formatters/terminal256.rb

Defined Under Namespace

Classes: EscapeSequence

Constant Summary

Constants inherited from Rouge::Formatter

Rouge::Formatter::REGISTRY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Rouge::Formatter

find, #render, tag

Constructor Details

#initialize(opts = {}) ⇒ Terminal256

Returns a new instance of Terminal256.



7
8
9
10
# File 'lib/rouge/formatters/terminal256.rb', line 7

def initialize(opts={})
  @theme = opts[:theme] || Themes::ThankfulEyes
  @theme = Theme.find(@theme) if @theme.is_a? String
end

Instance Attribute Details

#themeObject (readonly)

Returns the value of attribute theme.



6
7
8
# File 'lib/rouge/formatters/terminal256.rb', line 6

def theme
  @theme
end

Instance Method Details

#escape_sequence(token) ⇒ Object

private



141
142
143
144
145
146
147
148
149
# File 'lib/rouge/formatters/terminal256.rb', line 141

def escape_sequence(token)
  @escape_sequences ||= {}
  @escape_sequences[token.name] ||= begin
    esc = EscapeSequence.new(theme.get_style(token))
    # don't highlight text backgrounds
    esc.style.delete(:bg) if token.name == 'Text'
    esc
  end
end

#stream(tokens, &b) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/rouge/formatters/terminal256.rb', line 12

def stream(tokens, &b)
  tokens.each do |tok, val|
    escape = escape_sequence(tok)
    yield escape.style_string
    yield val
    yield escape.reset_string
  end
end