diff --git a/Cargo.lock b/Cargo.lock index fe9b500c1..b18039c19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -209,6 +209,12 @@ version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec" +[[package]] +name = "byteorder-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" + [[package]] name = "bytes" version = "1.11.1" @@ -1183,6 +1189,18 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "image" +version = "0.25.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104" +dependencies = [ + "bytemuck", + "byteorder-lite", + "moxcms", + "num-traits", +] + [[package]] name = "indexmap" version = "2.13.0" @@ -1372,6 +1390,16 @@ dependencies = [ "uuid", ] +[[package]] +name = "moxcms" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b" +dependencies = [ + "num-traits", + "pxfm", +] + [[package]] name = "multimap" version = "0.10.1" @@ -1644,6 +1672,21 @@ dependencies = [ "prost", ] +[[package]] +name = "pxfm" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a041e753da8b807c9255f28de81879c78c876392ff2469cde94799b2896b9d" + +[[package]] +name = "qrcode" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec" +dependencies = [ + "image", +] + [[package]] name = "quote" version = "1.0.45" @@ -2677,6 +2720,7 @@ dependencies = [ "moka", "portable-atomic", "prost", + "qrcode", "rand", "scopeguard", "serde", diff --git a/Cargo.toml b/Cargo.toml index 606c4d03d..000a0b6be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -125,6 +125,7 @@ log = { workspace = true } moka = { version = "0.12.12", features = ["future"], optional = true } portable-atomic = { workspace = true } prost = { workspace = true } +qrcode = "0.14.1" rand = { workspace = true } scopeguard = "1.2" serde = { workspace = true } diff --git a/src/main.rs b/src/main.rs index 9ca14fdaf..8dbc3416e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use chrono::{Local, Utc}; use log::{error, info}; +use qrcode::{QrCode, render::unicode}; use std::sync::Arc; use wacore::proto_helpers::MessageExt; use wacore::types::events::Event; @@ -90,6 +91,7 @@ fn main() { timeout.as_secs() ); info!("\n{}\n", code); + print_qr_to_terminal(&code); info!("----------------------------------------"); } Event::PairingCode { code, timeout } => { @@ -100,6 +102,7 @@ fn main() { info!("> Link with phone number instead"); info!(""); info!(" >>> {} <<<", code); + print_qr_to_terminal(&code); info!(""); info!("========================================"); } @@ -258,3 +261,14 @@ fn parse_arg(args: &[String], long: &str, short: &str) -> Option { } None } + +/// Show QR code on terminal as image. +pub fn print_qr_to_terminal(txt: &str) { + if let Ok(code) = QrCode::new(txt) { + // Render QR code as UTF-8 characters for the terminal + let qr_string = code.render::().build(); + + // Print to terminal + println!("{}", qr_string); + } +} \ No newline at end of file