A formatter for 256-color terminals
@private
@option opts :theme
(default is thankful_eyes) the theme to render with.
# File lib/rouge/formatters/terminal256.rb, line 14 def initialize(opts={}) @theme = opts[:theme] || 'thankful_eyes' @theme = Theme.find(@theme) if @theme.is_a? String end
private
# File lib/rouge/formatters/terminal256.rb, line 155 def escape_sequence(token) @escape_sequences ||= {} @escape_sequences[token.qualname] ||= EscapeSequence.new(get_style(token)) end
# File lib/rouge/formatters/terminal256.rb, line 161 def get_style(token) return text_style if token.ancestors.include? Token::Tokens::Text theme.get_own_style(token) || text_style end
# File lib/rouge/formatters/terminal256.rb, line 19 def stream(tokens, &b) tokens.each do |tok, val| escape = escape_sequence(tok) yield escape.style_string yield val.gsub("\n", "\n#{escape.style_string}") yield escape.reset_string end end
# File lib/rouge/formatters/terminal256.rb, line 167 def text_style style = theme.get_style(Token['Text']) # don't highlight text backgrounds style.delete :bg style end