Python/Perl/Shell 输出彩色字体

时间:2021-09-25 16:22:15

Python/Perl/Shell 输出彩色字体


彩色代码

Python/Perl/Shell 输出彩色字体


输出格式

    ++ 颜色代码+输出文字+结束符

如:

    红色 ->  \033[0;31m 红色 \033[0m

    黄色 ->  \033[1;33m 黄色 \033[0m

    蓝色 ->  \033[0;34m 蓝色 \033[0m


Perl输出

#!/bin/env perl
use strict;
#Set Color
my $black         = "\033[0;30m";
my $dary_gray     = "\033[1;30m";    my $light_gray   = "\033[0;37m";
my $blue          = "\033[0;34m";    my $light_blue   = "\033[1;34m";
my $green         = "\033[0;32m";    my $light_green  = "\033[1;32m";
my $cyan          = "\033[0;36m";    my $ligth_cyan   = "\033[1;36m";
my $red           = "\033[0;31m";    my $ligth_red    = "\033[1;31m";    my $red_bold = "\033[01;31m";
my $purple        = "\033[0;35m";    my $light_purple = "\033[1;35m";
my $brown         = "\033[0;33m";
my $yellow        = "\033[1;33m";
my $white         = "\033[1;37m";
my $default_color = "\033[00m";
my $end           = "\033[0m";

print $blue  ."蓝色$end\n";
print $red   ."红色$end\n";
print $yellow."黄色$end\n";

Python输出

#!/bin/env python
# -*- coding: utf-8 -*-

#Set Color Class
class colors:
    BLACK         = '\033[0;30m'
    DARK_GRAY     = '\033[1;30m'
    LIGHT_GRAY    = '\033[0;37m'
    BLUE          = '\033[0;34m'
    LIGHT_BLUE    = '\033[1;34m'
    GREEN         = '\033[0;32m'
    LIGHT_GREEN   = '\033[1;32m'
    CYAN          = '\033[0;36m'
    LIGHT_CYAN    = '\033[1;36m'
    RED           = '\033[0;31m'
    LIGHT_RED     = '\033[1;31m'
    PURPLE        = '\033[0;35m'
    LIGHT_PURPLE  = '\033[1;35m'
    BROWN         = '\033[0;33m'
    YELLOW        = '\033[1;33m'
    WHITE         = '\033[1;37m'
    DEFAULT_COLOR = '\033[00m'
    RED_BOLD      = '\033[01;31m'
    ENDC          = '\033[0m'
print colors.BLUE   + "蓝色" + colors.ENDC
print colors.RED    + "红色" + colors.ENDC
print colors.YELLOW + "黄色" + colors.ENDC

Shell输出

#!/bin/env bash

#Set Color
        black='\033[0;30m'
    dark_gray='\033[1;30m'
   light_gray='\033[0;37m'
         blue='\033[0;34m'
   light_blue='\033[1;34m'
        green='\033[0;32m'
  light_green='\033[1;32m'
         cyan='\033[0;36m'
   light_cyan='\033[1;36m'
          red='\033[0;31m'
    light_red='\033[1;31m'
       purple='\033[0;35m'
 light_purple='\033[1;35m'
        brown='\033[0;33m'
       yellow='\033[1;33m'
        white='\033[1;37m'
default_color='\033[00m'
     red_bold='\033[01;31m'
         endc='\033[0m'
echo -e   $blue"蓝色"$endc
echo -e    $red"红色"$endc
echo -e $yellow"黄色"$endc

输出效果均为 Python/Perl/Shell 输出彩色字体


--------------------------------------------------------------------------------------
版权所有,转载时必须以链接方式注明源地址,否则追究法律责任!

QQ    :   413844436
Email  :   softomg@163.com
Blog   :   http://blog.csdn.net/softomg