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
Generated
+32
View File
@@ -14,6 +14,15 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1"
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "anstream"
version = "0.6.18"
@@ -253,6 +262,7 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
name = "colorgram"
version = "0.1.0"
dependencies = [
"ansi_term",
"clap",
"image",
]
@@ -1105,6 +1115,28 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.59.0"
+1
View File
@@ -14,6 +14,7 @@ keywords = ["colors", "image", "extract", "colorgram"]
[dependencies]
image = { version = "0.25.6", features = ["default-formats"] }
clap = { version = "4.5.37", features = ["derive"] }
ansi_term = { version = "0.12.1" }
[lib]
name = "colorgram"
+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),