你如何用腻子/bash 显示 xterm 颜色?

qod*_*nja 8 colors xterm putty

Putty 有我想使用的“允许终端使用 xterm 256 色模式”,但我不知道如何使用。我一直在使用color.sh脚本来输出带有颜色的 echo 语句和命令,我想用 xterm 颜色做类似的事情。

#!/bin/bash
## Specify color to write in using arguments

function --help {
cat << EOF

ERROR: $0 requires a color argument.

USAGE: Changes the color of the text piped into it.

These color arguments are availabe:

    ARGUMENT    SHORTCUT
    white   ------  w
    red ------  r
    green   ------  g
    yellow  ------  y
    blue    ------  b
    violet  ------  v
    teal    ------  t

    bold    ------  bb

The "bold" argument will modify any color.
Use a max of 2 arguments (one color and bold).

EOF
}

function bold {
# make the color bold
BOLD=1\;
}

function white {
COLOR=1
}

function red {
COLOR=31
}

function green {
COLOR=32
}

function yellow {
COLOR=33
}

function blue {
COLOR=34
}

function violet {
COLOR=35
}

function teal {
COLOR=36
}


## shortcuts
function bb {
bold
}
function w {
white
}
function r {
red
}
function g {
green
}
function y {
yellow
}
function b {
blue
}
function v {
violet
}
function t {
teal
}
function o {
red
bold
}

## Execution

if [ "$#" = 0 ]
then
--help
fi

while (($#));
    do
        $1
        shift
    done

echo -n "["$BOLD""$COLOR"m"
cat
echo -n "[0m"
Run Code Online (Sandbox Code Playgroud)

小智 18

对我来说,我必须进入设置并设置终端类型。设置->连接>数据>终端类型更改为xterm-256color.


jas*_*yan 12

根据 PuTTY 用户手册,这应该默认启用

如果您有一个应该使用 256 色模式的应用程序但它不起作用,您可能会发现您需要告诉您的服务器您的终端支持 256 色。在 Unix 上,您可以通过确保 TERM 的设置描述一个具有 256 色能力的终端来做到这一点。您可以使用以下命令进行检查infocmp
$ infocmp | grep colors
        colors#256, cols#80, it#8, lines#24, pairs#256,
Run Code Online (Sandbox Code Playgroud) 如果colors#256在输出中没有看到,则可能需要更改终端设置。在现代 Linux 机器上,您可以尝试xterm-256color.

如果您希望在特定应用程序(如 Vim 或 Emacs)中使用 256 色,则有单独的指南来说明如何实现这一点:

  • 您也可以尝试将 Putty 的终端类型(`Connection-&gt;Data-&gt;Terminal-type string`)配置为您的系统可能识别的 `putty-256color`。 (3认同)