diff --git a/colout.py b/colout.py index 24cac49..a835351 100755 --- a/colout.py +++ b/colout.py @@ -256,6 +256,12 @@ def colorgen(stream, pattern, color="red", style="normal", on_groups=False): yield colorup(item, pattern, color, style, on_groups) +def colortheme(item, theme): + for args in theme: + item = colorup(item, *args) + return item + + ###################### # Command line tools # ###################### @@ -405,7 +411,8 @@ if __name__ == "__main__": break if not item: break - colored = themes[pattern].theme(item) + th = themes[pattern].theme() + colored = colortheme( item, th ) write(colored) # if pygments diff --git a/colout_cmake.py b/colout_cmake.py index 4638b79..01d74d2 100644 --- a/colout_cmake.py +++ b/colout_cmake.py @@ -1,19 +1,15 @@ - -import colout -def theme( item ): - item = colout.colorup( item, - "^(Scanning dependencies of target)(.*)$", - "magenta,blue", "normal,bold" ) - item = colout.colorup( item, - "^(Linking \w+ \w+ library)(\s.*/)(\w+.[aso]+)$", - "magenta", "normal,normal,bold" ) - item = colout.colorup( item, - "^\[\s*[0-9]+%\]\s(Built target)(\s.*)$", - "cyan,blue", "normal,bold") - item = colout.colorup( item, - "^\[\s*[0-9]+%\]\s(Building \w* object)(\s.*/)(\w+.cpp)(.o)$", - "green", "normal,normal,bold,normal") +def theme(): + th = [ + [ "^(Scanning dependencies of target)(.*)$", + "magenta,blue", "normal,bold" ], + [ "^(Linking \w+ \w+ library)(\s.*/)(\w+.[aso]+)$", + "magenta", "normal,normal,bold" ], + [ "^\[\s*[0-9]+%\]\s(Built target)(\s.*)$", + "cyan,blue", "normal,bold" ], + [ "^\[\s*[0-9]+%\]\s(Building \w* object)(\s.*/)(\w+.cpp)(.o)$", + "green", "normal,normal,bold,normal"] + ] percs={ "\s":("magenta","normal"), @@ -29,6 +25,6 @@ def theme( item ): "10":("red","bold"), } for p in percs: - item = colout.colorup( item, "^(\[)\s*("+p+"[0-9]%)(\])", "black,"+percs[p][0]+",black", percs[p][1] ) + th.append( [ "^(\[)\s*("+p+"[0-9]%)(\])", "black,"+percs[p][0]+",black", percs[p][1] ] ) - return item + return th diff --git a/colout_g++.py b/colout_g++.py index ad4daf2..048afe0 100644 --- a/colout_g++.py +++ b/colout_g++.py @@ -1,12 +1,12 @@ -import colout -def theme( item ): - item = colout.colorup( item, "error", "red", "bold" ) - item = colout.colorup( item, "warning", "magenta", "bold" ) - item = colout.colorup( item, "\[-W.*\]", "magenta", "normal" ) - item = colout.colorup( item, "note", "blue", "bold" ) - item = colout.colorup( item, ":([0-9]+):[0-9]*", "yellow", "normal" ) - item = colout.colorup( item, "^((/\w+)+)\.(h|cpp)", "white", "normal" ) - item = colout.colorup( item, "'(.*)'", "Cpp", "monokai" ) - return item +def theme(): + return [ + [ "error", "red", "bold" ], + [ "warning", "magenta", "bold" ], + [ "\[-W.*\]", "magenta", "normal" ], + [ "note", "blue", "bold" ], + [ ":([0-9]+):[0-9]*", "yellow", "normal" ], + [ "^((/\w+)+)\.(h|cpp)", "white", "normal" ], + [ "'(.*)'", "Cpp", "monokai" ], + ] diff --git a/colout_json.py b/colout_json.py index a4c8a0b..bc487b5 100644 --- a/colout_json.py +++ b/colout_json.py @@ -1,8 +1,8 @@ -import colout -def theme( item ): - item = colout.colorup( item, '[{}]' ) - item = colout.colorup( item, '[:,]', "blue" ) - item = colout.colorup( item, '".*"', "green" ) - return item +def theme(): + return [ + [ '[{}]' ], + [ '[:,]', "blue" ], + [ '".*"', "green" ] + ] diff --git a/colout_perm.py b/colout_perm.py index 37d5e77..3d2ed6a 100644 --- a/colout_perm.py +++ b/colout_perm.py @@ -1,9 +1,8 @@ -import colout -def theme( item ): +def theme(): p="([rwxs-])" reg="^([d-])"+p*9+"\s.*$" colors="blue"+",green"*3+",yellow"*3+",red"*3 styles="normal"+ ",normal,italic,bold"*3 - return colout.colorup( item, reg, colors, styles, True) + return [ [reg, colors, styles] ]