summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-18 09:42:36 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-18 09:42:36 -0400
commit67cbc92b720b12cdaad780bb95a40710f980dfe4 (patch)
tree40a3552a6cb534cc669fe71c9d8ebd1e85073a99
parentbcc4800b3d93ddf46299f568c7acfc1af919e80a (diff)
update view and cursor position after set_mode
-rw-r--r--src/commands/set_mode.rs56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs
index f39cbc3..a79c72e 100644
--- a/src/commands/set_mode.rs
+++ b/src/commands/set_mode.rs
@@ -1,4 +1,4 @@
-use crate::commands::{JoshutoCommand, JoshutoRunnable};
+use crate::commands::{CursorMoveInc, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoError;
use crate::structs::JoshutoDirEntry;
@@ -49,19 +49,21 @@ impl SetMode {
}
ncurses::doupdate();
- if let Some(s) = user_input {
- let mut mode: u32 = 0;
- for (i, ch) in s.chars().enumerate() {
- if ch == LIBC_PERMISSION_VALS[i].1 {
- let val: u32 = LIBC_PERMISSION_VALS[i].0.into();
- mode |= val;
+ match user_input {
+ Some(s) => {
+ let mut mode: u32 = 0;
+ for (i, ch) in s.chars().enumerate() {
+ if ch == LIBC_PERMISSION_VALS[i].1 {
+ let val: u32 = LIBC_PERMISSION_VALS[i].0.into();
+ mode |= val;
+ }
}
- }
- unix::set_mode(entry.path.as_path(), mode);
- entry.metadata.permissions.set_mode(mode + (1 << 15));
- return true;
+ unix::set_mode(entry.path.as_path(), mode);
+ entry.metadata.permissions.set_mode(mode + (1 << 15));
+ true
+ },
+ None => false,
}
- false
}
}
@@ -79,25 +81,21 @@ impl JoshutoRunnable for SetMode {
context: &mut JoshutoContext,
view: &JoshutoView,
) -> Result<(), JoshutoError> {
- let mut ok = false;
- {
- use std::os::unix::fs::PermissionsExt;
- let curr_tab = &mut context.tabs[context.curr_tab_index];
- if let Some(s) = curr_tab.curr_list.as_mut() {
- if let Some(file) = s.get_curr_mut() {
- let mode = file.metadata.permissions.mode();
- let mut mode_string = unix::stringify_mode(mode);
- mode_string.remove(0);
+ use std::os::unix::fs::PermissionsExt;
+ let curr_tab = &mut context.tabs[context.curr_tab_index];
+ if let Some(s) = curr_tab.curr_list.as_mut() {
+ if let Some(file) = s.get_curr_mut() {
+ let mode = file.metadata.permissions.mode();
+ let mut mode_string = unix::stringify_mode(mode);
+ mode_string.remove(0);
- ok = self.set_mode(file, mode_string);
- }
+ self.set_mode(file, mode_string);
+ CursorMoveInc::new(1).execute(context, view)
+ } else {
+ Ok(())
}
+ } else {
+ Ok(())
}
- if ok {
- let curr_tab = &mut context.tabs[context.curr_tab_index];
- curr_tab.refresh_curr(&view.mid_win, context.config_t.scroll_offset);
- curr_tab.refresh_file_status(&view.bot_win);
- }
- Ok(())
}
}