diff --git a/Cargo.lock b/Cargo.lock index 4cd66a1..b33a924 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,6 +193,19 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.52.0", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -244,6 +257,12 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -639,6 +658,12 @@ dependencies = [ "syn", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.161" @@ -1340,6 +1365,7 @@ name = "to-streamshare" version = "0.5.0" dependencies = [ "clap", + "console", "kdam", "streamshare", "tokio", @@ -1502,6 +1528,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + [[package]] name = "untrusted" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index 192068d..b86b3a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ keywords = ["streamshare", "file-sharing", "upload"] [dependencies] clap = { version = "4.5.20", features = ["derive"] } +console = "0.15.8" kdam = { version = "0.5.2", features = ["rich", "spinner"] } streamshare = "4" tokio = { version = "1.40.0", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index fd8b7ba..37da42d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use clap::{CommandFactory, Parser}; +use console::{measure_text_width, pad_str, Alignment}; use kdam::{term::Colorizer, tqdm, BarExt, Column, RichProgress, Spinner}; use std::fs; use std::io::{stderr, IsTerminal}; @@ -126,33 +127,48 @@ async fn main() -> std::io::Result<()> { pb.update_to(file_size as usize).unwrap(); pb.clear().unwrap(); - println!("\n{}", "┌".to_owned() + &"─".repeat(79) + "┐"); - println!("│{:^90}│", "Upload Complete!".colorize("bold green")); - println!("├{}┤", "─".repeat(79)); - - let download_url = format!( + let url = format!( "https://streamshare.wireway.ch/download/{}", file_identifier ); - println!( - "│ {:<15} {:<31} │", - "URL:".colorize("bold yellow"), - download_url - ); - println!( - "│ {:<15} {:<68} │", - "File ID:".colorize("bold yellow"), - file_identifier - ); - println!( - "│ {:<15} {:<61} │", - "Deletion Token:".colorize("bold yellow"), - deletion_token - ); - println!("{}", "└".to_owned() + &"─".repeat(79) + "┘"); - println!() + let title = "Upload Complete!".colorize("bold green"); + let label_url = "URL:".colorize("bold yellow"); + let label_file_id = "File ID:".colorize("bold yellow"); + let label_deletion_token = "Deletion Token:".colorize("bold yellow"); + + let labels = vec![ + (label_url, url), + (label_file_id, file_identifier), + (label_deletion_token, deletion_token), + ]; + + let title_width = measure_text_width(&title); + let max_line_width = labels + .iter() + .map(|(label, content)| measure_text_width(&format!("{} {}", label, content))) + .max() + .unwrap_or(0); + + let box_width = max_line_width.max(title_width) + 2; + + println!("\n{}", format!("┌{}┐", "─".repeat(box_width))); + + let padded_title = pad_str(&title, box_width, Alignment::Center, None); + println!("│{}│", padded_title); + + println!("{}", format!("├{}┤", "─".repeat(box_width))); + + for (label, content) in labels { + let combined = format!("{} {}", label, content); + let line_padded = pad_str(&combined, box_width - 2, Alignment::Left, None); + println!("│ {} │", line_padded); + } + + println!("{}", format!("└{}┘", "─".repeat(box_width))); + println!(); } + Err(e) => eprintln!("{}", format!("Error: {}", e).colorize("bold red")), }