diff --git a/Cargo.lock b/Cargo.lock index bfcb7f0..4c46c06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,7 +79,7 @@ dependencies = [ [[package]] name = "solid" -version = "0.1.0" +version = "0.2.1" dependencies = [ "serde", "toml", diff --git a/Cargo.toml b/Cargo.toml index bcf226d..8feb0fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "solid" -version = "0.1.0" +version = "0.2.1" edition = "2021" [dependencies] diff --git a/README.md b/README.md index 63e41e8..279ac96 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + # Solid The software unfold the rgb cube in a specific net and display it on terminal. Color amount, net shape, and cut orientation are configurable. Alternatively, @@ -20,26 +21,35 @@ cargo build --release ### Commands #### rgb -Shows a 2d mapping rgb cube, with differents nets.\ +Shows a 2d mapping rgb cube, with differents nets. + **Example**: `solid rgb` -> - Options: ->> -b \: - Bits quantitiy of each r,g,b channel. The range interval is [1,8].\ - **Example**: `solid -b 3`. ->> -n \: - Type of 2d representation of the rgb cube. Available nets are - "ladder" and "cross".\ - **Example**: `solid -n cross` +- Options: + - -b \: + Bits quantitiy for each r,g, and b channel. The range interval is [1,8].\ + 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**: `solid -b 3` + + - -n \: + Type of 2d representation of the rgb cube. Available nets are \ + "ladder" and "cross".\ + **Example**: `solid -n cross` ->> -c \: - Variation of where the cube is opened. It defines which planes are separeted or not. - Available \ are `a` and `b`.\ - **Example**: `solid -c a` + - -c \: + Variation of where the cube is opened. It defines which planes are separeted or not.\ + Available \ are `a` and `b`.\ + **Example**: `solid -c a` -> - Flag: ->> -f: Activate fill effect. Repeat the color to fullfill a rectangle +- Flag: + - -f: + Activate fill effect. Repeat the color to fulfill a rectangle. #### hsl -Shows colors with Hue, saturation and lightness parameters.\ +Shows colors with Hue, saturation and lightness parameters. + **Example**: `solid hsl` diff --git a/src/cube_net/render_net.rs b/src/cube_net/render_net.rs index 74c3ea6..56d1d97 100644 --- a/src/cube_net/render_net.rs +++ b/src/cube_net/render_net.rs @@ -71,7 +71,6 @@ pub fn render_matrix(block_matrix: &mut Matrix, plane_size: usize, net_shape: Ne match net_shape { NetShapeAndFx::Cross(cross) => { matrix_cross(&cross, block_matrix); - println!("Done"); } NetShapeAndFx::CrossFill(cross_fill) => { matrix_cross(&cross_fill, block_matrix); diff --git a/src/initialization/config_utils.rs b/src/initialization/config_utils.rs index 4b28ea3..7232678 100644 --- a/src/initialization/config_utils.rs +++ b/src/initialization/config_utils.rs @@ -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 : 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 : Type of 2d representation of the rgb cube. - Available nets are "ladder" and "cross". - Example: solid -n cross - -c : Variation of where the cube is opened. It defines which planes are separeted or not. - Available 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 :{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 :{reset} + Type of 2d representation of the rgb cube. + Available nets {bold}{reset} are {underline}ladder{reset} and {underline}cross{reset}. + Example: + {bold}solid -n cross{reset} + + {bold}-c :{reset} + Variation of where the cube is opened. It defines which planes are separeted or not. + Available {bold}{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); +} diff --git a/src/initialization/configuration.rs b/src/initialization/configuration.rs index baf5938..4047523 100644 --- a/src/initialization/configuration.rs +++ b/src/initialization/configuration.rs @@ -108,7 +108,7 @@ fn tokenize(args: Vec) -> Result, String> { } else if key_value_options.contains(&word.as_str()) { if let Some(value) = words.peek() { tokens.push(Token::KeyValueOption(word.to_string(), value.to_string())); - words.next(); // Consume the value + words.next(); } else { return Err(format!("Option '{}' requires a value", word)); } @@ -140,14 +140,14 @@ fn analyze_syntax(tokens: Vec) -> Result { if tokens.len() > 1 { return Err(format!("-v can't have other arguments")); } - println!("{}", config_utils::INFO_HELP); + config_utils::info_help(); cfg.show_info_on = true; } "-v" => { if tokens.len() > 1 { return Err(format!("-v can't have other arguments")); } - println!("{}", config_utils::INFO_VERSION); + config_utils::info_version(); cfg.show_info_on = true; } "-f" => cfg.rgb.flag_fill = true, @@ -221,7 +221,6 @@ pub fn start(mut args: Vec) { match config.rgb.bits_qty { 1..=8 => { rgb_net_render(&config); - // render_fill(&rgbspace.key_planes); } _ => {