summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-02 11:56:25 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-02 11:56:25 -0500
commit3682d2fca58e70c3779f3588bcc0925ddacbbbbd (patch)
tree395f28a0c709610eea707b549fdf00ee27e950df /src
parent8bc73974e78883eb1f619d1829a8be77933e5c00 (diff)
parent0f4d1c5f1ad0b8b1ae5309f2f005601c78df8487 (diff)
Merge branch 'dev'
Diffstat (limited to 'src')
-rw-r--r--src/commands/set_mode.rs67
-rw-r--r--src/context.rs2
-rw-r--r--src/ui/widgets/tui_view.rs24
3 files changed, 61 insertions, 32 deletions
diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs
index 94a6d23..b2c08df 100644
--- a/src/commands/set_mode.rs
+++ b/src/commands/set_mode.rs
@@ -29,27 +29,15 @@ impl SetMode {
"set_mode"
}
- pub fn set_mode(&self, entry: &mut JoshutoDirEntry, initial: String) -> bool {
- use std::os::unix::fs::PermissionsExt;
-
- const PROMPT: &str = ":set_mode ";
- let user_input: Option<String> = None;
-
- 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 as u32;
- mode |= val;
- }
- }
- unix::set_mode(entry.file_path().as_path(), mode);
- entry.metadata.permissions.set_mode(mode + (1 << 15));
- true
+ pub fn str_to_mode(s: &str) -> u32 {
+ 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 as u32;
+ mode |= val;
}
- None => false,
}
+ mode
}
}
@@ -64,17 +52,44 @@ impl std::fmt::Display for SetMode {
impl JoshutoRunnable for SetMode {
fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
use std::os::unix::fs::PermissionsExt;
- let curr_tab = &mut context.tabs[context.curr_tab_index];
- if let Some(curr_list) = curr_tab.curr_list_mut() {
- if let Some(file) = curr_list.get_curr_mut() {
- let mode = file.metadata.permissions.mode();
- let mut mode_string = unix::stringify_mode(mode);
- mode_string.remove(0);
- self.set_mode(file, mode_string);
+ const PREFIX: &'static str = "set_mode ";
+
+ let entry = context
+ .tabs[context.curr_tab_index]
+ .curr_list_ref()
+ .and_then(|x| x.get_curr_ref());
+
+ let user_input = match entry {
+ Some(entry) => {
+ let mode = entry.metadata.permissions.mode();
+ let mode_string = unix::stringify_mode(mode);
+ let mut textfield = TuiTextField::default()
+ .prompt(":")
+ .prefix(PREFIX)
+ .suffix(&mode_string.as_str()[1..]);
+ textfield.get_input(backend, context)
+ }
+ None => None,
+ };
+
+ if let Some(s) = user_input {
+ if s.starts_with(PREFIX) {
+ let s = &s[PREFIX.len()..];
+ let mode = Self::str_to_mode(s);
+
+ let mut entry = context
+ .tabs[context.curr_tab_index]
+ .curr_list_mut()
+ .and_then(|x| x.get_curr_mut())
+ .unwrap();
+
+ unix::set_mode(entry.file_path().as_path(), mode);
+ entry.metadata.permissions.set_mode(mode);
CursorMoveDown::new(1).execute(context, backend)?;
}
}
+
Ok(())
}
}
diff --git a/src/context.rs b/src/context.rs
index 601c1fc..56dcc89 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -13,7 +13,6 @@ pub struct JoshutoContext {
pub curr_tab_index: usize,
pub tabs: Vec<JoshutoTab>,
pub worker_queue: VecDeque<IOWorkerThread>,
- pub trx: (mpsc::SyncSender<u64>, mpsc::Receiver<u64>),
pub worker_msg: Option<String>,
pub message_queue: VecDeque<String>,
@@ -29,7 +28,6 @@ impl JoshutoContext {
curr_tab_index: 0,
tabs: Vec::new(),
worker_queue: VecDeque::with_capacity(10),
- trx: mpsc::sync_channel::<u64>(1),
worker_msg: None,
message_queue: VecDeque::with_capacity(4),
events: Events::new(),
diff --git a/src/ui/widgets/tui_view.rs b/src/ui/widgets/tui_view.rs
index 0f2d64d..9ab7e2c 100644
--- a/src/ui/widgets/tui_view.rs
+++ b/src/ui/widgets/tui_view.rs
@@ -25,14 +25,14 @@ impl<'a> TuiView<'a> {
impl<'a> Widget for TuiView<'a> {
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
+ let f_size = area;
+
let curr_tab = self.context.curr_tab_ref();
let curr_list = curr_tab.curr_list_ref();
let parent_list = curr_tab.parent_list_ref();
let child_list = curr_tab.child_list_ref();
- let f_size = area;
-
let constraints = match child_list {
Some(_) => DEFAULT_LAYOUT,
None => NO_PREVIEW_LAYOUT,
@@ -43,7 +43,23 @@ impl<'a> Widget for TuiView<'a> {
.constraints(constraints.as_ref())
.split(f_size);
- {
+ if self.context.tabs.len() > 1 {
+ let rect = Rect {
+ x: f_size.width - 5,
+ y: 0,
+ width: 5,
+ height: 1,
+ };
+
+ let rect = Rect {
+ x: 0,
+ y: 0,
+ width: f_size.width - 5,
+ height: 1,
+ };
+
+ TuiTopBar::new(curr_tab.curr_path.as_path()).draw(rect, buf);
+ } else {
let rect = Rect {
x: 0,
y: 0,
@@ -52,7 +68,7 @@ impl<'a> Widget for TuiView<'a> {
};
TuiTopBar::new(curr_tab.curr_path.as_path()).draw(rect, buf);
- }
+ }
if let Some(curr_list) = parent_list.as_ref() {
TuiDirList::new(&curr_list).draw(layout_rect[0], buf);