Skip to content

Commit

Permalink
Documentation improvements
Browse files Browse the repository at this point in the history
+ 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
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
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]
Expand Down
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 \<number\>:
Bits quantitiy of each r,g,b channel. The range interval is [1,8].\
**Example**: `solid -b 3`.

>> -n \<name\>:
Type of 2d representation of the rgb cube. Available nets <name> are
"ladder" and "cross".\
**Example**: `solid -n cross`
- Options:
- -b \<number\>:
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 \<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`
- -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
- 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`
1 change: 0 additions & 1 deletion src/cube_net/render_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
128 changes: 104 additions & 24 deletions src/initialization/config_utils.rs
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);
}
7 changes: 3 additions & 4 deletions src/initialization/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn tokenize(args: Vec<String>) -> Result<Vec<Token>, 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));
}
Expand Down Expand Up @@ -140,14 +140,14 @@ fn analyze_syntax(tokens: Vec<Token>) -> Result<Config, String> {
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,
Expand Down Expand Up @@ -221,7 +221,6 @@ pub fn start(mut args: Vec<String>) {
match config.rgb.bits_qty {
1..=8 => {
rgb_net_render(&config);
// render_fill(&rgbspace.key_planes);
}

_ => {
Expand Down

0 comments on commit fa92e77

Please sign in to comment.