-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Add simple formatted text capabilities to documentation + info_version() checks CARGO_PKG_VERSION + Remove debug messages + Fix README formatting
- Loading branch information
Hector
committed
Nov 15, 2024
1 parent
d7b3374
commit fa92e77
Showing
6 changed files
with
135 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "solid" | ||
version = "0.1.0" | ||
version = "0.2.1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,106 @@ | ||
pub const INFO_HELP: &str = r#" | ||
Usage: solid [command][flag][options...] | ||
Commands | ||
rgb | ||
Shows a 2d mapping rgb cube, with differents nets. | ||
Example: solid rgb | ||
Options: | ||
-b <number>: Bits quantitiy of each r,g,b channel. The range interval is [1,8]. | ||
Example: solid -b 3. Shows (axis^3)*(axis^3)*(cube faces). | ||
2^3 * 2^3 * 6 = 384 colors for the cube net. | ||
-n <name>: Type of 2d representation of the rgb cube. | ||
Available nets <name> are "ladder" and "cross". | ||
Example: solid -n cross | ||
-c <name>: Variation of where the cube is opened. It defines which planes are separeted or not. | ||
Available <name> are "a" and "b". | ||
Example: solid -c a | ||
Flag: | ||
-f: Activate fill effect. Repeat the color to fullfill a rectangle | ||
hsl | ||
Shows colors with Hue, saturation and lightness parameters.\ | ||
Example: solid hsl | ||
use std::collections::HashMap; | ||
|
||
#[derive(Debug)] | ||
enum TextStyle { | ||
Bold, | ||
Underline, | ||
Red, | ||
Green, | ||
BoldUnderline, | ||
BoldGreen, | ||
BoldUnderlineGreen, | ||
Reset, | ||
} | ||
|
||
impl TextStyle { | ||
fn to_ansi_code(&self) -> &'static str { | ||
match self { | ||
TextStyle::Bold => "\x1b[1m", | ||
TextStyle::Underline => "\x1b[4m", | ||
TextStyle::Red => "\x1b[31m", | ||
TextStyle::Green => "\x1b[32m", | ||
TextStyle::BoldUnderline => "\x1b[1;4m", | ||
TextStyle::BoldGreen => "\x1b[1;32m", | ||
TextStyle::BoldUnderlineGreen => "\x1b[1;4;32m", | ||
TextStyle::Reset => "\x1b[0m", | ||
} | ||
} | ||
} | ||
|
||
fn format_with_styles(template: &str, styles: &HashMap<&str, TextStyle>) -> String { | ||
let mut result = template.to_string(); | ||
|
||
for (placeholder, style) in styles { | ||
let ansi_code = style.to_ansi_code(); | ||
let placeholder_with_braces = format!("{{{}}}", placeholder); | ||
result = result.replace(&placeholder_with_braces, ansi_code); | ||
} | ||
|
||
result | ||
} | ||
|
||
pub fn info_help() { | ||
let info_help = r#" | ||
{bold}Usage:{reset} solid [command][flag][options...] | ||
{bold}COMMANDS{reset} | ||
{bold_green}rgb{reset} | ||
The default command. It shows a 2d mapping rgb cube, with differents nets. | ||
Example: | ||
{bold}solid rgb{reset} | ||
{bold}Options{reset}: | ||
{bold}-b <number>:{reset} | ||
Bits quantitiy for each r,g, and b channel. The range interval is {bold}[1,8]{reset}. | ||
It defines the amount of colors the cube net has. | ||
As a example if the option is set with value 3, then: | ||
Plane = (axis^3)*(axis^3) | ||
Cube = Plane * 6 | ||
Therefore, the total amount of colors displayed is 384 | ||
Example: | ||
{bold}solid -b 3{reset} | ||
{bold}-n <name>:{reset} | ||
Type of 2d representation of the rgb cube. | ||
Available nets {bold}<name>{reset} are {underline}ladder{reset} and {underline}cross{reset}. | ||
Example: | ||
{bold}solid -n cross{reset} | ||
{bold}-c <name>:{reset} | ||
Variation of where the cube is opened. It defines which planes are separeted or not. | ||
Available {bold}<name>{reset} are {underline}a{reset} and {underline}b{reset}. | ||
Example: | ||
{bold}solid -c a {reset} | ||
{bold}Flag:{reset} | ||
{bold}-f{reset}: | ||
Activate fill effect. Repeat colors to fullfill a rectangle. | ||
Example: | ||
{bold}solid -f{reset} | ||
{bold_green}hsl{reset} | ||
Shows colors with Hue, saturation and lightness parameters. | ||
Example: | ||
{bold}solid hsl{reset} | ||
"#; | ||
|
||
pub const INFO_VERSION: &str = r#"solid 0.1.0"#; | ||
let mut styles = HashMap::new(); | ||
styles.insert("bold", TextStyle::Bold); | ||
styles.insert("underline", TextStyle::Underline); | ||
styles.insert("red", TextStyle::Red); | ||
styles.insert("green", TextStyle::Green); | ||
styles.insert("bold_underline", TextStyle::BoldUnderline); | ||
styles.insert("bold_green", TextStyle::BoldGreen); | ||
styles.insert("bold_underline_green", TextStyle::BoldUnderlineGreen); | ||
styles.insert("reset", TextStyle::Reset); | ||
let formatted_text = format_with_styles(&info_help, &styles); | ||
|
||
println!("{}", formatted_text); | ||
} | ||
|
||
pub fn info_version() { | ||
let version = env!("CARGO_PKG_VERSION"); | ||
println!("Solid version: {}", version); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters