Class: Rouge::Formatters::Terminal256::EscapeSequence
- Inherits:
-
Object
- Object
- Rouge::Formatters::Terminal256::EscapeSequence
- Defined in:
- lib/rouge/formatters/terminal256.rb
Instance Attribute Summary collapse
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Class Method Summary collapse
Instance Method Summary collapse
- #bg ⇒ Object
- #fg ⇒ Object
-
#initialize(style) ⇒ EscapeSequence
constructor
A new instance of EscapeSequence.
- #reset_string ⇒ Object
- #style_string ⇒ Object
Constructor Details
#initialize(style) ⇒ EscapeSequence
Returns a new instance of EscapeSequence.
31 32 33 |
# File 'lib/rouge/formatters/terminal256.rb', line 31 def initialize(style) @style = style end |
Instance Attribute Details
#style ⇒ Object (readonly)
Returns the value of attribute style.
30 31 32 |
# File 'lib/rouge/formatters/terminal256.rb', line 30 def style @style end |
Class Method Details
.xterm_colors ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rouge/formatters/terminal256.rb', line 35 def self.xterm_colors @xterm_colors ||= [].tap do |out| # colors 0..15: 16 basic colors out << [0x00, 0x00, 0x00] # 0 out << [0xcd, 0x00, 0x00] # 1 out << [0x00, 0xcd, 0x00] # 2 out << [0xcd, 0xcd, 0x00] # 3 out << [0x00, 0x00, 0xee] # 4 out << [0xcd, 0x00, 0xcd] # 5 out << [0x00, 0xcd, 0xcd] # 6 out << [0xe5, 0xe5, 0xe5] # 7 out << [0x7f, 0x7f, 0x7f] # 8 out << [0xff, 0x00, 0x00] # 9 out << [0x00, 0xff, 0x00] # 10 out << [0xff, 0xff, 0x00] # 11 out << [0x5c, 0x5c, 0xff] # 12 out << [0xff, 0x00, 0xff] # 13 out << [0x00, 0xff, 0xff] # 14 out << [0xff, 0xff, 0xff] # 15 # colors 16..232: the 6x6x6 color cube valuerange = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff] 217.times do |i| r = valuerange[(i / 36) % 6] g = valuerange[(i / 6) % 6] b = valuerange[i % 6] out << [r, g, b] end # colors 233..253: grayscale 1.upto 22 do |i| v = 8 + i * 10 out << [v, v, v] end end end |
Instance Method Details
#bg ⇒ Object
78 79 80 81 |
# File 'lib/rouge/formatters/terminal256.rb', line 78 def bg return @bg if instance_variable_defined? :@bg @bg = style.bg && self.class.color_index(style.bg) end |
#fg ⇒ Object
73 74 75 76 |
# File 'lib/rouge/formatters/terminal256.rb', line 73 def fg return @fg if instance_variable_defined? :@fg @fg = style.fg && self.class.color_index(style.fg) end |
#reset_string ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rouge/formatters/terminal256.rb', line 95 def reset_string @reset_string ||= begin attrs = [] attrs << '39' if fg # fg reset attrs << '49' if bg # bg reset attrs << '00' if style[:bold] || style[:italic] escape(attrs) end end |
#style_string ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rouge/formatters/terminal256.rb', line 83 def style_string @style_string ||= begin attrs = [] attrs << ['38', '5', fg.to_s] if fg attrs << ['48', '5', bg.to_s] if bg attrs << '01' if style[:bold] attrs << '04' if style[:italic] # underline, but hey, whatevs escape(attrs) end end |