Merge pull request #167 from dyc3/stderr-for-prompts

write input prompts to stderr instead of stdout
This commit is contained in:
Carson McManus 2022-09-08 16:29:10 -04:00 committed by GitHub
commit 8c453585d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View file

@ -111,7 +111,7 @@ fn run() -> anyhow::Result<()> {
if manifest.has_passkey() { if manifest.has_passkey() {
error!("Incorrect passkey"); error!("Incorrect passkey");
} }
passkey = rpassword::prompt_password_stdout("Enter encryption passkey: ").ok(); passkey = rpassword::prompt_password_stderr("Enter encryption passkey: ").ok();
manifest.submit_passkey(passkey); manifest.submit_passkey(passkey);
} }
Err(e) => { Err(e) => {

View file

@ -9,7 +9,7 @@ use crossterm::{
use log::*; use log::*;
use regex::Regex; use regex::Regex;
use std::collections::HashSet; use std::collections::HashSet;
use std::io::{stdout, Write}; use std::io::{stderr, stdout, Write};
use steamguard::Confirmation; use steamguard::Confirmation;
lazy_static! { lazy_static! {
@ -41,7 +41,7 @@ fn test_validate_captcha_text() {
/// Prompt the user for text input. /// Prompt the user for text input.
pub(crate) fn prompt() -> String { pub(crate) fn prompt() -> String {
stdout().flush().unwrap(); stderr().flush().unwrap();
let mut line = String::new(); let mut line = String::new();
while let Event::Key(KeyEvent { code, .. }) = crossterm::event::read().unwrap() { while let Event::Key(KeyEvent { code, .. }) = crossterm::event::read().unwrap() {
@ -60,10 +60,10 @@ pub(crate) fn prompt() -> String {
} }
pub(crate) fn prompt_captcha_text(captcha_gid: &String) -> String { pub(crate) fn prompt_captcha_text(captcha_gid: &String) -> String {
println!("Captcha required. Open this link in your web browser: https://steamcommunity.com/public/captcha.php?gid={}", captcha_gid); eprintln!("Captcha required. Open this link in your web browser: https://steamcommunity.com/public/captcha.php?gid={}", captcha_gid);
let mut captcha_text; let mut captcha_text;
loop { loop {
print!("Enter captcha text: "); eprint!("Enter captcha text: ");
captcha_text = prompt(); captcha_text = prompt();
if captcha_text.len() > 0 && validate_captcha_text(&captcha_text) { if captcha_text.len() > 0 && validate_captcha_text(&captcha_text) {
break; break;
@ -78,8 +78,8 @@ pub(crate) fn prompt_captcha_text(captcha_gid: &String) -> String {
/// `chars` should be all lowercase characters, with at most 1 uppercase character. The uppercase character is the default answer if no answer is provided. /// `chars` should be all lowercase characters, with at most 1 uppercase character. The uppercase character is the default answer if no answer is provided.
pub(crate) fn prompt_char(text: &str, chars: &str) -> char { pub(crate) fn prompt_char(text: &str, chars: &str) -> char {
loop { loop {
let _ = stdout().queue(Print(format!("{} [{}] ", text, chars))); let _ = stderr().queue(Print(format!("{} [{}] ", text, chars)));
let _ = stdout().flush(); let _ = stderr().flush();
let input = prompt(); let input = prompt();
if let Ok(c) = prompt_char_impl(input, chars) { if let Ok(c) = prompt_char_impl(input, chars) {
return c; return c;
@ -273,8 +273,8 @@ pub(crate) fn prompt_confirmation_menu(
} }
pub(crate) fn pause() { pub(crate) fn pause() {
println!("Press any key to continue..."); eprintln!("Press any key to continue...");
let _ = stdout().flush(); let _ = stderr().flush();
loop { loop {
match crossterm::event::read().expect("could not read terminal events") { match crossterm::event::read().expect("could not read terminal events") {
Event::Key(_) => break, Event::Key(_) => break,