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:
Generated
+32
@@ -14,6 +14,15 @@ version = "0.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1"
|
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]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.18"
|
version = "0.6.18"
|
||||||
@@ -253,6 +262,7 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
|||||||
name = "colorgram"
|
name = "colorgram"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"ansi_term",
|
||||||
"clap",
|
"clap",
|
||||||
"image",
|
"image",
|
||||||
]
|
]
|
||||||
@@ -1105,6 +1115,28 @@ version = "0.1.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
|
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]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.59.0"
|
version = "0.59.0"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ keywords = ["colors", "image", "extract", "colorgram"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
image = { version = "0.25.6", features = ["default-formats"] }
|
image = { version = "0.25.6", features = ["default-formats"] }
|
||||||
clap = { version = "4.5.37", features = ["derive"] }
|
clap = { version = "4.5.37", features = ["derive"] }
|
||||||
|
ansi_term = { version = "0.12.1" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "colorgram"
|
name = "colorgram"
|
||||||
|
|||||||
+16
-9
@@ -1,3 +1,4 @@
|
|||||||
|
use ansi_term::{Color::RGB, Style};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use colorgram::extract;
|
use colorgram::extract;
|
||||||
use std::path::{PathBuf, absolute};
|
use std::path::{PathBuf, absolute};
|
||||||
@@ -5,10 +6,15 @@ use std::path::{PathBuf, absolute};
|
|||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[arg(short = 'i', long = "input")]
|
#[arg(short = 'i', long = "input", help = "Path to the image")]
|
||||||
input_file: PathBuf,
|
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,
|
colors_amount: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,13 +31,14 @@ fn main() {
|
|||||||
match extract(input_path, colors_amount) {
|
match extract(input_path, colors_amount) {
|
||||||
Ok(colors) => {
|
Ok(colors) => {
|
||||||
for color in colors {
|
for color in colors {
|
||||||
println!(
|
let style = Style::new()
|
||||||
"RGB: ({}, {}, {}), Proportion: {:.2}%",
|
.bold()
|
||||||
color.rgb.r,
|
.fg(RGB(255 - color.rgb.r, 255 - color.rgb.g, 255 - color.rgb.b))
|
||||||
color.rgb.g,
|
.on(RGB(color.rgb.r, color.rgb.g, color.rgb.b));
|
||||||
color.rgb.b,
|
let proportion_string = format!("{:.2}%", color.proportion * 100.0);
|
||||||
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),
|
Err(e) => eprintln!("Error: {}", e),
|
||||||
|
|||||||
Reference in New Issue
Block a user