Skip to content

Commit

Permalink
CLI: Use qrcode-rs instead of qr2term (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
ok300 authored Apr 16, 2024
1 parent 3efbdb9 commit 5e190a9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 117 deletions.
121 changes: 7 additions & 114 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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::<unicode::Dense1x2>()
.dark_color(unicode::Dense1x2::Light)
.light_color(unicode::Dense1x2::Dark)
.build()
}

0 comments on commit 5e190a9

Please sign in to comment.