July 1, 2016

A Much Better xterm

A Much Better xterm

A while back, I posted about improving my default xterm from drab nothingness to … something better. Here - A Better xterm.

Though, it was an improvement over the depressing white/black, its charm wore out pretty quickly. The colors were just too dull. And the script just wasn’t generic/flexible enough for my taste. That’s why I wrote another script(s), and this time, I certainly did get aesthetically pleasing random soft pastel colors - just as I wanted in the first place.

To start with, you’ll need to have my .Xresources, and merge it in your environment using xrdb -merge .Xresources.

My .Xresources

With the config in the .Xresources you’d already have a decent looking xterm (a massive improvement over the default). The next step is to enable random aesthetically pleasing colors to set as the foreground/background, each time we call it. I wrote a perl script that generates the fg/bg arguments.

xtermc.pl : random fg/bg argument generator


use strict;
use warnings;

# parse mixing brightness or default it to 256
# 256 - nice pastel colors
# 128 = dark pastel
my $mix = shift || 256;

# generate random BG
my $r = int(rand(256));
my $g = int(rand(256));
my $b = int(rand(256));

# mix in the offset
$r = ($r+$mix) / 2;
$g = ($g+$mix) / 2;
$b = ($b+$mix) / 2;

# format the bg color string
my $bg = sprintf("#%x%x%x", $r, $g, $b);

# generate FG color based on luminosity of the BG
# V = 0.2126 R + 0.7152 G + 0.0722 B
my $lumin = (0.2126*$r + 0.7152*$g + 0.0722*$b)/256;
my $fg = ($lumin<0.5) ? '#f2f3f4' : '#131516';

# print "\n|$bg|$fg|\n";
#generate text string for xterm commands
print "-fg $fg -bg $bg";

It generates a random color and then blends it with an offset color, to make the BG. In this script the blending color is defaulted to white, but can take any gray color (R=G=B). Surely, this could be modified to afford any kind of blends (reds, violets, etc), but I have left it simple. The FG is decided based on the luminosity (brightness) of the BG, and takes a natural light/dark color. The brightness of an RGB color is obtained according to the HSV color notation (V = 0.2126 R + 0.7152 G + 0.0722 B) (credit: source1, source2).

Here’s a jsfiddle that I forked that demonstrates the above concept: JS Color Palette Gen - You can play around with the blend colors and see what palette it generates.

Finally, alias that script in your .baschrc or .cshrc to some command you can call easily, say term, just like in part-1.

alias term 'xterm `/home/a0226966/bin/xtermc.pl` &'

Blend = White(#ffffff):

Blend = White(#ffffff)

Blend = Gray(#7f7f7f):

Blend = Gray(#7f7f7f)