Skip to content

Commit b65070b

Browse files
authored
Merge pull request #15 from Syaw0/develop
Merge develop into main for version 0.1.0
2 parents 517e2b3 + 8b40d10 commit b65070b

File tree

13 files changed

+1304
-12
lines changed

13 files changed

+1304
-12
lines changed

.github/workflows/rust.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: ["develop"]
6+
pull_request:
7+
branches: ["develop"]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Build
19+
run: cargo build --verbose
20+
- name: Run tests
21+
run: cargo test --verbose

.gitignore

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,12 @@
33
debug/
44
target/
55

6-
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7-
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8-
Cargo.lock
9-
106
# These are backup files generated by rustfmt
117
**/*.rs.bk
128

139
# MSVC Windows builds of rustc generate these, which store debugging information
1410
*.pdb
1511

16-
# RustRover
17-
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
18-
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
19-
# and can be added to the global gitignore or merged into this file. For a more nuclear
20-
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
21-
#.idea/
12+
# Added by cargo
13+
14+
/target

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "term_tools"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Colorize Your Terminal with Term-Tools: A Rust-powered Formatting Tool"
6+
authors = ["Siavash Siamhb7@protonmail.com"]
7+
homepage = "https://crates.io/crates/term_tools"
8+
repository = "https://github.com/Syaw0/term_tools"
9+
license-file = "./LICENSE"
10+
keywords = ["cli","terminal","rust","tool","coloize","formatter"]
11+
categories = ["terminal","cli","command-line-utilitise","term-style", "terminal style"]
12+
13+
[dependencies]

README.md

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,135 @@
1-
# Vitalux
2-
Colorize Your Terminal with Vitalux: A Rust-powered Formatting Tool
1+
# **term_tools: Rich API for Colorizing Terminal**
2+
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Version](https://img.shields.io/badge/dynamic/toml?url=https%3A%2F%2Fraw.githubusercontent.com%2FSyaw0%2Fterm_tools%2Frefs%2Fheads%2Fdevelop%2FCargo.toml&query=package.version&label=Version&color=red)](https://crates.io/term_tools)
4+
5+
## **Overview**
6+
7+
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.
8+
9+
## **Features**
10+
11+
- **Colors**: Supports 16 basic colors, 256 palette colors, and RGB colors.
12+
- **Effects**: Supports slow blink and rapid blink.
13+
- **Formatters**: Supports reset, bold, faint, italic, underline, and overline formatters.
14+
- **Easy to use**: Simple and intuitive API for creating styled text strings.
15+
16+
## **Usage**
17+
18+
To use term_tools, simply add the following line to your `Cargo.toml` file:
19+
20+
```toml
21+
[dependencies]
22+
term_tools = "0.1.0"
23+
```
24+
25+
Then, import the library in your Rust code:
26+
27+
```rust
28+
use term_tools::styled;
29+
```
30+
31+
Create a styled text string using the `styled` function:
32+
33+
```rust
34+
let styled_text = styled("Hello, World!")
35+
.red()
36+
.bold()
37+
.underline()
38+
.paint();
39+
println!("{}", styled_text);
40+
```
41+
42+
## **Sequence of Styles**
43+
44+
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.
45+
46+
When you call `fg` or `bg`, all styles that come before it will be applied to the foreground or background, respectively.
47+
48+
Here's an example:
49+
50+
```rust
51+
let styled_text = styled("Hello, World!")
52+
.red() // applies to foreground
53+
.fg() // sets foreground color to red
54+
.blue() // applies to background
55+
.bg() // sets background color to blue
56+
.paint();
57+
```
58+
59+
In this example, the `red` style is applied to the foreground, and the `blue` style is applied to the background.
60+
61+
if there is only one call of `fg` or `bg` whole colors applied that `PaintType` for example:
62+
63+
```rust
64+
let styled_text = styled("Hello, World!")
65+
.red() // red color
66+
.blue() // blue color
67+
.bg() // apply background color
68+
.magenta() // magenta color
69+
.paint();
70+
```
71+
72+
in this example `paint` method will apply the background color of all colors.
73+
74+
if there is not any `fg` or `bg` call , the default paint type assume as `Foreground` for example:
75+
76+
```rust
77+
let styled_text = styled("Hello, World!")
78+
.red() // red color
79+
.blue() // blue color
80+
.paint();
81+
```
82+
83+
in this example the `paint` method will use foreground color of the colors.
84+
85+
## **Examples**
86+
87+
Here are some examples of using term_tools:
88+
89+
- **Basic colors**:
90+
91+
```rust
92+
let styled_text = styled("Hello, World!")
93+
.red()
94+
.paint();
95+
println!("{}", styled_text);
96+
```
97+
98+
- **RGB colors**:
99+
100+
```rust
101+
let styled_text = styled("Hello, World!")
102+
.rgb(255, 0, 0)
103+
.paint();
104+
println!("{}", styled_text);
105+
```
106+
107+
- **Effects**:
108+
109+
```rust
110+
let styled_text = styled("Hello, World!")
111+
.bold()
112+
.underline()
113+
.paint();
114+
println!("{}", styled_text);
115+
```
116+
117+
- **Formatters**:
118+
119+
```rust
120+
let styled_text = styled("Hello, World!")
121+
.reset()
122+
.bold()
123+
.paint();
124+
println!("{}", styled_text);
125+
```
126+
127+
## **License**
128+
129+
term_tools is licensed under the MIT License.
130+
131+
## **Contributing**
132+
133+
Contributions are welcome If you'd like to contribute to term_tools, please fork the repository and submit a pull request.
134+
135+
I hope this helps Let me know if you'd like me to make any changes.

src/ansi_code.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/// A module for creating ansi escape code.
2+
///
3+
/// This module provides an struct `ANSIEscapeCode`
4+
/// that represents ansi escape code, with `parameter` field.
5+
/// It also implements the `ANSIEscapeCode`, with `new` and `code` method
6+
/// which allows for generating anis escape code and getting a code.
7+
8+
// =======================================================================
9+
10+
/// An struct representing ansi escape code.
11+
///
12+
/// This struct has 1 field: `parameter` , which represent String of the ansi code.
13+
pub struct ANSIEscapeCode {
14+
parameter: String,
15+
}
16+
impl ANSIEscapeCode {
17+
/// Returns a ANSIEscapeCode instance with parameter .
18+
pub fn new(parameter: &str) -> Self {
19+
ANSIEscapeCode { parameter: parameter.to_string() }
20+
}
21+
22+
/// Returns a String that represent the ansi code.
23+
pub fn code(&self) -> String {
24+
format!("\x1b[{}m", self.parameter)
25+
}
26+
}
27+
28+
// =======================================================================
29+
30+
#[cfg(test)]
31+
mod tests {
32+
use super::*;
33+
34+
#[test]
35+
fn create_simple_ansi_code() {
36+
let p = ANSIEscapeCode::new("33");
37+
assert_eq!(p.code(), "\x1b[33m")
38+
}
39+
40+
#[test]
41+
fn create_reset_ansi_code() {
42+
let reset_ansi = ANSIEscapeCode::new("0");
43+
assert_eq!("\x1b[0m", reset_ansi.code());
44+
}
45+
46+
#[test]
47+
fn create_bright_cyan_ansi_code() {
48+
let reset_ansi = ANSIEscapeCode::new("96");
49+
assert_eq!("\x1b[96m", reset_ansi.code());
50+
}
51+
}

0 commit comments

Comments
 (0)