Class: AI::Highlighter
- Inherits:
-
Object
- Object
- AI::Highlighter
- Defined in:
- lib/highlighter.rb
Overview
── Streaming syntax highlighter ─────────────────────────────────────
Constant Summary collapse
- R =
"\e[0m"- OPENERS =
{ "(" => ")", "[" => "]", "{" => "}" }.freeze
- CLOSERS =
OPENERS.invert.freeze
- PINK =
[255, 128, 170].freeze
- PURPLE =
[204, 153, 255].freeze
- SALMON =
[250, 128, 114].freeze
- BROWN =
[196, 168, 130].freeze
- BG =
[40, 42, 54].freeze
- TAG_DELIM =
"38;2;170;255;220"- TAG_NAME =
"38;2;200;240;215"- STRING =
"38;2;195;255;195"- NUM_FG =
183- SYMS =
{ ":" => 159, ";" => 159, "@" => 229, "^" => 229, "&" => 229, "*" => 229, "-" => 180, "+" => 180, "." => 180, "," => 180, "!" => 210, "~" => 217, "'" => 217 }.freeze
Instance Method Summary collapse
-
#initialize ⇒ Highlighter
constructor
A new instance of Highlighter.
- #paint(text) ⇒ Object
Constructor Details
#initialize ⇒ Highlighter
Returns a new instance of Highlighter.
20 21 22 23 24 25 26 27 |
# File 'lib/highlighter.rb', line 20 def initialize @col = 0; @at_line_start = true @mode = nil @slash = false; @star = false @in_string = false; @escape = false @brackets = []; @in_word = false @tag_state = nil; @tag_buf = +""; @tag_width = 0 end |
Instance Method Details
#paint(text) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/highlighter.rb', line 29 def paint(text) out = +"" text.each_char do |c| if c == "\n" then out << newline else out << paint_char(c); @col += 1 end end out end |