class Rouge::Formatters::Terminal256

A formatter for 256-color terminals

Attributes

theme[R]

@private

Public Class Methods

new(theme = Themes::ThankfulEyes.new) click to toggle source

@param [Hash,Rouge::Theme] theme

the theme to render with.
# File lib/rouge/formatters/terminal256.rb, line 14
def initialize(theme = Themes::ThankfulEyes.new)
  if theme.is_a?(Rouge::Theme)
    @theme = theme
  elsif theme.is_a?(Hash)
    @theme = theme[:theme] || Themes::ThankfulEyes.new
  else
    raise ArgumentError, "invalid theme: #{theme.inspect}"
  end
end

Public Instance Methods

escape_sequence(token) click to toggle source

private

# File lib/rouge/formatters/terminal256.rb, line 160
def escape_sequence(token)
  @escape_sequences ||= {}
  @escape_sequences[token.qualname] ||=
    EscapeSequence.new(get_style(token))
end
get_style(token) click to toggle source
# File lib/rouge/formatters/terminal256.rb, line 166
def get_style(token)
  return text_style if token.ancestors.include? Token::Tokens::Text

  theme.get_own_style(token) || text_style
end
stream(tokens) { |style_string| ... } click to toggle source
# File lib/rouge/formatters/terminal256.rb, line 24
def stream(tokens, &b)
  tokens.each do |tok, val|
    escape = escape_sequence(tok)
    yield escape.style_string
    yield val.gsub("\n", "#{escape.reset_string}\n#{escape.style_string}")
    yield escape.reset_string
  end
end
text_style() click to toggle source
# File lib/rouge/formatters/terminal256.rb, line 172
def text_style
  style = theme.get_style(Token['Text'])
  # don't highlight text backgrounds
  style.delete :bg
  style
end