colout/index.html
Adrian Sadłocha 6f98ee301b Fix typos
Changes occurrences of 'Ouput' to 'Output'
2014-06-28 13:56:58 +02:00

200 lines
8 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Colout by nojhan</title>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="javascripts/respond.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--[if lt IE 8]>
<link rel="stylesheet" href="stylesheets/ie.css">
<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>
<body>
<div id="header">
<nav>
<li class="fork"><a href="https://github.com/nojhan/colout">View On GitHub</a></li>
<li class="downloads"><a href="https://github.com/nojhan/colout/zipball/master">ZIP</a></li>
<li class="downloads"><a href="https://github.com/nojhan/colout/tarball/master">TAR</a></li>
<li class="title">DOWNLOADS</li>
</nav>
</div><!-- end header -->
<div class="wrapper">
<section>
<div id="title">
<h1>Colout</h1>
<p>Color Up Arbitrary Command Output</p>
<hr>
<span class="credits left">Project maintained by <a href="https://github.com/nojhan">nojhan</a></span>
<span class="credits right">Hosted on GitHub Pages &mdash; Theme by <a href="http://twitter.com/#!/michigangraham">mattgraham</a></span>
</div>
<h1>colout</h1>
<h2>Introduction</h2>
<p>colout is a simple command to add colors to a text stream in your terminal.</p>
<p>The <code>colout</code> command line interface has been carefully designed to be simple. Basically, you will call it like: <code>&lt;text
stream&gt; | colout &lt;pattern to color&gt; [color [style]]</code></p>
<p>colout has the ability to use 8 colors mode, 256 colors mode, colormaps, themes and source code syntax coloring.
Patterns are regular expressions.</p>
<p>You can think of colout as an alternative to <code>grep --color</code> which will preserve the surrounding context, whith more
powerful coloring capabilites.</p>
<h2>Useful examples</h2>
<h3>Basic coloring</h3>
<p>In the most simple use, you just have to call <code>colout word</code> to highlight what you want to spot in a text stream. This is
particularly useful when examining logs.</p>
<p>Color every occurence of the word "fail" in bold red, in the boot log:</p>
<p><code>tail /var/log/boot.log | colout fail</code></p>
<p><img src="boot_log_fail_red_bold.png" alt=""></p>
<p>Using regular expressions, you can highlight anything you want in a text stream.</p>
<p>Color every <em>line</em> containing the word "fail" in bold red, in the boot log:</p>
<p><code>tail /var/log/boot.log | colout "^.*fail.*$" red bold</code></p>
<p><img src="boot_log_fail_line_red_bold.png" alt=""></p>
<p>Color in blue the user name of the <code>ps</code> output that have been greped:</p>
<p><code>ps aux | grep firefox | colout "^\w+\s" blue</code></p>
<p><img src="ps_grep_firefox_user_blue.png" alt=""></p>
<h3>Multiple colors</h3>
<p>Using groups in the regular expressions, you can highlight several matchs in different colors.</p>
<p>Highlight the different parts of the permissions of files in your home directories, that are <code>rwx</code> for user and group,
but <code>r-x</code> for others:</p>
<p><code>ls -l ~ | colout "^(d*)-*(rwx)(rwx)(r-x)" blue,red,yellow,green</code></p>
<p><img src="ll_perms_groups_4_colors.png" alt=""></p>
<h3>Color maps</h3>
<p>Using colormaps, you can change the colors for each lines</p>
<p>Predefined colormaps are particularly useful for reading logs that have long
lines that are wrapped.</p>
<p><code>tail /var/log/kern.log | colout "^.*$" rainbow</code></p>
<p><img src="kern_log_rainbow.png" alt=""></p>
<p>But you can also create your own colormap, using the <code>-c</code> switch, for example to alternate two colors:</p>
<p><code>tail /var/log/kern.log | colout -c "^.*$" blue,yellow normal </code></p>
<p><img src="kern_log_yb.png" alt=""></p>
<p>If you prefer a rainbow with more colors, just use an upper-case R. For example to color a progress bar:</p>
<p><code>echo "Progress [########################] 100%" | colout "#" Rainbow</code><p>
<p><img src="progress_Rainbow.png" alt=""></p>
<p>If you want even more colors, you can highlight each line of your log with a random one among the 256 ANSI colors:</p>
<p><code>tail /var/log/dmesg | colout "^.*$" Random</code></p>
<p><img src="dmesg_Random.png" alt=""></p>
<p>You can color numbers according to their value on a linear scale:</p>
<p><code>cmake .. &amp;&amp; make 2&gt;&amp;1 | colout --scale 0,100 "\[(.*)%\]" scale</code></p>
<p><img src="cmake_scale.png" alt=""></p>
<p>You can even fill your screen with esoteric disco characters (not <em>that</em> useful, but fun):</p>
<p><code>cat /dev/urandom | colout "." Random</code></p>
<p><img src="urandom_character.png" alt=""></p>
<h3>Palettes</h3>
<p>You can load extern palettes as colormaps. colout supports the GIMP Palette format (*.gpl, used by GIMP and inkscape,
for instance) and will translate them from their RGB values to their nearest ANSI colors (which may thus contains
fewer colors than the orginal RGB palette).</p>
<p><code>sudo apt-get update | colout -P /usr/share/gimp/2.0/palettes/ "^.*$" Firecode</code></p>
<p><img src="apt_update_palette_firecode.png" alt=""></p>
<h3>Source code</h3>
<p>You can use colout as a basic proxy to the pygments library, if you want to highlight a source code.</p>
<p>For example, let say you want to have a quick look at a source file, without being bothered by comments and empty lines:</p>
<p><code>tail colout.py | grep -v "#" | grep -v "^\s*$" | colout -s Python monokai</code></p>
<p><img src="code_grep_monokai.png" alt=""></p>
<p>But even more interesting, you can highlight the syntax of the matching parts of your text stream, which is useful
for spotting code in a log.</p>
<p>For example, color the code parts in the output of <code>g++</code> (they come inside single quotes):</p>
<p><code>make 2&gt;&amp;1 | colout "'.*'" Cpp vim</code></p>
<p><img src="make_Cpp_vim.png" alt=""></p>
<h3>Themes</h3>
<p>colout comes with a set of handy shortcuts for coloring common outputs.</p>
<p>For example, if you often build your software with <code>cmake</code> but find its coloring scheme a bit boring, you can use the
following shortcut:
<p><code>make 2&gt;&amp;1 | colout -t cmake</code></p>
<p><img src="cmake_theme_paradiseo.png" alt=""></p>
<p>You can, of course, combine several calls to colout using pipes:
<p><code>make 2&gt;&amp;1 | colout -t cmake | colout -t g++</code></p>
<p><img src="themes_cmake_g++_paradiseo.png" alt=""></p>
<h2>Tips</h2>
<p>To be able to use the syntax highlighting, you should install the <code>python-pygments</code> library.</p>
<p><code>colout -r</code> will give you the lists of available colors, colormaps, themes and supported programming languages.</p>
<p>Colormaps and source code syntax highlighting most often comes in 8 or 256 colors mode. Use a lower case first letter
for the 8 colors mode and an upper case first one for the 256 colors.</p>
<p>The 8 colors mode syntax highlighting only comes in two styles: light and dark. If you want more fancy styles, you
should use 256 colors mode, and thus upper case the first letter of the language name, or else the style is ignored.</p>
<p>You can leave simple words without quotes, but it is better to put the regexp in quotes to avoid escaping special
characters that would overwise be interpreted by your shell (like parenthesis).</p>
<p>Do not hesitate to design your own theme, they are defined as separated files, and basically are just like chaining
several calls to colout in pipes, with the possibility to use python code around.</p>
<p>Don't use nested groups or colout will duplicate the corresponding input text with each matching colors.</p>
</section>
</div>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
</body>
</html>