彩色文本输出

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/bash

#输出彩色文字,需要四个参数,分别是前景色,背景色,样式,文字
function ColorText()
{
#判断参数个数,更加严格的判断比如是否超过范围这里就不做详细判断了
        if [ $# -ne 4  ]
        then
                echo "Usage:4 parameters are needed!"
                echo "ForeColor,BackgroundClor Style and Text!"
                ShowHelp;
        else
                Fg="3""$1"
                Bg="4""$2"
                SetColor="\E[""$Fg;$Bg""m"
                Style="\033[""$3""m"
                Text="$4"
                EndStyle="\033[0m"
                echo -e "$SetColor""$Style""$Text""$EndStyle"
        fi;
}

#输出帮助信息
function ShowHelp()
{
        echo "The frst parameter is a number ranged from 1 to 10,represents the foreground color."
        echo "The second parameter is  a number ranged from 1 to 10,represents the background color."
        ColorText 1 8 2 "1    red";
        ColorText 2 8 2 "2    green";
        ColorText 3 8 2 "3    yellow";
        ColorText 4 8 2 "4    blue";
        ColorText 5 8 2 "5    magenta";
        ColorText 6 8 2 "6    cyan";
        ColorText 7 8 2 "7    gray";
        ColorText 8 8 2 "8    white";
        ColorText 9 8 2 "9    white";
        ColorText 10 8 2 "10   black";
        echo "The third parameter is a number ranged from 1 to 9,represents the style of the characters."
        ColorText 10 8 1 "1    lighter,and bold";
        ColorText 10 8 4 "4    draw a line under the string.";
        ColorText 10 8 7 "7    swap the foreground color and the background color";
        ColorText 10 8 9 "9    draw a deleting line";
        ColorText 10 8 9 "others  normal style";
        echo "The fourth parameter is the content you wanna clolor,a string."
}

ColorText 1 8 2 'Test'

#ColorText

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

系ubuntu 下面打开终端输入:sudo apt-get install sendmail...
依家我有1个软件goagent目录(大家懂得) 放在/home/gateman/...
其实我想讲的是 cp -L关于-L参数的解释:-L, --dereferenc...
原地址:http://www.rjgc.net/control/content/content.php?...
chroot,即 change root directory (更改 root 目录)。在 li...
简单解析下, stdin就是标准输入, stdout就是标准。举个例子...