fix prompts sometimes not showing up (again) (#187)
- fix tui::pause only accept enter to continue so it's less confusing - replace unwrap with flush - replace some prints with eprints - make tui::prompt flush stdout and stderr fixes #178
This commit is contained in:
parent
3457f9cb43
commit
4ba0459bb6
4 changed files with 25 additions and 7 deletions
|
@ -103,6 +103,8 @@ impl FromStr for Verbosity {
|
||||||
pub(crate) struct ArgsDebug {
|
pub(crate) struct ArgsDebug {
|
||||||
#[clap(long, help = "Show a text prompt.")]
|
#[clap(long, help = "Show a text prompt.")]
|
||||||
pub demo_prompt: bool,
|
pub demo_prompt: bool,
|
||||||
|
#[clap(long, help = "Show a \"press any key\" prompt.")]
|
||||||
|
pub demo_pause: bool,
|
||||||
#[clap(long, help = "Show a character prompt.")]
|
#[clap(long, help = "Show a character prompt.")]
|
||||||
pub demo_prompt_char: bool,
|
pub demo_prompt_char: bool,
|
||||||
#[clap(long, help = "Show an example confirmation menu using dummy data.")]
|
#[clap(long, help = "Show an example confirmation menu using dummy data.")]
|
||||||
|
|
|
@ -8,6 +8,15 @@ pub fn demo_prompt() {
|
||||||
println!("Result: {}", result);
|
println!("Result: {}", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn demo_pause() {
|
||||||
|
let mut x = 0;
|
||||||
|
loop {
|
||||||
|
tui::pause();
|
||||||
|
x += 1;
|
||||||
|
println!("looped {} times", x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn demo_prompt_char() {
|
pub fn demo_prompt_char() {
|
||||||
println!("Showing prompt");
|
println!("Showing prompt");
|
||||||
let result = tui::prompt_char("Continue?", "yn");
|
let result = tui::prompt_char("Continue?", "yn");
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -222,9 +222,9 @@ fn get_selected_accounts(
|
||||||
|
|
||||||
fn do_login(account: &mut SteamGuardAccount) -> anyhow::Result<()> {
|
fn do_login(account: &mut SteamGuardAccount) -> anyhow::Result<()> {
|
||||||
if account.account_name.len() > 0 {
|
if account.account_name.len() > 0 {
|
||||||
println!("Username: {}", account.account_name);
|
info!("Username: {}", account.account_name);
|
||||||
} else {
|
} else {
|
||||||
print!("Username: ");
|
eprint!("Username: ");
|
||||||
account.account_name = tui::prompt();
|
account.account_name = tui::prompt();
|
||||||
}
|
}
|
||||||
let _ = std::io::stdout().flush();
|
let _ = std::io::stdout().flush();
|
||||||
|
@ -339,6 +339,9 @@ fn do_subcmd_debug(args: cli::ArgsDebug) -> anyhow::Result<()> {
|
||||||
if args.demo_prompt {
|
if args.demo_prompt {
|
||||||
demos::demo_prompt();
|
demos::demo_prompt();
|
||||||
}
|
}
|
||||||
|
if args.demo_pause {
|
||||||
|
demos::demo_pause();
|
||||||
|
}
|
||||||
if args.demo_prompt_char {
|
if args.demo_prompt_char {
|
||||||
demos::demo_prompt_char();
|
demos::demo_prompt_char();
|
||||||
}
|
}
|
||||||
|
@ -358,8 +361,8 @@ fn do_subcmd_setup(
|
||||||
_args: cli::ArgsSetup,
|
_args: cli::ArgsSetup,
|
||||||
manifest: &mut accountmanager::Manifest,
|
manifest: &mut accountmanager::Manifest,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
println!("Log in to the account that you want to link to steamguard-cli");
|
eprintln!("Log in to the account that you want to link to steamguard-cli");
|
||||||
print!("Username: ");
|
eprint!("Username: ");
|
||||||
let username = tui::prompt().to_lowercase();
|
let username = tui::prompt().to_lowercase();
|
||||||
let account_name = username.clone();
|
let account_name = username.clone();
|
||||||
if manifest.account_exists(&username) {
|
if manifest.account_exists(&username) {
|
||||||
|
|
10
src/tui.rs
10
src/tui.rs
|
@ -41,7 +41,8 @@ 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 {
|
||||||
stderr().flush().unwrap();
|
stdout().flush().expect("failed to flush stdout");
|
||||||
|
stderr().flush().expect("failed to flush stderr");
|
||||||
|
|
||||||
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() {
|
||||||
|
@ -273,11 +274,14 @@ pub(crate) fn prompt_confirmation_menu(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn pause() {
|
pub(crate) fn pause() {
|
||||||
eprintln!("Press any key to continue...");
|
let _ = write!(stderr(), "Press enter to continue...");
|
||||||
let _ = stderr().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(KeyEvent {
|
||||||
|
code: KeyCode::Enter,
|
||||||
|
..
|
||||||
|
}) => break,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue