Skip to content

Commit

Permalink
move terminal pause to end of process to prevent automatic close on e…
Browse files Browse the repository at this point in the history
…rror
  • Loading branch information
msmoiz committed Aug 14, 2020
1 parent 8457aca commit c9055a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
11 changes: 4 additions & 7 deletions src/renamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
}

Expand All @@ -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", "");
}
Expand Down Expand Up @@ -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", "");
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c9055a5

Please sign in to comment.