Crates.io | vividtext |
lib.rs | vividtext |
version | 0.1.3 |
source | src |
created_at | 2024-03-27 09:19:38.371968 |
updated_at | 2024-03-27 14:08:32.708251 |
description | Library to change text color |
homepage | |
repository | https://github.com/cuticle999/VividText |
max_upload_size | |
id | 1187673 |
size | 26,306 |
This is a library for coloring text. At this stage, it is designed for output on the CLI.
Add a dependency
cargo add vividtext
Example of coloring the specified text main.rs
use vividtext::colorful_text::{apply_gradient, OutputFormat};
fn main() {
let text = "Hello, world!";
let formatted_text = apply_gradient(text, OutputFormat::Ansi);
println!("{}", formatted_text);
}
Example of outputting text entered in a text file main.rs
use std::fs::File;
use std::io::{self, Read};
use vividtext::colorful_text::{apply_gradient, OutputFormat};
fn main() -> io::Result<()> {
let file_path = "./like.text";
let mut file = File::open(file_path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let gradient_text = apply_gradient(&contents, OutputFormat::Ansi);
// または
// let gradient_text = apply_gradient(&contents, OutputFormat::Rgb);
println!("{}", gradient_text);
Ok(())
}
How to use with CLI If you specify a text file, etc., the text will be colored on the CLI.
cargo install vividtext
vividtext your_file
MIT