Saturday, October 13, 2012

Alternate line colors for terminal

For a long time, I was in search for a Vim plug-in that will highlight the odd lines in a slightly different color. I was not able to find anything that works neat. Later, I realized that the problem should be solved with the help of the terminal program, not with vim.

Most of the terminal programs (terminator, gnome terminal etc) support setting background image. All I had to do was writing a Python script to generate the background I needed. Here is the script I wrote.


import scipy as sp
import Image as im
hight = 768
width = 1366
# 17 for djvu sans mono 10, inconsolata 12
# 18 for djvu sans mono 11, monaco 10
line_width = 18
offset = 1
x = sp.zeros( (hight, width, 3), dtype=sp.uint8 )
# odd line color
[r1, g1, b1] = [230, 230, 230]
# even line color
[r2, g2, b2] = [255, 255, 255]
# color for thin line
[r0, g0, b0] = [200, 200, 200]
ind=sp.arange(hight)
indoff = sp.absolute(ind - offset)
ind1 = ind[sp.where( (indoff / line_width) % 2 == 0 )]
ind2 = ind[sp.where( (indoff / line_width) % 2 == 1 )]
ind0 = ind[sp.where( (indoff % line_width)     == 0 )]
x[ind1, :, 0] = r1
x[ind1, :, 1] = g1
x[ind1, :, 2] = b1
x[ind2, :, 0] = r2
x[ind2, :, 1] = g2
x[ind2, :, 2] = b2
x[ind0, :, 0] = r0
x[ind0, :, 1] = g0
x[ind0, :, 2] = b0
img = im.fromarray(x, "RGB")
img.save("term_wall.png")

Save it as wallgen.py and run it using python wallgen.py. It will generate an image named term_wall.png. (You can add some extra beautification with Gimp if you want)
You can set it as background for your terminal. (Disable scrolling of background, if you feel it as annoying)

one, two, three - some example images which can be directly downloaded.

This is how it is going to look like:


No comments:

Post a Comment