#ansi-colors #color #ansi

colorism

一个用于使用终端 ANSI 颜色的库

1 个不稳定版本

0.1.0 2022年7月4日

16#colors

MIT 许可证

6KB
97

Colorism

一个用于使用终端 ANSI 颜色的库

 

❗️ 安装

cargo add colorism

 

🚀 使用方法

使用前景方法

// Import the fore method and RESET
use colorism::{foreground::Fore, util::RESET};

// Use RESET on all string ends, if you don't, the colors will escape to your terminal and will be really ugly, but not danger.
fn main() {
    // Green regular text
    println!("{}Hello, world!{}", Fore::color(Fore::Green), RESET);

    // Green bold text
    println!("{}Hello, world!{}", Fore::color(Fore::BdGreen), RESET);
}

 

使用背景方法

use colorism::{background::Back, util::RESET};

// Use RESET on all string ends, if you don't, the colors will escape to your terminal and will be really ugly, but not danger.
fn main() {
    // Green background, white text
    println!("{}Hello, world!{}", Back::color(Back::Green), RESET);

    // Green background, white bold text
    println!("{}Hello, world!{}", Back::color(Fore::BdGreen), RESET);
}

 

使用工具

// Import the util and (We will use Style to styling texts) RESET
use colorism::util::{Style, RESET};

// Use RESET on all string ends, if you don't, the colors will escape to your terminal and will be really ugly, but not danger.
fn main() {
    // Simple bold text
    println!("{}I am a text{}", Style::text(Style::Bold), RESET);

    // Simple underline text
    println!("{}I am a text{}", Style::text(Style::Underline), RESET);
}

无运行时依赖