Linux SSH终端terminal配色更改为256色


一般使用Xshell通过SSH连接管理Centos/Debina服务器终端为8色,通过设置终端类型可开启256色彩以显示更加鲜艳的色彩。
查看当前终端类型:
 
echo $TERM 
xterm-color
 
查看当前服务器终端色彩:
 
tput colors
8
 
或使用以下脚本检测并以色彩方式:
 
#!/usr/bin/env python
#检测当前终端支持色彩
import sys
import os
 
def echo(msg):
    os.system('echo -n "' + str(msg) + '"')
 
def out(n):
    os.system("tput setab " + str(n) + "; echo -n " + ("\"% 4d\"" % n))
    os.system("tput setab 0")
 
# normal colors 1 - 16
os.system("tput setaf 16")
for n in range(8):
    out(n)
echo("\n")
for n in range(8, 16):
    out(n)
 
echo("\n")
echo("\n")
 
y=16
while y < 231:
    for z in range(0,6):
        out(y)
        y += 1
 
    echo("\n")
 
echo("\n")
 
for n in range(232, 256):
    out(n)
    if n == 237 or n == 243 or n == 249:
        echo("\n")
 
echo("\n")
 
配置Linux终端如果支持就调整为256色终端,添加到.bashrc文件内。
 
if [ -e /usr/share/terminfo/x/xterm-256color ]; then
#debian在/lib/terminfo/x/xterm-256color
        export TERM='xterm-256color'
else
        export TERM='xterm-color'
fi
 
如不支持xterm-256color安装:
 
apt-get install ncurses-base
yum install ncurses
 
扩展阅读:
Colour colour everywhere! 256 colour-mode for Linux consoles:http://www.robmeerman.co.uk/unix/256colours
256 colors in vim:http://vim.wikia.com/wiki/256_colors_in_vim

相关内容

    暂无相关文章