Crates.io | term_tools |
lib.rs | term_tools |
version | 0.1.0 |
source | src |
created_at | 2024-11-12 06:49:20.89704 |
updated_at | 2024-11-12 06:49:20.89704 |
description | Colorize Your Terminal with Term-Tools: A Rust-powered Formatting Tool |
homepage | https://crates.io/crates/term_tools |
repository | https://github.com/Syaw0/term_tools |
max_upload_size | |
id | 1444595 |
size | 42,680 |
term_tools is a Rust library that provides a rich API for colorizing terminal output. It allows you to create styled text strings with various colors, effects, and formatters.
To use term_tools, simply add the following line to your Cargo.toml
file:
[dependencies]
term_tools = "0.1.0"
Then, import the library in your Rust code:
use term_tools::styled;
Create a styled text string using the styled
function:
let styled_text = styled("Hello, World!")
.red()
.bold()
.underline()
.paint();
println!("{}", styled_text);
The sequence of styles is important when using the fg
and bg
methods. These methods set the foreground and background colors, respectively, for all subsequent styles.
When you call fg
or bg
, all styles that come before it will be applied to the foreground or background, respectively.
Here's an example:
let styled_text = styled("Hello, World!")
.red() // applies to foreground
.fg() // sets foreground color to red
.blue() // applies to background
.bg() // sets background color to blue
.paint();
In this example, the red
style is applied to the foreground, and the blue
style is applied to the background.
if there is only one call of fg
or bg
whole colors applied that PaintType
for example:
let styled_text = styled("Hello, World!")
.red() // red color
.blue() // blue color
.bg() // apply background color
.magenta() // magenta color
.paint();
in this example paint
method will apply the background color of all colors.
if there is not any fg
or bg
call , the default paint type assume as Foreground
for example:
let styled_text = styled("Hello, World!")
.red() // red color
.blue() // blue color
.paint();
in this example the paint
method will use foreground color of the colors.
Here are some examples of using term_tools:
let styled_text = styled("Hello, World!")
.red()
.paint();
println!("{}", styled_text);
let styled_text = styled("Hello, World!")
.rgb(255, 0, 0)
.paint();
println!("{}", styled_text);
let styled_text = styled("Hello, World!")
.bold()
.underline()
.paint();
println!("{}", styled_text);
let styled_text = styled("Hello, World!")
.reset()
.bold()
.paint();
println!("{}", styled_text);
term_tools is licensed under the MIT License.
Contributions are welcome If you'd like to contribute to term_tools, please fork the repository and submit a pull request.
I hope this helps Let me know if you'd like me to make any changes.