@@ -59,6 +59,10 @@ def g(*args, **kwargs):
5959 return g
6060 return util
6161
62+ @guard
63+ def guarded_print (* args , ** kwargs ):
64+ print (* args , ** kwargs )
65+
6266@with_modifiers (Colors .RED )
6367def error (* args , ** kwargs ):
6468 print (* args , ** kwargs )
@@ -100,15 +104,23 @@ def _split_multiple_without_removing(text, delimeters):
100104 text = temp
101105 return text
102106
103- @guard
104- def modify_words (text , words , color = '' , style = '' , replacement_rule = lambda x : x ):
107+ def modify_text (text , words , color = '' , replacement_rule = lambda x : x ):
105108 t = ""
106109 for word in _split_multiple_without_removing (text , words ):
107110 if word in words :
108- t += color + style + replacement_rule (word ) + END
111+ t += color + replacement_rule (word ) + END
109112 else :
110113 t += word
111114 return t
112115
116+ def modified_print (text , color_mapping , replacement_rule = lambda x : x ):
117+ for words , color in color_mapping .items ():
118+ text = modify_text (text , words , color , replacement_rule = replacement_rule )
119+ guarded_print (text )
120+
113121if __name__ == "__main__" :
114- print (modify_words ("Merhaba dünya haha" , ["dünya" ], Colors .RED ))
122+ guarded_print (modify_text (modify_text ("Hello world!" , ["world" ], Colors .GREEN + Styles .UNDERLINE ), ["Hello" ], Colors .BLUE + Styles .ITALIC ))
123+ modified_print ("Colors here!" , {
124+ ("lors" , "he" ): Colors .YELLOW ,
125+ ("Co" , "re!" ): Colors .RED ,
126+ })
0 commit comments