Question

I would like to have a if-else loop in .screenrc for the following codes such that it is run if my terminal supports 256 colors. Otherwise, it is not run.

attrcolor b ".I"
# tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm "Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm"
termcapinfo xterm-color "Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm"

How can you make the if-else loop in .screenrc?

Was it helpful?

Solution

This should already be set by the terminfo database file. In my case my default terminal is xterm. It uses 8 colors which is reflected in vi by using the

:set termcap

command an inspecting the t_Co item which is set to 8. If I change my terminal to another terminal type like gnome-256color which uses 256 colors then vi will show t_Co as equal to 256. I'm not sure why you need to try and set this in your .vimrc file.

OTHER TIPS

I believe something like this should work if you have bash available:

#!/bin/bash
if [ "$TERM" = "xterm-256color" ]; then
    # do stuff for 256
else
    if [ "$TERM" = "xterm" ]; then
        # do stuff for 16
    else
        # do something else entirely
    fi
fi

My pseudo-code attempt for .screenrc

[ -e t_Co(256) ] . ColorFile

The same in English

If 256 color support, then source ColorFile.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top