diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-06-27 13:18:21 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-06-27 13:18:21 -0400 |
commit | 19d59e9290493b8b645abcbe0e4e036b08b750e3 (patch) | |
tree | 5078d742a3709265a8cc39846190492cf59b79db | |
parent | 7a0a027df6b7c81dbb31f0dd3f82dd28479e560f (diff) |
fix confirm_exit not working
-rw-r--r-- | src/commands/bulk_rename.rs | 14 | ||||
-rw-r--r-- | src/config/general/app.rs | 2 | ||||
-rw-r--r-- | src/util/process.rs | 15 |
3 files changed, 23 insertions, 8 deletions
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs index 096869e..bca4c9f 100644 --- a/src/commands/bulk_rename.rs +++ b/src/commands/bulk_rename.rs @@ -9,24 +9,26 @@ use rand::Rng; use crate::context::AppContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; use crate::ui::TuiBackend; +use crate::util::process::wait_for_enter; use super::reload; const ENV_TMP_DIR: &str = "TMP_DIR"; const ENV_EDITOR: &str = "EDITOR"; +const FILE_PREFIX: &str = "joshuto-"; +const RAND_STR_LEN: usize = 10; pub fn _bulk_rename(context: &mut AppContext) -> JoshutoResult { let tmp_directory = env::var(ENV_TMP_DIR).unwrap_or_else(|_| "/tmp".to_string()); - const PREFIX: &str = "joshuto-"; let editor = std::env::var(ENV_EDITOR)?; /* generate a random file name to write to */ - let mut rand_str = String::with_capacity(PREFIX.len() + 10); - rand_str.push_str(PREFIX); + let mut rand_str = String::with_capacity(FILE_PREFIX.len() + RAND_STR_LEN); + rand_str.push_str(FILE_PREFIX); rand::thread_rng() .sample_iter(&rand::distributions::Alphanumeric) - .take(10) + .take(RAND_STR_LEN) .for_each(|ch| rand_str.push(ch as char)); /* create this file in a temporary folder */ @@ -112,9 +114,7 @@ pub fn _bulk_rename(context: &mut AppContext) -> JoshutoResult { handle.wait()?; } } - print!("Press ENTER to continue..."); - std::io::stdout().flush()?; - std::io::stdin().read_line(&mut user_input)?; + wait_for_enter()?; std::fs::remove_file(file_path)?; Ok(()) diff --git a/src/config/general/app.rs b/src/config/general/app.rs index 2c78e33..c890259 100644 --- a/src/config/general/app.rs +++ b/src/config/general/app.rs @@ -1,6 +1,6 @@ use super::DEFAULT_CONFIG_FILE_PATH; - use super::app_raw::AppConfigRaw; + use crate::config::option::{DisplayOption, PreviewOption, SortOption, TabOption}; use crate::error::JoshutoResult; diff --git a/src/util/process.rs b/src/util/process.rs index 06e12cd..4bf34fa 100644 --- a/src/util/process.rs +++ b/src/util/process.rs @@ -1,3 +1,4 @@ +use std::io::{self, Write}; use std::process; use std::sync::mpsc; use std::thread; @@ -54,5 +55,19 @@ where command.args(paths); let _ = command.status()?; + + if entry.get_confirm_exit() { + wait_for_enter()?; + } + + Ok(()) +} + +pub fn wait_for_enter() -> io::Result<()> { + print!("===============\nPress ENTER to continue... "); + std::io::stdout().flush()?; + + let mut user_input = String::with_capacity(4); + std::io::stdin().read_line(&mut user_input)?; Ok(()) } |