Package: grc
Generic ColorizerNoteInspired byhttp://kassiopeia.juls.savba.sk/~garabik/software/grc.htmlgrcallows you to colorize (even transform) shell output.WARNING - Pending Project RenameIn order to make roon on pypi for the originalgrcproject, this project
will be renamed tostrecsoon. The new name was chosen to be very different
fromgrcto show that it’s a different project. While bothdothe same,
they do it in a very different manner, and more importantly, the config format
is different.AlternativesThe originalgrcAvailable athttp://kassiopeia.juls.savba.sk/~garabik/software/grc.htmlWhile the originalgrcis a bit smarter with subprocesses, this rewrite
focuses on ease of use (including Installation,Configurationandsource-code access).Installation should also honour theLinux FHSsedorawksedandawkare extremely powerful tools, and can certainly do whatgrcdoes. They will certainly perform better on large streams. It’s their
intended use afterall.However, they both use an archaic and arcane syntax
for their scripts. Additionally, if you would like to colorize your output
with these, you need to work with ANSI escape sequences.grcaims to
simplify this by having a more readableConfigurationsyntax, and by hiding
the ANSI escape sequences.See the installation document for more information.UsageRead lines fromstdinand emit modified/colorized lines onstdoutNoteThis is the best supported mode of operation.Synopsis<some_process> | grc -c <config>Exampletail -f /var/log/apache2/access.log | grc -c apache_accessAdvantagesOnly the stream you are sending togrcis affected.No known side-effectsDisadvantagesAsgrconly sees a stream, it cannot determine what application is
emitting the stream. You have to specify the config manually.Spawn a subprocess, capture it’s outputNoteUse this if you don’t care about the downsides, and are lazy to
type.Synopsisgrc <some_procss>Examplegrc aptitude search pythonAdvantagesMuch less to typeCan auto-detect the config by using the sub-process application name.DisadvantagesSpawning a subprocess and interacting with it’s IO is non-trivial on a
TTY/PTY. To simplify the code,grcusespexpectto do the IO
magic.stdoutandstderrof the subprocess are combined into one
stream, which is then emitten on grc’sstdout.[1]The output may not use all of the available terminal width.[1]Configurationgrcsearches three locations for configuration files in order:~/.grc/conf.d/<confname>.yml/etc/grc/conf.d/<confname>.yml/usr/share/grc/conf.d/<confname>.ymlThe first matching config file wins. This means, you can override any
system-wide configs with your own concoctions.SyntaxgrcusesYAMLas config syntax. Comparing to.iniandjsonfiles
(both included in the Python stdlib), this syntax lends itself much better to
the requirements of this application.Basic structureThe config file is separated into sections (contexts). It has to have at least
therootcontext.Each context has a list of rules. These rules fire if a line contains a
given regular expresssion. The first matching rule wins.The line will then be replaced with the string contained in thereplacevalue. You can use back-refs if you used capture groups in your regular
expressions. Colours can be insterted using${t.color_name}. You should
always insert a${t.normal}after using a color, to reset to the terminal
default. The colors are provided by the packageblessings. Thetvariable is a reference to ablessingsterminal instance so you should be
able to use it as it is documented on theblessingshomepage.Rules may define, that processing shouldnotstop using thecontinue: yesflag. In that case, the same line will be matched with the following
rule as well.Additionally, rules may “push” another context onto the stack. If that’s the
case, the rule will be processed, and all following lines will be matched
against rules contained in the context named by thepushvalue.If in a non-root context, a rule may “pop” the current context from the
stack using thepop: yesaction.SeeConfig Referencefor more details.Annotated Example# the primary context. This section must exist!
root:
    - match: '^(running)(.*)'
      # demonstrating replacements /and/ colorizing
      replace: '*** ${t.green}\1${t.normal}\2'

    - match: '^(writing)(.*)'
      replace: '>>> ${t.yellow}\1${t.normal}\2'

    - match: '^(reading)(.*)'
      replace: '<<< ${t.blue}\1${t.normal}\2'

    - match: '^(Processing dependencies for)(.*)'
      replace: '${t.green}\1${t.normal}\2'
      # switch to the "dependencies" context
      push: dependencies

    - match: '^(Installing.*)'
      replace: '>>> ${t.green}\1${t.normal}'

# the "dependencies" context
dependencies:
    - match: '^(Finished processing dependencies for)(.*)'
      replace: '${t.green}\1${t.normal}\2'
      # Revert back to the "root" context
      pop: yes

    - match: '^(Searching for )(.*)$'
      replace: '\1${t.blue}\2${t.normal}'
      # switch to the "dependency" context
      push: dependency

# the "dependency" context
dependency:
    # Let's prepend all lines with a small indent and pipe.
    # To do this, we specify a "match-all" regex, replace the line, and
    # specify that we will continue with the next matching rule using
    # "continue"
    - match: '(.*)'
      replace: ' | \1'
      continue: yes

    # Note that after the above rule, all lines are prepended with
    # additional text. We need to include this in the regex!
    - match: '^ \| (Installing.*)'
      replace: ' | >>> ${t.green}\1${t.normal}'

    - match: '^ \| (Running.*)'
      replace: ' | ${t.green}\1${t.normal}'

    - match: '^ \| (Best match.*)'
      replace: ' | ${t.green}\1${t.normal}'

    - match: '^ \| (WARNING|warning)'
      replace: ' | ${t.yellow}\1${t.normal}'

    - match: '^ \| Installed(.*)'
      replace: ' | Installed\1\n'
      pop: yesConfig ReferenceMain LevelrootSpecifies the primary contextAll other keys represent a context youpushedsomewhere.ContextsA context is simply a list of rulesRulesmatchType:stringApython regular expression. If this matches somewhere in the input
line, all occurrences will be replaced with the string specified inreplace.NoteWhile YAML does not enforce you to enclose strings in quotes, I
is strongly recommend you usesinglequotes for regexps to
avoid trouble with string escapes (backslashes).replaceType:stringIfcontinueis false (the default), this string will be emitted tostdout. Otherwise, this string will be passed to the next matching
rule. Not that the following rule sees themodifiedstring!NoteWhile YAML does not enforce you to enclose strings in quotes, I
is recommend usingsinglequotes if using backreferences
(backslashes).continueType:booleanIf true, don’t write the string yet tostdout. Instead, pass it on to
the next matching rule.pushType:stringPushes a new context onto the stack. All following lines fromstdinwill be matched agains rules in the new context.NoteThis may change in a future release to give you yet more controlpopType:booleanIf this is set to true, then return to the previous context after this
rule has been processed. If in therootcontext, this is a no-op.NoteThis may change in a future release to give you yet more controlScreenshotsA python setup sessionBeforeAfterSimple aptitude searchBeforeAfterApache access_logBeforeAfterFootnotes[1](1,2)grcusespyexpectto deal with TTY pecularities. This will
however have two side-effects. First,stdoutwill be combined withstderr. And second, terminal width may not be well respected.