海运的博客

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

发布时间:December 15, 2012 // 分类:Xshell // No Comments

一般使用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

分类
最新文章
最近回复
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...
  • jiangker: good, very helpful to me
  • fengfeng: N1 armbian 能有编译下内核吗。。我要开启can 不懂怎么操作
  • 1: 方法一ngtcp2要改下:./configure PKG_CONFIG_PATH=/usr/l...
  • 海运: 关闭服务器
  • 海风: override.battery.charge.low以及override.battery.r...
  • koldjf: 不能过滤
  • 杰迪武士: 此文甚好甚强巨,依照此文在树莓派2 + Rasbian上部署成功 感谢博主美文共赏