Skip to content

Commit

Permalink
feat: press any key to exit
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleRicardo committed Mar 2, 2024
1 parent 4eaa98a commit c0dbc1e
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
use std::io;
use std::io::{Read, Write};

pub fn pause() {
let mut stdin = io::stdin();
let mut stdout = io::stdout();

// We want the cursor to stay at the end of the line, so we print without a newline and flush manually.
write!(stdout, "按回车键退出 Press enter to exit...").unwrap();
stdout.flush().unwrap();

// Read a single byte and discard
let _ = stdin.read(&mut [0u8]).unwrap();
use std::process::Command;
let _ = Command::new("cmd.exe").arg("/c").arg("pause").status();
}

0 comments on commit c0dbc1e

Please sign in to comment.