module Doing::StringHighlight

Tag and search highlighting

Public Instance Methods

highlight_search!(search, distance: nil, negate: false, case_type: nil) click to toggle source
# File lib/doing/string/highlight.rb, line 27
def highlight_search!(search, distance: nil, negate: false, case_type: nil)
  replace highlight_search(search, distance: distance, negate: negate, case_type: case_type)
end
highlight_tags(color = 'yellow', last_color: nil) click to toggle source

Colorize @tags with ANSI escapes

@param color [String] color (see Color)

@return [String] string with @tags highlighted

# File lib/doing/string/highlight.rb, line 18
def highlight_tags(color = 'yellow', last_color: nil)
  unless last_color
    color = color.split(' ') unless color.is_a?(Array)
    tag_color = color.each_with_object([]) { |c, arr| arr << Doing::Color.send(c) }.join('')
    last_color = last_color_code
  end
  gsub(/(\s|m)(@[^ ("']+)/, "\\1#{tag_color}\\2#{last_color}")
end
highlight_tags!(color = 'yellow', last_color: nil) click to toggle source

@param (see highlight_tags)

# File lib/doing/string/highlight.rb, line 7
def highlight_tags!(color = 'yellow', last_color: nil)
  replace highlight_tags(color)
end
last_color() click to toggle source

Returns the last escape sequence from a string.

Actually returns all escape codes, with the assumption that the result of inserting them will generate the same color as was set at the end of the string. Because you can send modifiers like dark and bold separate from color codes, only using the last code may not render the same style.

@return [String] All escape codes in string

# File lib/doing/string/highlight.rb, line 73
def last_color
  scan(/\e\[[\d;]+m/).join('')
end
uncolor() click to toggle source

Remove color escape codes

@return clean string

# File lib/doing/string/highlight.rb, line 82
def uncolor
  gsub(/\e\[[\d;]+m/, '')
end
uncolor!() click to toggle source

@see uncolor

# File lib/doing/string/highlight.rb, line 89
def uncolor!
  replace uncolor
end