diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-26 18:28:58 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-26 18:28:58 -0400 |
commit | 829d8b9ff0806ffc2da692f12b9e8a6f5c228aa4 (patch) | |
tree | fb018bafc4c8568d447825e5da3c17263d74466e /src/commands/rename_file.rs | |
parent | 397506b398aa1cc6d03a154ae1792815131f8125 (diff) |
update commands to use new textfield
Diffstat (limited to 'src/commands/rename_file.rs')
-rw-r--r-- | src/commands/rename_file.rs | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs index b4fa83c..558ce74 100644 --- a/src/commands/rename_file.rs +++ b/src/commands/rename_file.rs @@ -32,29 +32,41 @@ impl RenameFile { path: &path::PathBuf, context: &mut JoshutoContext, view: &JoshutoView, - start_str: String, + initial: String, ) -> Result<(), std::io::Error> { const PROMPT: &str = ":rename_file "; let (term_rows, term_cols) = ui::getmaxyx(); let user_input: Option<String> = { - let textfield = JoshutoTextField::new( - 1, - term_cols, - (term_rows as usize - 1, 0), - PROMPT.to_string(), - ); - + let prefix: String; + let suffix: String; match self.method { RenameFileMethod::Append => { - if let Some(ext) = start_str.rfind('.') { - textfield.readline_with_initial((&start_str[0..ext], &start_str[ext..])) + if let Some(ext) = initial.rfind('.') { + prefix = String::from(&initial[0..ext]); + suffix = String::from(&initial[ext..]); } else { - textfield.readline_with_initial((&start_str, "")) + prefix = initial; + suffix = String::new(); } } - RenameFileMethod::Prepend => textfield.readline_with_initial(("", &start_str)), - RenameFileMethod::Overwrite => textfield.readline(), + RenameFileMethod::Prepend => { + prefix = String::new(); + suffix = initial; + } + RenameFileMethod::Overwrite => { + prefix = String::new(); + suffix = String::new(); + } } + let textfield = JoshutoTextField::new( + 1, + term_cols, + (term_rows as usize - 1, 0), + PROMPT.to_string(), + prefix, + suffix, + ); + textfield.readline() }; if let Some(s) = user_input { |