@@ -250,7 +250,7 @@ def _tigetstr(self, cap_name):
250250 cap = self ._ctigetstr (cap_name ) or ''
251251 return re .sub (r'\$<\d+>[/*]?' , '' , cap )
252252
253- def sub (self , haystack , beg , end , needles , escape = None ):
253+ def sub (self , haystack , beg , end , needles , escape = None , ignore_case = False ):
254254 if not self .__enabled :
255255 return haystack
256256
@@ -259,7 +259,10 @@ def sub(self, haystack, beg, end, needles, escape=None):
259259
260260 render = lambda match : beg + match .group () + end
261261 for needle in needles :
262- haystack = re .sub (escape (needle ), render , haystack )
262+ pat = escape (needle )
263+ if ignore_case :
264+ pat = re .template (pat , re .I )
265+ haystack = re .sub (pat , render , haystack )
263266 return haystack
264267 def sub_norm (self , haystack , beg , needles , ** kwds ):
265268 return self .sub (haystack , beg , self .MODE ['normal' ], needles , ** kwds )
@@ -268,7 +271,7 @@ def sub_mode(self, haystack, mode, needles, **kwds):
268271 return self .sub_norm (haystack , self .MODE [mode ], needles , ** kwds )
269272
270273 def sub_bold (self , haystack , needles , ** kwds ):
271- return self .sub_mode (haystack , 'bold' , needles )
274+ return self .sub_mode (haystack , 'bold' , needles , ** kwds )
272275
273276 def sub_fg (self , haystack , color , needles , ** kwds ):
274277 return self .sub_norm (haystack , self .FG_COLOR [color ], needles , ** kwds )
@@ -341,6 +344,10 @@ def _highlight(self, highlight):
341344 hiend = self .term .MODE ['normal' ]
342345 return (hibeg , hiend )
343346
347+ def _sub_highlight (self , haystack , highlight , needles , ** kwds ):
348+ hibeg , hiend = self ._highlight (highlight )
349+ return self .term .sub (haystack , hibeg , hiend , needles , ** kwds )
350+
344351 @staticmethod
345352 def _calc_columns_spaces_helps (current , data_tups , left ):
346353 """ Spaces left on the current field will help how many pkgs? """
@@ -775,7 +782,8 @@ def format_number(self, number, SI=0, space=' '):
775782 def format_time (seconds , use_hours = 0 ):
776783 return urlgrabber .progress .format_time (seconds , use_hours )
777784
778- def matchcallback (self , po , values , matchfor = None , verbose = None ):
785+ def matchcallback (self , po , values , matchfor = None , verbose = None ,
786+ highlight = None ):
779787 """ Output search/provides type callback matches. po is the pkg object,
780788 values are the things in the po that we've matched.
781789 If matchfor is passed, all the strings in that list will be
@@ -788,7 +796,9 @@ def matchcallback(self, po, values, matchfor=None, verbose=None):
788796 msg = '%s.%s : ' % (po .name , po .arch )
789797 msg = self .fmtKeyValFill (msg , self ._enc (po .summary ))
790798 if matchfor :
791- msg = self .term .sub_bold (msg , matchfor )
799+ if highlight is None :
800+ highlight = self .conf .color_search_match
801+ msg = self ._sub_highlight (msg , highlight , matchfor ,ignore_case = True )
792802
793803 print msg
794804
@@ -822,7 +832,8 @@ def matchcallback(self, po, values, matchfor=None, verbose=None):
822832 key = _ ("Other : " )
823833
824834 if matchfor :
825- item = self .term .sub_bold (item , matchfor )
835+ item = self ._sub_highlight (item , highlight , matchfor ,
836+ ignore_case = True )
826837 if can_overflow :
827838 print self .fmtKeyValFill (key , item )
828839 else :
0 commit comments