@ 21 Nov 09

The perfect console howto: Screen, dvtm, 256 colors, and more

Introduction

Console tools are cool. Most of them are really efficient and powerful, althought they don’t consume much ressources.
To me, one of the coolest feature, the better advantage it offers against GUIs, is that TUI or CLI tools can be used remotly from anywhere (wait, we need a network :p).
Some crazy guys would say: “heyyy, wait a minute ! You can do the same with firefox ! Or with the newly bloated kde 4.x release ! I can start my gnome-session on a ssh tunnel, thanks to X-forwarding ! VNC is (001.”

Huhu. Well, that’s “possible”. But that sucks. It works great on a private nerwork with high bandwith.

It is not designed to go through TEH INTERNET.

Thus, we have two possibilities:
– use those new shiny CLOUD fuckages
– having anything we need on our computer, or on our computers, walking around with our laptop or with an USB key…
– have anything we need on a remote computer, a “server@home”, that we can access from the internet. So all we need is networking and a ssh client.

I prefer the last choice. One great configuration on one computer, and I can recover these configuration from anywhere.

BTW, I really like TUIs. Many of them are powerful and lightweight. Typing on a keyboard is much faster than cliking on 5 or 6 buttons.

However, black and white displays can sometimes be boring and less readable than colorful GUIs.

No problem, terminals can display colors ! Here we go, we're going to configure an environnement wich supports 256 colors, to improve our console “user experience”.

Termcap and terminfo: correct terminal capabilities for the TERM envirronement variable

Termcap and terminfo files define terminals capabilities. They are used in ncurses softwares.
We need our terminal to be recognized as supporting 256 colors.
To do that, the TERM environement variable must be correctly set and a correspondant termcap/terminfo file must exist.
I spent lots of time in testing and looking for a solution. Next is mine.
You may find another way. It may work out of the box on your OS.

I experienced problems and i've found a solution. It works great enought to make me satisfied and willing share this solution with you :)

Solution

Hopefully, I suceeded to get 256 colors support within screen, dvtm, vim… On remote hosts that run FreeBSD, NetBSD or Debian.

Here we go:

Debian GNU/Linux

Install the ncurses-term package.
Xterm supports 256 colors out of the box. I dunno for others. VTE-based terminal emulators don’t support 256 colors on my Debian box. Maybe a more recent version of the VTE library support it, I dunno.

NetBSD and FreeBSD

I've created (hmm, i've copied and modified some examples I found on teh internet :p) my own termcap/terminfo files.

Creation of a “custom” termcap description file: .termcap

     rxvt|rxvt terminal emulator (X Window System):\
     :am:eo:km:mi:ms:ut:xn:xo:cc:\
     :co#80:it#8:li#24:Co#256:pa#32767:\
     :DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
     :AB=\E[48;5;%dm:AF=\E[38;5;%dm:\
     :K1=\EOw:K2=\EOu:K3=\EOy:K4=\EOq:K5=\EOs:LE=\E[%dD:\
     :RI=\E[%dC:UP=\E[%dA:ae=\E(B:al=\E[L:as=\E(0:bl=^G:cd=\E[J:\
     :al=\E[L:bl=^G:cd=\E[J:\
     :ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:cr=^M:\
     :cs=\E[%i%d;%dr:ct=\E[3g:dc=\E[P:dl=\E[M:do=^J:\
     :ho=\E[H:i1=\E[?47l\E=\E[?1l:ic=\E[@:\
     :is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l\E[4l:\
     :k0=\E[21~:k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~:\
     :k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:\
     :kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:kb=^H:kd=\E[B:ke=\E>:\
     :kl=\E[D:kr=\E[C:ks=\E=:ku=\E[A:le=^H:mb=\E[5m:\
     :md=\E[1m:me=\E[m:mr=\E[7m:nd=\E[C:op=\E[m:rc=\E8:sc=\E7:\
     :se=\E[27m:sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:\
     :te=\E[?47l\E8:ti=\E7\E[?47h:ue=\E[24m:up=\E[A:us=\E[4m:\
     :vb=\E[?5h\E[?5l:ve=\E[?25h:vi=\E[?25l:vs=\E[?25h:\
     :@7=\E[8~:kh=\E[7~:
 

It defines capabilities of the rxvt terminal. I don’t really know what everything mean. The important thing is that colors is set to 256: Co#256
Then, the file must be compiled by the ncurses tool tic to create the terminfo file.

 $ tic .termcap
 

tic is not part of FreeBSD’s base. You need to install ncurses from ports.

A new file is created: .terminfo/r/rxvt . .terminfo is our custom termcap database.

On FreeBSD, all termcap specifications are stored in a single file, .termcap.db

Let’s use it:

 $ vi .zshrc # or whatever-shellrc
 export TERMINFO=.terminfo  # or .termcap.db
 export TERM=rxvt
 

Now, your term must be recognized as being rxvt and supporting 256colors.

 $ tput colors
 256
 $ tput Co
 256
 

Screen

You already know screen. If you don’t, RTFM, noob.
To support 256 colors, the TERM environement variable must be set to a terminal that correctly support that capability.

Debian GNU/Linux

Create or modify your ~/.screenrc file.
Add:

 term screen-256color
 

Screen is now able to support 256 colors.

NetBSD and FreeBSD

Build screen with 256 colors support. On FreeBSD, make config would prompt for options.
On NetBSD, it seems that there’s no 256 colors option.

For now, the Makefile has be to modified:

Add:

 CONFIGURE_ARGS+=        --enable-colors256
 

in the Makefile (/usr/pkgsrc/misc/screen/Makefile).

Then, create or modify your ~/.screenrc file.
Add:

 termcapinfo rxvt 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
 

With the term directive only, screen seems to don’t recognized well the terminal capabilities on NetBSD/FreeBSD. The termcapinfo directive specifies directly some capabilities, as for example, the maximum number of colors.

Screen is now able to support 256 colors.

dvtm

dvtm brings the concept of tiling window management to the console. Learn more about it.
256 colors support has been commited in the development branch some days ago (mid september, 08).
Until a next stable release, build a development snapshot:

 git clone git://repo.or.cz/dvtm.git  
 cd dvtm && make unicode  
 

I don’t like dvtm’s mouse support, that obliges to use a special key + mouse binding to select text in the terminal (shift-mouse-drag).
That’s why i've disabled mouse support.
(config.mk, delete this line: )

     CFLAGS += -DCONFIG_MOUSE 
 

vim, elinks…

VIM, the best editor ever :) !

It supports 256 color schemes. I really like the wombat theme.
It is originally a GUI theme (designed for gvim).

Someone has turned it into a vim theme (designed for the console) as well, but I don’t remember where I found it.
I host the vim file here

Elinks is a great browser. It supports (however, it remains quite basic) CSS, 256 colors and javascript.
Select Color option “3” in the setup/terminal menu of elinks ;)

I don’t use it every time, but it can be cool to browse the web when you don’t have X or that you only need some documentation under the eyes :)

Other cool softwares

Here are some softwares that I use in console (and that are often kept open in a screen+dvtm session):

  • Mutt: powerful mail client (MUA)
  • irssi: IRC/jabber/MSN client (the last two thanks to bitlbee)
  • bitlbee: translate jabber/msn into irc communication :p
  • SVN

Result: enjoy :)

Here are some pics of my config:

vim, lstree and svn
irssi: IRC, jabber and msn
My website under elinks