Class: Eskimo::ASCII::HighlightColumn

Inherits:
Component
  • Object
show all
Defined in:
lib/eskimo/ascii/components/highlight_column.rb

Overview

Highlight a particular character of a string with an ASCII arrow.

HighlightColumn.new(line: 0, column: 14) do
  "- include: lol://wut.yml"
end
=> "- include: lol://wut.yml"
   "              ^         "
   "              here      "

Instance Method Summary collapse

Constructor Details

#initialize(column:, line:, markers: ['^', 'here'], style: [:bold, :red], &children) ⇒ HighlightColumn

Returns a new instance of HighlightColumn.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/eskimo/ascii/components/highlight_column.rb', line 11

def initialize(
  column:,
  line:,
  markers: ['^', 'here'],
  style: [:bold, :red],
  &children
)
  pastel = Pastel.new

  @colorize = ->(str) { pastel.decorate(str, *style) }
  @column = column
  @line = line
  @marker_padding = ' ' * @column
  @markers = markers

  super
end

Instance Method Details

#renderObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/eskimo/ascii/components/highlight_column.rb', line 29

def render(**)
  lines = super.lines
  line = lines[@line]

  unless line.nil? || line[@column].nil?
    lines[@line] = transform_line!(line, @column, &@colorize)
  end

  lines.join
end