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
Direct Known Subclasses
Defined Under Namespace
Classes: EscapeSequence, Unescape
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 = Themes::ThankfulEyes.new) ⇒ Terminal256
constructor
A new instance of Terminal256.
- #make_escape_sequence(style) ⇒ Object
- #stream(tokens, &b) ⇒ Object
- #text_style ⇒ Object
Methods inherited from Rouge::Formatter
disable_escape!, enable_escape!, #escape?, escape_enabled?, #filter_escapes, find, #format, format, #render, tag, with_escape
Constructor Details
#initialize(theme = Themes::ThankfulEyes.new) ⇒ Terminal256
Returns a new instance of Terminal256.
15 16 17 18 19 20 21 22 23 |
# File 'lib/rouge/formatters/terminal256.rb', line 15 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 |
Instance Attribute Details
#theme ⇒ Object (readonly)
11 12 13 |
# File 'lib/rouge/formatters/terminal256.rb', line 11 def theme @theme end |
Instance Method Details
#escape_sequence(token) ⇒ Object
private
173 174 175 176 177 178 |
# File 'lib/rouge/formatters/terminal256.rb', line 173 def escape_sequence(token) return Unescape.new if escape?(token) @escape_sequences ||= {} @escape_sequences[token.qualname] ||= make_escape_sequence(get_style(token)) end |
#get_style(token) ⇒ Object
184 185 186 187 188 |
# File 'lib/rouge/formatters/terminal256.rb', line 184 def get_style(token) return text_style if token.ancestors.include? Token::Tokens::Text theme.get_own_style(token) || text_style end |
#make_escape_sequence(style) ⇒ Object
180 181 182 |
# File 'lib/rouge/formatters/terminal256.rb', line 180 def make_escape_sequence(style) EscapeSequence.new(style) end |
#stream(tokens, &b) ⇒ Object
25 26 27 28 29 |
# File 'lib/rouge/formatters/terminal256.rb', line 25 def stream(tokens, &b) tokens.each do |tok, val| escape_sequence(tok).stream_value(val, &b) end end |
#text_style ⇒ Object
190 191 192 193 194 195 |
# File 'lib/rouge/formatters/terminal256.rb', line 190 def text_style style = theme.get_style(Token['Text']) # don't highlight text backgrounds style.delete :bg style end |