diff --git a/README.md b/README.md index f13ae26..065af82 100644 --- a/README.md +++ b/README.md @@ -266,3 +266,22 @@ cmake and g++ themes: You then can use the `cm` alias as a prefix to your build command, for example: `cm make test` + +### Themes + +You can easily add your own theme to colout. +A theme is basically a module with a function named `theme` that take the configuration context as an argument and +return back the (modified) context and a list of triplets. +Each triplet figures the same arguments than those of the command line interface. + + def theme(context): + return context,[ [regexp, colors, styles] ] + +With the context dictionary at hand, you have access to the internal configuration of colout, you can thus change colormaps for +special keywords, the scale, even the available colors, styles or themes. + +See the cmake theme for how to modify an existing colormap if (and only if) the user didn't ask for an +alternative one. +See the ninja theme for how to extend an existing theme with more regexps and a different configuration. +See the gcc theme for an example of how to use the localization of existing softwares to build translated regexp. + diff --git a/colout/colout.py b/colout/colout.py index 41346c6..94b06ba 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -68,6 +68,8 @@ context["colormaps"]["Hash"] = context["colormaps"]["Rainbow"] context["colormaps"]["default"] = context["colormaps"]["spectrum"] context["colormaps"]["Default"] = context["colormaps"]["Spectrum"] +context["user_defined_colormaps"] = False + context["colormap_idx"] = 0 context["scale"] = (0,100) @@ -100,6 +102,7 @@ def set_special_colormaps( cmap ): context["colormaps"]["Default"] = cmap context["colormaps"]["random"] = cmap context["colormaps"]["Random"] = cmap + context["user_defined_colormaps"] = True logging.debug("user-defined special colormap: %s" % ",".join([str(i) for i in cmap]) ) diff --git a/colout/colout_cmake.py b/colout/colout_cmake.py index cca396f..68ff06e 100644 --- a/colout/colout_cmake.py +++ b/colout/colout_cmake.py @@ -8,9 +8,11 @@ def theme(context): # actions taking an unknown time untimed="blue" - # A palette that goes: purple, orange, white - percs = [45, 39, 33, 27, 21, 57, 63, 62, 98, 97, 133, 132, 138, 173, 172, 208, 214, 220, 226, 228, 229, 230, 231, 255] - context["colormaps"]["Scale"] = percs + # If the user do not ask for his own colormap + if not context["user_defined_colormaps"]: + # A palette that goes: purple, orange, white + percs = [45, 39, 33, 27, 21, 57, 63, 62, 98, 97, 133, 132, 138, 173, 172, 208, 214, 220, 226, 228, 229, 230, 231, 255] + context["colormaps"]["Scale"] = percs return context,[ # Configure... @@ -31,9 +33,6 @@ def theme(context): # Link (make) [ "^(Linking .* )(library|executable) (.*/)*(.+(\.[aso]+)*)$", untimed, "normal,normal,bold" ], - # Link (ninja) - [ "^\[[0-9/]+\]\s?(Linking .* )(library|executable) (.*/)*(.+(\.[aso]+)*)$", - untimed, "normal,normal,bold" ], # [percent] Built [ "^\[\s*[0-9/]+%?\]\s(Built target)(\s.*)$", performed, "normal,bold" ], @@ -47,7 +46,5 @@ def theme(context): [ "make\[[0-9]+\].*", "yellow"], [ "(make: \*\*\* \[.+\] )(.* [0-9]+)", "red", "normal,bold"], # progress percentage (make) - [ "^(\[\s*[0-9]+%\])","Scale" ], - # progress percentage (ninja) - [ "^(\[[0-9]+/[0-9]+\])","Scale" ] + [ "^(\[\s*[0-9]+%\])","Scale" ] ] diff --git a/colout/colout_ninja.py b/colout/colout_ninja.py new file mode 100644 index 0000000..1d416c9 --- /dev/null +++ b/colout/colout_ninja.py @@ -0,0 +1,19 @@ + +import colout_cmake + +def theme(context): + # Ninja theme + + # Inherit from the CMake theme + context,th = colout_cmake.theme(context) + + # Because Ninja note progress as a fraction, we do not want the scale of a percentage + context["scale"] = (0,1) + + # Link (ninja) + th.append( [ "^\[[0-9/]+\]\s?(Linking .* )(library|executable) (.*/)*(.+(\.[aso]+)*)$", + "blue", "normal,normal,bold" ] ) + # progress percentage (ninja) + th.append( [ "^(\[[0-9]+/[0-9]+\])","Scale" ] ) + + return context,th