https://github.com/syaw0/term_tools
Colorize Your Terminal with Term_Tools: A Rust-powered Formatting Tool
https://github.com/syaw0/term_tools
cli cli-style rust rust-cli rust-crate rust-lang rust-terminal terminal terminal-style
Last synced: 5 months ago
JSON representation
Colorize Your Terminal with Term_Tools: A Rust-powered Formatting Tool
- Host: GitHub
- URL: https://github.com/syaw0/term_tools
- Owner: Syaw0
- License: mit
- Created: 2024-10-29T05:57:23.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2024-11-12T06:48:55.000Z (over 1 year ago)
- Last Synced: 2024-11-27T13:24:05.651Z (about 1 year ago)
- Topics: cli, cli-style, rust, rust-cli, rust-crate, rust-lang, rust-terminal, terminal, terminal-style
- Language: Rust
- Homepage: https://crates.io/crates/term_tools
- Size: 36.1 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# **term_tools: Rich API for Colorizing Terminal**
[](https://opensource.org/licenses/MIT) [](https://crates.io/term_tools)
## **Overview**
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.
## **Features**
- **Colors**: Supports 16 basic colors, 256 palette colors, and RGB colors.
- **Effects**: Supports slow blink and rapid blink.
- **Formatters**: Supports reset, bold, faint, italic, underline, and overline formatters.
- **Easy to use**: Simple and intuitive API for creating styled text strings.
## **Usage**
To use term_tools, simply add the following line to your `Cargo.toml` file:
```toml
[dependencies]
term_tools = "0.1.0"
```
Then, import the library in your Rust code:
```rust
use term_tools::styled;
```
Create a styled text string using the `styled` function:
```rust
let styled_text = styled("Hello, World!")
.red()
.bold()
.underline()
.paint();
println!("{}", styled_text);
```
## **Sequence of Styles**
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:
```rust
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:
```rust
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:
```rust
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.
## **Examples**
Here are some examples of using term_tools:
- **Basic colors**:
```rust
let styled_text = styled("Hello, World!")
.red()
.paint();
println!("{}", styled_text);
```
- **RGB colors**:
```rust
let styled_text = styled("Hello, World!")
.rgb(255, 0, 0)
.paint();
println!("{}", styled_text);
```
- **Effects**:
```rust
let styled_text = styled("Hello, World!")
.bold()
.underline()
.paint();
println!("{}", styled_text);
```
- **Formatters**:
```rust
let styled_text = styled("Hello, World!")
.reset()
.bold()
.paint();
println!("{}", styled_text);
```
## **License**
term_tools is licensed under the MIT License.
## **Contributing**
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.