diff options
author | Kamiyaa <jeff.no.zhao@gmail.com> | 2020-05-26 17:01:56 -0400 |
---|---|---|
committer | Kamiyaa <jeff.no.zhao@gmail.com> | 2020-05-26 17:01:56 -0400 |
commit | ea79ae00629ffd3ee8991727bb7122bb7e6c8381 (patch) | |
tree | e2ecac79a39d2ad0e64a1cdef44d0524a6532aa0 | |
parent | 0a18ffbf9242f47a7c3a0bb56a9f84804ee7dcf5 (diff) |
open files now pass relative paths instead of full paths
-rw-r--r-- | src/commands/open_file.rs | 4 | ||||
-rw-r--r-- | src/config/mimetype.rs | 7 | ||||
-rw-r--r-- | src/ui/widgets/tui_progress_view.rs | 130 |
3 files changed, 137 insertions, 4 deletions
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index ca07a11..5c3c966 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -73,7 +73,7 @@ impl OpenFile { LoadChild::load_child(context)?; } else if let Some(entries) = selected_entries { let options = Self::get_options(entries[0]); - let entry_paths: Vec<&Path> = entries.iter().map(|e| e.file_path().as_path()).collect(); + let entry_paths: Vec<&str> = entries.iter().map(|e| e.file_name()).collect(); if !options.is_empty() { let res = if options[0].get_fork() { options[0].execute_with(entry_paths.as_slice()) @@ -142,7 +142,7 @@ impl OpenFileWith { .menu(menu_widget); textfield.get_input(backend, &context) }; - let entry_paths: Vec<&Path> = entries.iter().map(|e| e.file_path().as_path()).collect(); + let entry_paths: Vec<&str> = entries.iter().map(|e| e.file_name()).collect(); match user_input.as_ref() { Some(user_input) if user_input.starts_with(PROMPT) => { diff --git a/src/config/mimetype.rs b/src/config/mimetype.rs index 0520d9e..189dd29 100644 --- a/src/config/mimetype.rs +++ b/src/config/mimetype.rs @@ -82,7 +82,10 @@ impl JoshutoMimetypeEntry { self._confirm_exit } - pub fn execute_with(&self, paths: &[&Path]) -> std::io::Result<()> { + pub fn execute_with<I, S>(&self, paths: I) -> std::io::Result<()> + where + I: IntoIterator<Item = S>, + S: AsRef<std::ffi::OsStr>, { let program = String::from(self.get_command()); let mut command = process::Command::new(program); @@ -92,7 +95,7 @@ impl JoshutoMimetypeEntry { } command.args(self.get_args()); - command.args(paths.iter().map(|path| path.as_os_str())); + command.args(paths); let mut handle = command.spawn()?; if !self.get_fork() { diff --git a/src/ui/widgets/tui_progress_view.rs b/src/ui/widgets/tui_progress_view.rs new file mode 100644 index 0000000..9dad78f --- /dev/null +++ b/src/ui/widgets/tui_progress_view.rs @@ -0,0 +1,130 @@ +use tui::buffer::Buffer; +use tui::layout::{Direction, Layout, Rect}; +use tui::style::{Color, Style}; +use tui::widgets::{Paragraph, Text, Widget}; + +use super::{TuiDirList, TuiDirListDetailed, TuiFooter, TuiTabBar, TuiTopBar}; +use crate::context::JoshutoContext; + +const TAB_VIEW_WIDTH: u16 = 15; + +pub struct TuiProgressView<'a> { + pub context: &'a JoshutoContext, +} + +impl<'a> TuiProgressView<'a> { + pub fn new(context: &'a JoshutoContext) -> Self { + Self { + context, + show_bottom_status: true, + } + } +} + +impl<'a> Widget for TuiProgressView<'a> { + fn render(self, area: Rect, buf: &mut Buffer) { + let f_size = area; + + let layout_rect = Layout::default() + .direction(Direction::Horizontal) + .margin(1) + .split(f_size); + + let terminal = backend.terminal_mut(); + + loop { + terminal + .draw(|mut frame| { + }) + .unwrap(); + + if let Ok(event) = context.events.next() { + match event { + Event::IOWorkerProgress(_) => { + + } + Event::Input(key) => { + match key { + Key::Backspace => { + if line_buffer.backspace(1) { + completion_tracker.take(); + } + } + Key::Left => { + if line_buffer.move_backward(1) { + completion_tracker.take(); + } + } + Key::Right => { + if line_buffer.move_forward(1) { + completion_tracker.take(); + } + } + Key::Delete => { + if line_buffer.delete(1).is_some() { + completion_tracker.take(); + } + } + Key::Home => { + line_buffer.move_home(); + completion_tracker.take(); + } + Key::End => { + line_buffer.move_end(); + completion_tracker.take(); + } + Key::Up => {} + Key::Down => {} + Key::Esc => { + return None; + } + Key::Char('\t') => { + if completion_tracker.is_none() { + let res = completer + .complete_path(line_buffer.as_str(), line_buffer.pos()); + if let Ok((pos, mut candidates)) = res { + candidates.sort_by(|x, y| { + x.display() + .partial_cmp(y.display()) + .unwrap_or(std::cmp::Ordering::Less) + }); + let ct = CompletionTracker::new( + pos, + candidates, + String::from(line_buffer.as_str()), + ); + completion_tracker = Some(ct); + } + } + + if let Some(ref mut s) = completion_tracker { + if s.index < s.candidates.len() { + let candidate = &s.candidates[s.index]; + completer.update( + &mut line_buffer, + s.pos, + candidate.display(), + ); + s.index += 1; + } + } + } + Key::Char('\n') => { + break; + } + Key::Char(c) => { + if line_buffer.insert(c, 1).is_some() { + completion_tracker.take(); + } + } + _ => {} + } + context.events.flush(); + } + _ => {} + }; + } + } + + } +} |