Class: Rouge::Formatters::Terminal256
- Inherits:
-
Rouge::Formatter
- Object
- Rouge::Formatter
- Rouge::Formatters::Terminal256
- Defined in:
- lib/rouge/formatters/terminal256.rb
Overview
A formatter for 256-color terminals
Defined Under Namespace
Classes: EscapeSequence
Constant Summary
Constants inherited from Rouge::Formatter
Instance Attribute Summary collapse
- #theme ⇒ Object readonly
Instance Method Summary collapse
-
#escape_sequence(token) ⇒ Object
private.
- #get_style(token) ⇒ Object
-
#initialize(theme = nil) ⇒ Terminal256
constructor
A new instance of Terminal256.
- #stream(tokens, &b) ⇒ Object
- #text_style ⇒ Object
Methods inherited from Rouge::Formatter
find, format, #format, #render, tag
Constructor Details
#initialize(theme = nil) ⇒ Terminal256
Returns a new instance of Terminal256.
12 13 14 |
# File 'lib/rouge/formatters/terminal256.rb', line 12 def initialize(theme=nil) @theme = theme || Themes::ThankfulEyes end |
Instance Attribute Details
#theme ⇒ Object (readonly)
8 9 10 |
# File 'lib/rouge/formatters/terminal256.rb', line 8 def theme @theme end |
Instance Method Details
#escape_sequence(token) ⇒ Object
private
152 153 154 155 156 |
# File 'lib/rouge/formatters/terminal256.rb', line 152 def escape_sequence(token) @escape_sequences ||= {} @escape_sequences[token.qualname] ||= EscapeSequence.new(get_style(token)) end |
#get_style(token) ⇒ Object
158 159 160 161 162 |
# File 'lib/rouge/formatters/terminal256.rb', line 158 def get_style(token) return text_style if token.ancestors.include? Token::Tokens::Text theme.get_own_style(token) || text_style end |
#stream(tokens, &b) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/rouge/formatters/terminal256.rb', line 16 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 ⇒ Object
164 165 166 167 168 169 |
# File 'lib/rouge/formatters/terminal256.rb', line 164 def text_style style = theme.get_style(Token['Text']) # don't highlight text backgrounds style.delete :bg style end |