Refactor themes to avoid imports

Enhancement #9
This commit is contained in:
Johann Dreo 2013-03-24 23:54:02 +01:00
commit 5b52c7eceb
5 changed files with 39 additions and 37 deletions

View file

@ -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

View file

@ -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

View file

@ -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" ],
]

View file

@ -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" ]
]

View file

@ -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] ]