Class: Eskimo::Components::HighlightColumn

Inherits:
Eskimo::Component show all
Defined in:
lib/eskimo/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



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

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



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

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