summaryrefslogtreecommitdiffstats
path: root/src/commands/new_directory.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-05-25 16:56:22 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-05-25 16:56:22 -0400
commit3eef301229181535365f4d969091dee6c77e1b46 (patch)
tree3c45e7ee093dd5d7b76a36eedbad3da3b86242a7 /src/commands/new_directory.rs
parent4de4dde12c7a6ddb28053ad8225c12fad3d7cf9d (diff)
changed the way new directories are handled
- now new directories are handled via the command line because it requires user input almost always
Diffstat (limited to 'src/commands/new_directory.rs')
-rw-r--r--src/commands/new_directory.rs34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs
index 1e951b7..022ebe9 100644
--- a/src/commands/new_directory.rs
+++ b/src/commands/new_directory.rs
@@ -3,16 +3,16 @@ use std::path;
use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
use crate::error::JoshutoError;
-use crate::textfield::JoshutoTextField;
-use crate::ui;
use crate::window::JoshutoView;
#[derive(Clone, Debug)]
-pub struct NewDirectory;
+pub struct NewDirectory {
+ path: path::PathBuf,
+}
impl NewDirectory {
- pub fn new() -> Self {
- NewDirectory
+ pub fn new(path: path::PathBuf) -> Self {
+ NewDirectory { path }
}
pub const fn command() -> &'static str {
"mkdir"
@@ -21,26 +21,10 @@ impl NewDirectory {
fn new_directory(
context: &mut JoshutoContext,
view: &JoshutoView,
+ path: &path::Path,
) -> Result<(), std::io::Error> {
- let (term_rows, term_cols) = ui::getmaxyx();
- const PROMPT: &str = ":mkdir ";
-
- let user_input: Option<String> = {
- let textfield = JoshutoTextField::new(
- 1,
- term_cols,
- (term_rows as usize - 1, 0),
- PROMPT.to_string(),
- );
- textfield.readline()
- };
-
- if let Some(user_input) = user_input {
- let path = path::PathBuf::from(user_input);
-
- std::fs::create_dir_all(&path)?;
- ReloadDirList::reload(context, view)?;
- }
+ std::fs::create_dir_all(path)?;
+ ReloadDirList::reload(context, view)?;
ncurses::doupdate();
Ok(())
}
@@ -60,7 +44,7 @@ impl JoshutoRunnable for NewDirectory {
context: &mut JoshutoContext,
view: &JoshutoView,
) -> Result<(), JoshutoError> {
- match Self::new_directory(context, view) {
+ match Self::new_directory(context, view, self.path.as_path()) {
Ok(_) => Ok(()),
Err(e) => Err(JoshutoError::IO(e)),
}