Files
metasploit-gs/lib/msf/ui/console/table_print/highlight_substring_styler.rb
T
2021-10-21 11:01:25 +01:00

24 lines
606 B
Ruby

# -*- coding: binary -*-
module Msf
module Ui
module Console
module TablePrint
class HighlightSubstringStyler
HIGHLIGHT_COLOR = '%bgmag'
RESET_COLOR = '%clr'
# @param [Array<Regex|String>] terms An array of either strings or regular expressions to highlight
def initialize(terms)
@highlight_terms = /#{Regexp.union(terms.compact).source}/i
end
def style(value)
value.gsub(@highlight_terms) { |match| "#{HIGHLIGHT_COLOR}#{match}#{RESET_COLOR}" }
end
end
end
end
end
end