class Eskimo::ASCII::HighlightColumn
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 "
Public Class Methods
new( column:, line:, markers: ['^', 'here'], style: [:bold, :red], &children )
click to toggle source
Calls superclass method
Eskimo::ASCII::Component::new
# 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
Public Instance Methods
render(**)
click to toggle source
Calls superclass method
Eskimo::ASCII::Component#render
# 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
Protected Instance Methods
create_markers()
click to toggle source
# File lib/eskimo/ascii/components/highlight_column.rb, line 42 def create_markers() buf = '' for marker in @markers do buf << @marker_padding + @colorize[marker] + "\n" end buf end
transform_line!(line, column, &fn)
click to toggle source
# File lib/eskimo/ascii/components/highlight_column.rb, line 52 def transform_line!(line, column, &fn) line[column] = fn[line[column]] line << "\n" unless line.end_with?("\n") line << create_markers line end