Tag Archives: colorize

colorwrapper: Quite obviously, the author had me in mind

Boring. Dull. Uninteresting.

2014-07-17-6m47421-date-pstree 2014-07-17-6m47421-netstat

Exciting! Interesting! Readable!

2014-07-17-6m47421-colorwrapper-01 2014-07-17-6m47421-colorwrapper-02

I get razzed occasionally about my preference for color in … well, in just about anything that passes through the console. I must not be the only one, for as many colorize tools as there are.

colorwrapper — instead of screening program output for colorizable (is that a word?) strings, or requiring you to select a color scheme from a list — uses an executable preset profile to catch and colorize the results of a command. (I’m avoiding the word “wrapper” here, just for clarity.)

I don’t know how to explain that properly. But here’s a snippet from the profile that produced the colorized version of pstree, above.

#!/home/kmandla/.cw/bin/cw
path /bin:/usr/bin:/sbin:/usr/sbin:
ifnarg -G:-U
base cyan
digit green+:default
match white:default |
...
match white:default )
match white:default init

I trimmed away a little bit for the sake of space. But I think you get the idea — the profile tells colorwrapper what to pluck out, and where the colors appear.

By default, colorwrapper comes with a huge list of profiles for commonplace Unix-y commands, and if you take a little time you should be able to either edit those to your particular color scheme, or to produce some of your own. For what I’ve seen of colorwrapper, the markdown is fairly intuitive.

This is something we’ve seen before, in programs like rainbow. Compare what rainbow does with ping, to what colorwrapper does:

2014-07-17-6m47421-colorwrapper-ping

Not everything is green and cyan with colorwrapper, by the way. It depends on the tool and the profile. 😉

A few caveats, because there always are some: colorwrapper is pushing toward five years without an apparent update; I mention that out of a sense of obligation and because I know there are some folks who won’t touch a program older than a few weeks, regardless of how well it works. Whatever. ❓

That does suggest though that some profiles (I didn’t check them all) might not be current with what the tool can do. The author talks about colorizing top, for example, and as we all know, top has its own built-in color scheme system. We all know that, right? RIGHT?! 👿

Second, I am sure you noticed that there was a slight difference between the output of straight pstree and colorwrapper’s version of pstree. You might want to step through the profiles you like best, to make sure the output you prefer is what appears with colorwrapper.

Also, if you want to give colorwrapper a test run before committing, notice that the make command has an option for localinstall which will drop everything into $HOME/.cw … which makes it easier to get rid of, when you realize K.Mandla is stark raving mad. 🙄

I’ll leave the rest for you to discover. The home page for colorwrapper is particularly sparse, but the bundled documentation is quite good. Watch for headers and footers too, which throw an added color element into the equation. Have fun! 🙂

rainbow: Color filtering in a different way

I’ve seen quite a few text colorizers in the past year or so, the most recent being pygments, but even as far back as highlighter or colout.

rainbow seems to work a little differently from those.

2014-03-26-lv-r1fz6-rainbow-ping

rainbow has quite a few presets to correspond to common commands and applications. As you can see, you can tack on the command to rainbow, and the results are “converted” from dull black and white to something a bit more … rainbow-y. 😀

You can make your own configurations to match the applications you use most, and voila! Your boring old text app is now in vibrant living color.

This sounds like my kind of program. :mrgreen:

Unfortunately (there had to be an “unfortunately” coming, didn’t there?), it seems some of the best effects are intended for terminal emulators. Some effects were lost or mangled at the framebuffer, and just didn’t line up quite right.

And there seems to be a slight discrepancy between what rainbow can accept as a command, and what it reads as flags for its own interpretation. In other words, sometimes flags for the target application were being seized by rainbow, which triggered errors. I’m still working on ways around that.

And while I appreciate the length and breadth of available sample configurations, I have to wonder if it’s really necessary to have some of them.

2014-03-26-lv-r1fz6-rainbow-top

top, when injected into rainbow’s sample config, isn’t nearly as impressive as top on its own.

So it’s a bit caveat emptor: For some things, it’s sheer genius. For others, not so much.

In the mean time, I intend to work out a configuration for nethack. The world needs a colorized version of nethack. 🙄

pygments: Because everyone loves color

I have, on occasion, let slip the fact that terminal application that employ color win my favor more easily. I suppose I should keep that quiet, but it would be dishonest to do otherwise.

It might follow that applications that add color to things get an extra thumbs-up from me. Well, sometimes yes. pygments gets a thumbs-up either way.

2014-03-21-lv-r1fz6-pygments

pygments is sort of twofold: Not only does it colorize text, like you see above, but it can also set up text to appear colorized in other formats. So you can output, for example, your text file re-encoded to appear colorized in html. As an illustration, this …

pygmentize -f html coreutils.htm

changes this …

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" />

to this …

<div class="highlight"><pre><span class="cp">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span>
<span class="cp">    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>

<span class="nt">&lt;html</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span class="na">xml:lang=</span><span class="s">&quot;en&quot;</span> <span class="na">lang=</span><span class="s">&quot;en&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;head&gt;</span>
  <span class="nt">&lt;meta</span> <span class="na">name=</span><span class="s">&quot;generator&quot;</span> <span class="na">content=</span><span class="s">&quot;HTML Tidy for Linux (vers 25 March 2009), see www.w3.org&quot;</span> <span class="nt">/&gt;</span>

That might be a little dense to look at, but take my word for it. 🙄

(Of course, if that’s the direction you’re going, then perhaps the web interface is easier to copy-and-paste. 😉 )

I like pygments for doing a little more than colout or highlighter, and having the extra option to “convert” the product to a different “format.” It’s not often that I need to colorize files but I intend to employ this when the time comes. 😉

highlighter: Picking out letters, words, phrases

I’m not sure where I heard about highlighter, but I have a feeling it’s been on my list for a long time.

2013-11-23-lv-r1fz6-highlighter

highlighter is a python program that behaves like a color filter. You could compare it with grep in some ways, but grep plucks out lines that match; highlighter just tweaks the color.

highlighter stays out of the way; if you just execute hl on its own, not much happens. You might have to pipe text through it.

That does make it convenient for some other applications though: Send the output of a program through highlighter to add some color to the original results.

We’ve seen this before, in colout and ccze (though that’s more for colorizing logs) and perhaps some others. One shortcoming that I found with highlighter is that it didn’t seem to work in a virtual console; all I got was text of the same color. I’m not sure why. 😕

This is not in AUR or Debian that I could find; you might have to install this manually out of git or with pip. Enjoy.

colout: Colorize on a whim

Not far off from codemetre, this is colout, which you might be able to ascertain on your own.

2013-09-25-v5-122p-colout

Pipe text through colout, and you can apply color to specific strings. It’s a very clever idea, and one I like a lot.

What you see above is a good example of what colout can do — find commented sections in code and highlight them.

In the most basic terms, just cat text.txt | colout word red bold will search for “word” in the file and paint it red where it is found.

Of course, that alone is possible just with grep --color, in a way. colout just gives a little more flexibility.

If it sounds like I like colout, you’re right. I’m willing to give this one a gold smiley: 😀