一般使用Xshell通过SSH连接管理Centos/Debina服务器终端为8色,通过设置终端类型可开启256色彩以显示更加鲜艳的色彩。
查看当前终端类型:
1 2 | echo $TERM xterm-color |
查看当前服务器终端色彩:
1 2 | tput colors 8 |
或使用以下脚本检测并以色彩方式:
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 32 33 34 35 36 37 38 39 | #!/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文件内。
1 2 3 4 5 6 | 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安装:
1 2 | 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