new output for colorgram-cli

This commit is contained in:
2025-05-09 22:58:56 +03:00
parent 916bea5eb2
commit c1f4b420b3
3 changed files with 49 additions and 9 deletions
+16 -9
View File
@@ -1,3 +1,4 @@
use ansi_term::{Color::RGB, Style};
use clap::Parser;
use colorgram::extract;
use std::path::{PathBuf, absolute};
@@ -5,10 +6,15 @@ use std::path::{PathBuf, absolute};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[arg(short = 'i', long = "input")]
#[arg(short = 'i', long = "input", help = "Path to the image")]
input_file: PathBuf,
#[arg(short = 'c', long = "colors", default_value_t = 10)]
#[arg(
short = 'c',
long = "colors",
default_value_t = 10,
help = "Amount of colors to extract"
)]
colors_amount: usize,
}
@@ -25,13 +31,14 @@ fn main() {
match extract(input_path, colors_amount) {
Ok(colors) => {
for color in colors {
println!(
"RGB: ({}, {}, {}), Proportion: {:.2}%",
color.rgb.r,
color.rgb.g,
color.rgb.b,
color.proportion * 100.0
);
let style = Style::new()
.bold()
.fg(RGB(255 - color.rgb.r, 255 - color.rgb.g, 255 - color.rgb.b))
.on(RGB(color.rgb.r, color.rgb.g, color.rgb.b));
let proportion_string = format!("{:.2}%", color.proportion * 100.0);
let final_string = format!("{:6} | {}", proportion_string, color.rgb);
let output = style.paint(format!("{:1}{:28}", "", final_string));
println!("{}", output);
}
}
Err(e) => eprintln!("Error: {}", e),