class Rouge::Formatters::Terminal256
A formatter for 256-color terminals
Attributes
theme[R]
@private
Public Class Methods
new(opts={})
click to toggle source
@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
Public Instance Methods
escape_sequence(token)
click to toggle source
private
# File lib/rouge/formatters/terminal256.rb, line 155 def escape_sequence(token) @escape_sequences ||= {} @escape_sequences[token.name] ||= EscapeSequence.new(get_style(token)) end
get_style(token)
click to toggle source
# 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
stream(tokens) { |style_string| ... }
click to toggle source
# 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
text_style()
click to toggle source
# 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