-
-
Notifications
You must be signed in to change notification settings - Fork 122
Show QR code image on terminal along with text #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
|
|
@@ -31,6 +32,7 @@ fn main() { | |
| eprintln!("Phone number provided: {}", phone); | ||
| if let Some(ref code) = custom_code { | ||
| eprintln!("Custom pair code: {}", code); | ||
| print_qr_to_terminal(&code); | ||
| } | ||
| eprintln!("Will use pair code authentication (concurrent with QR)"); | ||
| } | ||
|
|
@@ -90,6 +92,7 @@ fn main() { | |
| timeout.as_secs() | ||
| ); | ||
| info!("\n{}\n", code); | ||
| print_qr_to_terminal(&code); | ||
| info!("----------------------------------------"); | ||
|
Comment on lines
+94
to
95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's check the file size to determine how to read it
wc -l src/main.rsRepository: jlucaso1/whatsapp-rust Length of output: 81 🏁 Script executed: # Read the relevant sections - around lines 94-95 (callsite)
sed -n '85,110p' src/main.rsRepository: jlucaso1/whatsapp-rust Length of output: 1504 🏁 Script executed: # Read the function definition around lines 267-272
sed -n '260,280p' src/main.rsRepository: jlucaso1/whatsapp-rust Length of output: 422 🏁 Script executed: # Also check for any other references to print_qr_to_terminal
rg 'print_qr_to_terminal' -n src/main.rsRepository: jlucaso1/whatsapp-rust Length of output: 223 🏁 Script executed: # Check if log/logging is available in the file
head -30 src/main.rs | grep -E "use log|use tracing"Repository: jlucaso1/whatsapp-rust Length of output: 89 🏁 Script executed: # Check imports and see what logging is used in the file
rg "log::|info!|warn!" src/main.rs | head -10Repository: jlucaso1/whatsapp-rust Length of output: 679 Offload QR render/print from async event handling and surface QR generation failures.
Wrap the function body in Suggested change- print_qr_to_terminal(&code);
+ print_qr_to_terminal(&code).await;
@@
- print_qr_to_terminal(&code);
+ print_qr_to_terminal(&code).await;
@@
-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::<unicode::Dense1x2>().build();
-
- // Print to terminal
- println!("{}", qr_string);
- }
+pub async fn print_qr_to_terminal(txt: &str) {
+ let payload = txt.to_owned();
+ let _ = tokio::task::spawn_blocking(move || {
+ match QrCode::new(&payload) {
+ Ok(code) => {
+ let qr_string = code.render::<unicode::Dense1x2>().build();
+ println!("{}", qr_string);
+ }
+ Err(e) => {
+ log::warn!("Failed to generate QR code for terminal output: {}", e);
+ }
+ }
+ })
+ .await;
}🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, if it should be implemented. Need to ask the maintainers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why the fix matters (the concern is valid):
Why the impact is low in practice:
Recommendation for maintainers: Feel free to share this context with the maintainers when asking for their preference! 🧠 Learnings used |
||
| } | ||
| Event::PairingCode { code, timeout } => { | ||
|
|
@@ -100,6 +103,7 @@ fn main() { | |
| info!("> Link with phone number instead"); | ||
| info!(""); | ||
| info!(" >>> {} <<<", code); | ||
| print_qr_to_terminal(&code); | ||
| info!(""); | ||
| info!("========================================"); | ||
| } | ||
|
|
@@ -258,3 +262,14 @@ fn parse_arg(args: &[String], long: &str, short: &str) -> Option<String> { | |
| } | ||
| None | ||
| } | ||
|
|
||
| /// Show QR code on terminal as image. | ||
| pub fn print_qr_to_terminal(txt: &str) { | ||
| let code = QrCode::new(txt).unwrap(); | ||
|
|
||
| // Render QR code as UTF-8 characters for the terminal | ||
| let qr_string = code.render::<unicode::Dense1x2>().build(); | ||
|
|
||
| // Print to terminal | ||
| println!("{}", qr_string); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.