From 5e190a9a5dc1d99c38c6151a1cb53360f44dfce9 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 16 Apr 2024 21:07:11 +0000 Subject: [PATCH] CLI: Use qrcode-rs instead of qr2term (#88) --- cli/Cargo.lock | 121 +++----------------------------------------- cli/Cargo.toml | 2 +- cli/src/commands.rs | 20 +++++++- 3 files changed, 26 insertions(+), 117 deletions(-) diff --git a/cli/Cargo.lock b/cli/Cargo.lock index cfce83fcc..cc6da8eb5 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -332,12 +332,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "checked_int_cast" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cc5e6b5ab06331c33589842070416baa137e8b0eb912b008cfd4a78ada7919" - [[package]] name = "cipher" version = "0.3.0" @@ -436,31 +430,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossterm" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" -dependencies = [ - "bitflags 1.3.2", - "crossterm_winapi", - "libc", - "mio", - "parking_lot 0.12.1", - "signal-hook", - "signal-hook-mio", - "winapi", -] - -[[package]] -name = "crossterm_winapi" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" -dependencies = [ - "winapi", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -1134,7 +1103,7 @@ dependencies = [ "env_logger 0.11.3", "log", "ls-sdk", - "qr2term", + "qrcode-rs", "rustyline", "serde", "serde_json", @@ -1267,7 +1236,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", - "log", "wasi", "windows-sys 0.48.0", ] @@ -1392,17 +1360,7 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core 0.8.6", -] - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core 0.9.9", + "parking_lot_core", ] [[package]] @@ -1414,24 +1372,11 @@ dependencies = [ "cfg-if", "instant", "libc", - "redox_syscall 0.2.16", + "redox_syscall", "smallvec", "winapi", ] -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.4.1", - "smallvec", - "windows-targets 0.48.5", -] - [[package]] name = "percent-encoding" version = "2.3.1" @@ -1484,23 +1429,10 @@ dependencies = [ ] [[package]] -name = "qr2term" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2a1e77b5cd714b04247ad912b7c8fe9a1fe1d58425048249def91bcf690e4c" -dependencies = [ - "crossterm", - "qrcode", -] - -[[package]] -name = "qrcode" -version = "0.12.0" +name = "qrcode-rs" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16d2f1455f3630c6e5107b4f2b94e74d76dea80736de0981fd27644216cff57f" -dependencies = [ - "checked_int_cast", -] +checksum = "4680be54420a86f28b3e662bd8f76fd270c1eed5b2e3ebe9e404c12c4ec2b066" [[package]] name = "quick-error" @@ -1566,15 +1498,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "regex" version = "1.10.4" @@ -1961,36 +1884,6 @@ dependencies = [ "digest", ] -[[package]] -name = "signal-hook" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" -dependencies = [ - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-mio" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" -dependencies = [ - "libc", - "mio", - "signal-hook", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -2427,7 +2320,7 @@ checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" dependencies = [ "futures", "js-sys", - "parking_lot 0.11.2", + "parking_lot", "pin-utils", "wasm-bindgen", "wasm-bindgen-futures", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 5ed0f25c7..ec0581392 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -12,7 +12,7 @@ clap = { version = "4.5.1", features = ["derive"] } env_logger = "0.11" log = "0.4.20" ls-sdk = { path = "../lib/ls-sdk-core" } -qr2term = "0.3.1" +qrcode-rs = { version = "0.1", default-features = false } rustyline = { version = "13.0.0", features = ["derive"] } serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 71a7bf55c..23d1ece58 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -6,6 +6,8 @@ use std::time::Duration; use anyhow::Result; use clap::{arg, Parser}; use ls_sdk::{ReceivePaymentRequest, Wallet}; +use qrcode_rs::render::unicode; +use qrcode_rs::{EcLevel, QrCode}; use rustyline::highlight::Highlighter; use rustyline::history::DefaultHistory; use rustyline::Editor; @@ -80,8 +82,13 @@ pub(crate) fn handle_command( invoice_amount_sat, onchain_amount_sat, })?; - qr2term::print_qr(response.invoice.clone())?; - command_result!(response) + + let invoice = response.invoice.clone(); + let mut result = command_result!(response); + result.push('\n'); + result.push_str(&build_qr_text(&invoice)); + + result } Command::SendPayment { bolt11, delay } => { let prepare_response = wallet.prepare_payment(&bolt11)?; @@ -112,3 +119,12 @@ pub(crate) fn handle_command( } }) } + +fn build_qr_text(text: &str) -> String { + QrCode::with_error_correction_level(text, EcLevel::L) + .unwrap() + .render::() + .dark_color(unicode::Dense1x2::Light) + .light_color(unicode::Dense1x2::Dark) + .build() +}