From c9055a5eb0bf978825bf7bb3891671020cc7507a Mon Sep 17 00:00:00 2001 From: Mustafa Date: Fri, 14 Aug 2020 02:02:18 -0700 Subject: [PATCH] move terminal pause to end of process to prevent automatic close on error --- src/main.rs | 5 +++++ src/renamer.rs | 11 ++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index ac985bb..4b78be3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,9 +5,14 @@ mod renamer; use printer::Print; use renamer::Renamer; +use std::io::{stdin, Read}; + fn main() { let mut renamer = Renamer::new(); if let Err(e) = renamer.start() { Print::error(format!("Project rename failed: {}", e)); } + + Print::prompt("Press Enter to exit."); + let _ = stdin().read(&mut [0u8]); } diff --git a/src/renamer.rs b/src/renamer.rs index 4a79b4f..d46cb32 100644 --- a/src/renamer.rs +++ b/src/renamer.rs @@ -3,7 +3,7 @@ use regex::Regex; use serde_json::Value; use std::error::Error; use std::fs::{self}; -use std::io::{self, Read}; +use std::io::{stdin, Read}; use std::path::{Path, PathBuf}; use crate::pathfinder::Pathfinder; @@ -89,9 +89,6 @@ impl Renamer { Print::basic("Project successfully renamed."); Print::newline(); - Print::prompt("Press Enter to exit."); - let _ = io::stdin().read(&mut [0u8])?; - Ok(()) } @@ -100,7 +97,7 @@ impl Renamer { Print::prompt("Project root"); let mut root = String::new(); - match io::stdin().read_line(&mut root) { + match stdin().read_line(&mut root) { Ok(_) => { root = root.replace("\r", "").replace("\n", ""); } @@ -153,7 +150,7 @@ impl Renamer { Print::prompt("Project final name"); let mut final_name = String::new(); - match io::stdin().read_line(&mut final_name) { + match stdin().read_line(&mut final_name) { Ok(_) => { final_name = final_name.replace("\r", "").replace("\n", ""); } @@ -896,7 +893,7 @@ impl Renamer { Print::prompt("[Y]es/[N]o"); let mut buf = String::new(); - io::stdin().read_line(&mut buf)?; + stdin().read_line(&mut buf)?; if let Some(c) = buf.chars().next() { if c == 'y' || c == 'Y' { return Ok(true);