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(substrings) ⇒ HighlightSubstringStyler

Returns a new instance of HighlightSubstringStyler.


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

def initialize(substrings)
  @substrings = substrings
end

Instance Method Details

#style(value) ⇒ Object


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

def style(value)
  search_terms = @substrings.map { |substring| Regexp.escape(substring) }
  search_pattern = /#{search_terms.join('|')}/i

  value.gsub(search_pattern) { |match| "#{HIGHLIGHT_COLOR}#{match}#{RESET_COLOR}" }
end