« The InternetStopping Weakness, Starting Strength »

Thu, Aug 08, 2013

[Icon][Icon]Colours within screens within screens

• Post categories: Omni, FOSS, Technology, Helpful

If you're a heavy command-line user, you're likely to find the pathetic handful of colours available as standard to be too limiting.

So you'll be running a 256-colour terminal. Much nicer.

You may also use GNU screen, or tmux, to allow for persistent sessions and multiple terminals within a single window. Also nice.

My problem started when I started needing to access multiple machines at once. One screen connected to multiple machines just resulted in too many terminals to try switching between. So I went the slightly more difficult route: Screens within screens.

You can do this with the defaults so long as you know that "Ctrl-a a" will send a "Ctrl-a" to the screen within the screen. But it's tortuous, so I advise you instead change the escape key. I moved mine to Z, since I rarely need to use Ctrl-z. Just add "escape ^Zz" to your screen config file to do this.

Job done, I now switch between machines with Ctrl-z and between screens on the machine with the usual Ctrl-a.

Just one problem: I lost my 256 colours :(

The problem was odd, because the screens were all 256-color. There's a nice little perl script I found ages ago - 256colors2.pl - which simply outputs all 256 colours to the terminal. My local screen displayed them perfectly. My remote machine's screen displayed them perfectly. But the remote machine's screen within my local screen didn't.


I asked around on #screen but although the problem sounded familiar, nobody could offer a solution.

I figured the problem had to be something in my environment, so I checked my TERM. it was 'xterm', then 'screen-bce' within a screen session. All fine. Then I noticed that when I ssh'd to the remote machine from within my local screen, it too picked up the 'screen-bce' setting. Which makes sense and is clever and all, but I had a hunch..

Yep. Exporting TERM=xterm on the remote machine before running screen solved the problem. In fact, running it before re-attaching to my existing screen fixed it, too. Finally, my vim syntax hilighting was back to full-colour!

It turns out the screen-bce terminfo on the remote machine isn't set to have 256 colours:

$ infocmp screen-bce   
#       Reconstructed via infocmp from file: /lib/terminfo/s/screen-bce
screen-bce|VT 100/ANSI X3.64 virtual terminal with bce,
        am, bce, km, mir, msgr, xenl,
        colors#8, cols#80, it#8, lines#24, pairs#64,

See? Eight. What use are just EIGHT colours?!?

So, let's fix this problem properly, shall we? We need to fix the terminal settings.

Now, you could do this by modifying the termcap:

$ infocmp screen-bce > screen-bce.ti
$ vi !$

^ dumps the current definition into a text file and opens it for editing in vi. Edit colors from 8 to 256, save and exit.

$ sudo tic screen-bce.ti 

^ As root, compile the modified source file into the binary that'll live in /usr/share/terminfo/

However, an examination of the /usr/share/terminfo/s/ directory shows a termcap called screen-256color-s, so rather than change the termcap on every server, it seemed to make more sense to just update my settings so that screen would set my TERM to be the 256-color one.

This I duly did, and w00t! I have 256 colours everywhere, regardless of whether the screens are contained in other screens. Yay!

No feedback yet


[Links][icon] My links

[Icon][Icon]About Me

[Icon][Icon]About this blog

[Icon][Icon]My /. profile

[Icon][Icon]My Wishlist


[FSF Associate Member]

December 2017
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31


User tools

XML Feeds

eXTReMe Tracker

Valid XHTML 1.0 Transitional

Valid CSS!

[Valid RSS feed]

powered by b2evolution