mirror of
https://github.com/arabianq/colorgram-rust.git
synced 2026-04-28 06:31:22 +00:00
new output for colorgram-cli
This commit is contained in:
+16
-9
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user