Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop into main for version 0.1.0 #15

Merged
merged 51 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9cf7b1e
feat: initialize new Rust project with cargo init
Syaw0 Oct 29, 2024
8cd25aa
chore: update Cargo.toml project metadata
Syaw0 Oct 29, 2024
d67a238
chore: add Github Actions workflow file
Syaw0 Oct 29, 2024
6367638
feat: Add ANSIEscapeCode struct with accompanying tests
Syaw0 Oct 31, 2024
d63eee2
refactor: move ANSIEscapeCode and tests to own module
Syaw0 Nov 1, 2024
27dc04f
feat: Add basic colors constants
Syaw0 Nov 1, 2024
5adde3c
feat: Add palette color struct with tests
Syaw0 Nov 1, 2024
8b24455
feat: Add RGB struct with tests
Syaw0 Nov 1, 2024
5b24cde
feat: Add Colorify trait with paint_fg and paint_bg
Syaw0 Nov 1, 2024
5c669e6
feat: Add a new trait, `Stylify` that use just `make_styles`
Syaw0 Nov 1, 2024
17609c6
chore: rename package from Vitalux to vitalux for consistency
Syaw0 Nov 2, 2024
68b701e
refactor: remove test.rs file and move tests to a module files
Syaw0 Nov 2, 2024
c41e8d8
feat: Implement the Stylify for PaintType
Syaw0 Nov 2, 2024
ffe74d4
feat: Add StyledText struct and implement the public api for basic co…
Syaw0 Nov 2, 2024
ca0f229
feat: Add Style enum and store style variants with their structs
Syaw0 Nov 3, 2024
be0cbea
feat: Use new implementation for styled_text
Syaw0 Nov 3, 2024
169ac59
feat: Add Clone to Styles variant structs
Syaw0 Nov 3, 2024
363697b
feat : Use default paint type if there is only one or zero pain type …
Syaw0 Nov 3, 2024
c5f297f
fix: Remove the extra \ from ANSIEscapeCode
Syaw0 Nov 3, 2024
bdd27b4
feat: Develop the paint method that merge all styles into String
Syaw0 Nov 3, 2024
d0c6ff5
feat: Using ref PaintType in make_styles trait method
Syaw0 Nov 3, 2024
a322ef4
test: Add test for basic color styles
Syaw0 Nov 3, 2024
4d0647d
feat: Add Formatter struct
Syaw0 Nov 4, 2024
427a129
feat: Add methods to format text
Syaw0 Nov 4, 2024
ad2546d
feat: Add reset method and change txt public api to styled
Syaw0 Nov 4, 2024
874e156
doc: Add basic documantation for styled method
Syaw0 Nov 4, 2024
fb1a1c0
refactor: extract the Stylify trait to traits.rs module and update th…
Syaw0 Nov 4, 2024
a56c441
refactor(colors.rs): just break the file into multiple module
Syaw0 Nov 5, 2024
95fb216
refactor: Move the styled_text module to lib and remove the styled_te…
Syaw0 Nov 5, 2024
d4beec4
refactor: rename the ansi_escape_code to ansi_code
Syaw0 Nov 6, 2024
ff9e504
refactor: Use `Macros` to create basic colors
Syaw0 Nov 6, 2024
4b4126e
test(basic_color.rs): Write test for coverage all of the module
Syaw0 Nov 6, 2024
8cabf4e
doc(basic_color.rs): Write document for module
Syaw0 Nov 6, 2024
fbf1c1b
refactor(formatter.rs): Write `Macro` to reduce code duplication
Syaw0 Nov 6, 2024
860c7a5
fix(basic_color.rs): fix issue with document comment test for color_c…
Syaw0 Nov 6, 2024
df4a75c
test(formatter.rs): Write test for coverage module
Syaw0 Nov 6, 2024
67b873d
doc(formatter.rs): Write document test for a module
Syaw0 Nov 6, 2024
217ce50
doc(paint_type.rs): Add document for a module
Syaw0 Nov 7, 2024
8fe8c70
test(paint_type.rs): Add basic tests for a module
Syaw0 Nov 7, 2024
8b9f3c8
doc(palette.rs): Add document for a module
Syaw0 Nov 7, 2024
d981ce9
test(palette.rs): Add tests for a module
Syaw0 Nov 7, 2024
745d582
doc(rgb.rs): Add test for a module
Syaw0 Nov 7, 2024
fadfff3
test(rgb.rs): Add tests for a module
Syaw0 Nov 7, 2024
1302bcd
doc(ansi_code.rs): add basic document for a module
Syaw0 Nov 7, 2024
f5bb741
doc(styles.rs): Add basic document for a module
Syaw0 Nov 7, 2024
1a67984
feat: Public the field of BasicColor and Formatter struct
Syaw0 Nov 7, 2024
6fbd3b5
test(styles.rs): Add tests for a module
Syaw0 Nov 7, 2024
f57bbf4
doc(lib.rs): Add document for a public api
Syaw0 Nov 7, 2024
01bfd96
chore: rename a package to `term_tools`
Syaw0 Nov 9, 2024
e8a2e64
doc(readme.md): just change the package name inside the file
Syaw0 Nov 9, 2024
8b40d10
doc: Add a document for a package
Syaw0 Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Rust

on:
push:
branches: ["develop"]
pull_request:
branches: ["develop"]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
13 changes: 3 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

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

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

/target
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "term_tools"
version = "0.1.0"
edition = "2021"
description = "Colorize Your Terminal with Term-Tools: A Rust-powered Formatting Tool"
authors = ["Siavash Siamhb7@protonmail.com"]
homepage = "https://crates.io/crates/term_tools"
repository = "https://github.com/Syaw0/term_tools"
license-file = "./LICENSE"
keywords = ["cli","terminal","rust","tool","coloize","formatter"]
categories = ["terminal","cli","command-line-utilitise","term-style", "terminal style"]

[dependencies]
137 changes: 135 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,135 @@
# Vitalux
Colorize Your Terminal with Vitalux: A Rust-powered Formatting Tool
# **term_tools: Rich API for Colorizing Terminal**

[![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)

## **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.
51 changes: 51 additions & 0 deletions src/ansi_code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/// A module for creating ansi escape code.
///
/// This module provides an struct `ANSIEscapeCode`
/// that represents ansi escape code, with `parameter` field.
/// It also implements the `ANSIEscapeCode`, with `new` and `code` method
/// which allows for generating anis escape code and getting a code.

// =======================================================================

/// An struct representing ansi escape code.
///
/// This struct has 1 field: `parameter` , which represent String of the ansi code.
pub struct ANSIEscapeCode {
parameter: String,
}
impl ANSIEscapeCode {
/// Returns a ANSIEscapeCode instance with parameter .
pub fn new(parameter: &str) -> Self {
ANSIEscapeCode { parameter: parameter.to_string() }
}

/// Returns a String that represent the ansi code.
pub fn code(&self) -> String {
format!("\x1b[{}m", self.parameter)
}
}

// =======================================================================

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn create_simple_ansi_code() {
let p = ANSIEscapeCode::new("33");
assert_eq!(p.code(), "\x1b[33m")
}

#[test]
fn create_reset_ansi_code() {
let reset_ansi = ANSIEscapeCode::new("0");
assert_eq!("\x1b[0m", reset_ansi.code());
}

#[test]
fn create_bright_cyan_ansi_code() {
let reset_ansi = ANSIEscapeCode::new("96");
assert_eq!("\x1b[96m", reset_ansi.code());
}
}
Loading