Class: Msf::Ui::Console::TablePrint::HighlightSubstringStyler

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/ui/console/table_print/highlight_substring_styler.rb

Constant Summary collapse

HIGHLIGHT_COLOR =
'%bgmag'
RESET_COLOR =
'%clr'

Instance Method Summary collapse

Constructor Details

#initialize(terms) ⇒ HighlightSubstringStyler

Returns a new instance of HighlightSubstringStyler.

Parameters:

  • terms (Array<Regex|String>)

    An array of either strings or regular expressions to highlight



12
13
14
# File 'lib/msf/ui/console/table_print/highlight_substring_styler.rb', line 12

def initialize(terms)
  @highlight_terms = /#{Regexp.union(terms.compact).source}/i
end

Instance Method Details

#style(value) ⇒ Object



16
17
18
# File 'lib/msf/ui/console/table_print/highlight_substring_styler.rb', line 16

def style(value)
  value.gsub(@highlight_terms) { |match| "#{HIGHLIGHT_COLOR}#{match}#{RESET_COLOR}" }
end