class Rugments::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/rugments/formatters/terminal256.rb, line 12
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/rugments/formatters/terminal256.rb, line 154
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/rugments/formatters/terminal256.rb, line 160
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/rugments/formatters/terminal256.rb, line 17
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/rugments/formatters/terminal256.rb, line 166
def text_style
  style = theme.get_style(Token['Text'])
  # don't highlight text backgrounds
  style.delete :bg
  style
end