From 09117ff7fd17914067f71479da19bfda3ef01736 Mon Sep 17 00:00:00 2001 From: Stefanuk12 <42220813+Stefanuk12@users.noreply.github.com> Date: Mon, 22 Aug 2022 00:21:38 +0100 Subject: [PATCH] Added a better pause --- src/main.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6af6607..feba8f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,20 @@ // Dependencies -use std::{fs, io::{stdin, stdout, Write}}; +use std::{fs, io::{stdin, stdout, Write, Read}}; use platform_dirs::AppDirs; +// Pauses the application until userinput +fn pause() { + let mut stdin = stdin(); + let mut stdout = 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 any key to continue...").unwrap(); + stdout.flush().unwrap(); + + // Read a single byte and discard + let _ = stdin.read(&mut [0u8]).unwrap(); +} + // Path to the installation root dir fn patch(path: String) { // Patching the background file @@ -68,6 +81,6 @@ fn main() { // patch(input_dir.to_string()); - println!("Patched! Press enter to exit."); - stdin(); + println!("Patched!"); + pause(); } \ No newline at end of file