Skip to content

Commit

Permalink
feat(deltachat-repl): built-in QR code printer
Browse files Browse the repository at this point in the history
Print QR codes with Rust code
instead of depending on external `qrencode`.
  • Loading branch information
link2xt committed Oct 15, 2024
1 parent 3a72188 commit f1cbb16
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
39 changes: 39 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions deltachat-repl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ deltachat = { workspace = true, features = ["internals"]}
dirs = "5"
log = { workspace = true }
nu-ansi-term = { workspace = true }
qr2term = "0.3.3"
rusqlite = { workspace = true }
rustyline = "14"
tokio = { workspace = true, features = ["fs", "rt-multi-thread", "macros"] }
Expand Down
9 changes: 1 addition & 8 deletions deltachat-repl/src/cmdline.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#![allow(clippy::format_push_string)]
extern crate dirs;

use std::io::Write;
use std::path::Path;
use std::process::Command;
use std::str::FromStr;
use std::time::Duration;

Expand Down Expand Up @@ -491,12 +489,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
let provider = BackupProvider::prepare(&context).await?;
let qr = format_backup(&provider.qr())?;
println!("QR code: {}", qr);
let output = Command::new("qrencode")
.args(["-t", "ansiutf8", qr.as_str(), "-o", "-"])
.output()
.expect("failed to execute process");
std::io::stdout().write_all(&output.stdout).unwrap();
std::io::stderr().write_all(&output.stderr).unwrap();
qr2term::print_qr(qr.as_str())?;
provider.await?;
}
"receive-backup" => {
Expand Down
9 changes: 1 addition & 8 deletions deltachat-repl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
extern crate deltachat;

use std::borrow::Cow::{self, Borrowed, Owned};
use std::io::{self, Write};
use std::process::Command;

use anyhow::{bail, Error};
use deltachat::chat::ChatId;
Expand Down Expand Up @@ -450,12 +448,7 @@ async fn handle_cmd(
qr.replace_range(12..22, "0000000000")
}
println!("{qr}");
let output = Command::new("qrencode")
.args(["-t", "ansiutf8", qr.as_str(), "-o", "-"])
.output()
.expect("failed to execute process");
io::stdout().write_all(&output.stdout).unwrap();
io::stderr().write_all(&output.stderr).unwrap();
qr2term::print_qr(qr.as_str())?;
}
}
"getqrsvg" => {
Expand Down

0 comments on commit f1cbb16

Please sign in to comment.