summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-10-15 17:27:47 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-10-15 17:27:47 -0400
commitc0a071f81b2a7a9776dfca313b19ade350c677b2 (patch)
tree9694c95453de122ef02734845f4226c7a6c0818c /src
parent1e18ad1b95397b18af801e5b72eba366abb92fd2 (diff)
deprecate skim over fzf
Diffstat (limited to 'src')
-rw-r--r--src/commands/mod.rs2
-rw-r--r--src/commands/search_fzf.rs66
-rw-r--r--src/commands/search_skim.rs101
-rw-r--r--src/config/general/config.rs3
-rw-r--r--src/key_command/command.rs2
-rw-r--r--src/key_command/constants.rs4
-rw-r--r--src/key_command/impl_appcommand.rs2
-rw-r--r--src/key_command/impl_appexecute.rs2
-rw-r--r--src/key_command/impl_comment.rs2
-rw-r--r--src/key_command/impl_from_str.rs4
-rw-r--r--src/preview/preview_dir.rs1
-rw-r--r--src/preview/preview_file.rs1
-rw-r--r--src/run.rs2
-rw-r--r--src/tab.rs1
-rw-r--r--src/ui/views/tui_textfield.rs6
-rw-r--r--src/ui/widgets/tui_file_preview.rs6
-rw-r--r--src/util/sort_option.rs5
17 files changed, 86 insertions, 124 deletions
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 68ae2e8..454498b 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -13,8 +13,8 @@ pub mod quit;
pub mod reload;
pub mod rename_file;
pub mod search;
+pub mod search_fzf;
pub mod search_glob;
-pub mod search_skim;
pub mod search_string;
pub mod selection;
pub mod set_mode;
diff --git a/src/commands/search_fzf.rs b/src/commands/search_fzf.rs
new file mode 100644
index 0000000..445ce35
--- /dev/null
+++ b/src/commands/search_fzf.rs
@@ -0,0 +1,66 @@
+use std::io;
+use std::io::Write;
+use std::process::{Command, Stdio};
+
+use crate::commands::cursor_move;
+use crate::context::AppContext;
+use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
+use crate::ui::TuiBackend;
+
+pub fn search_fzf(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ let items = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .curr_list_ref()
+ .map(|list| {
+ let v: Vec<String> = list
+ .iter()
+ .enumerate()
+ .map(|(i, entry)| format!("{} {}\n", i, entry.file_name().to_string()))
+ .collect();
+ v
+ })
+ .unwrap_or_else(|| vec![]);
+
+ if items.is_empty() {
+ return Err(JoshutoError::new(
+ JoshutoErrorKind::Io(io::ErrorKind::InvalidData),
+ "no files to select".to_string(),
+ ));
+ }
+
+ backend.terminal_drop();
+
+ let mut fzf = Command::new("fzf")
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .spawn()?;
+
+ match fzf.stdin.as_mut() {
+ Some(fzf_stdin) => {
+ let mut writer = io::BufWriter::new(fzf_stdin);
+ for item in items {
+ writer.write_all(item.as_bytes())?;
+ }
+ }
+ None => {}
+ }
+ let fzf_output = fzf.wait_with_output();
+
+ backend.terminal_restore()?;
+
+ if let Ok(output) = fzf_output {
+ if output.status.success() {
+ if let Ok(selected) = std::str::from_utf8(&output.stdout) {
+ let selected_idx_str = selected.split_once(' ');
+ if let Some((selected_idx_str, _)) = selected_idx_str {
+ if let Ok(index) = selected_idx_str.parse::<usize>() {
+ cursor_move::cursor_move(index, context);
+ }
+ }
+ }
+ }
+ }
+
+ Ok(())
+}
diff --git a/src/commands/search_skim.rs b/src/commands/search_skim.rs
deleted file mode 100644
index 9190587..0000000
--- a/src/commands/search_skim.rs
+++ /dev/null
@@ -1,101 +0,0 @@
-use std::borrow;
-use std::io;
-use std::sync;
-use std::thread;
-
-use skim::prelude::*;
-
-use crate::commands::cursor_move;
-use crate::context::AppContext;
-use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
-use crate::ui::TuiBackend;
-use crate::util::search::SearchPattern;
-
-#[derive(Clone, Debug)]
-pub struct JoshutoSkimItem {
- pub idx: usize,
- pub value: String,
-}
-
-impl SkimItem for JoshutoSkimItem {
- fn text(&self) -> Cow<str> {
- borrow::Cow::Borrowed(self.value.as_str())
- }
-}
-
-pub fn search_skim(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
- let options = SkimOptionsBuilder::default()
- .height(Some("100%"))
- .multi(true)
- .build()
- .unwrap();
-
- let items = context
- .tab_context_ref()
- .curr_tab_ref()
- .curr_list_ref()
- .map(|list| {
- let v: Vec<JoshutoSkimItem> = list
- .iter()
- .enumerate()
- .map(|(i, e)| JoshutoSkimItem {
- idx: i,
- value: e.file_name().to_string(),
- })
- .collect();
- v
- })
- .unwrap_or_else(|| vec![]);
-
- if items.is_empty() {
- return Err(JoshutoError::new(
- JoshutoErrorKind::Io(io::ErrorKind::InvalidData),
- "no files to select".to_string(),
- ));
- }
-
- let (s, r): (SkimItemSender, SkimItemReceiver) = unbounded();
- let thread = thread::spawn(move || {
- for item in items {
- let _ = s.send(sync::Arc::new(item));
- }
- });
-
- backend.terminal_drop();
-
- let skim_output = Skim::run_with(&options, Some(r));
-
- backend.terminal_restore()?;
-
- let _ = thread.join();
-
- if let Some(skim_output) = skim_output {
- if skim_output.final_key == Key::ESC {
- return Ok(());
- }
-
- let query = skim_output.query;
- if !query.is_empty() {
- context.set_search_context(SearchPattern::String(query));
- }
-
- for sk_item in skim_output.selected_items {
- let item: Option<&JoshutoSkimItem> =
- (*sk_item).as_any().downcast_ref::<JoshutoSkimItem>();
-
- match item {
- Some(item) => {
- cursor_move::cursor_move(item.idx, context);
- }
- None => {
- return Err(JoshutoError::new(
- JoshutoErrorKind::Io(io::ErrorKind::InvalidData),
- "Error casting".to_string(),
- ))
- }
- }
- }
- }
-
- Ok(())
-}
diff --git a/src/config/general/config.rs b/src/config/general/config.rs
index dba8dcf..3196017 100644
--- a/src/config/general/config.rs
+++ b/src/config/general/config.rs
@@ -79,9 +79,6 @@ impl AppConfig {
pub fn tab_options_ref(&self) -> &TabOption {
&self._tab_options
}
- pub fn tab_options_mut(&mut self) -> &mut TabOption {
- &mut self._tab_options
- }
}
impl ConfigStructure for AppConfig {
diff --git a/src/key_command/command.rs b/src/key_command/command.rs
index 34e8340..284eb8f 100644
--- a/src/key_command/command.rs
+++ b/src/key_command/command.rs
@@ -47,7 +47,7 @@ pub enum Command {
SearchGlob(String),
SearchString(String),
- SearchSkim,
+ SearchFzf,
SearchNext,
SearchPrev,
diff --git a/src/key_command/constants.rs b/src/key_command/constants.rs
index c9778e6..04b0d4e 100644
--- a/src/key_command/constants.rs
+++ b/src/key_command/constants.rs
@@ -33,11 +33,13 @@ pub const CMD_RELOAD_DIRECTORY_LIST: &str = "reload_dirlist";
pub const CMD_RENAME_FILE: &str = "rename";
pub const CMD_RENAME_FILE_APPEND: &str = "rename_append";
pub const CMD_RENAME_FILE_PREPEND: &str = "rename_prepend";
+
pub const CMD_SEARCH_STRING: &str = "search";
pub const CMD_SEARCH_GLOB: &str = "search_glob";
-pub const CMD_SEARCH_SKIM: &str = "search_skim";
+pub const CMD_SEARCH_FZF: &str = "search_fzf";
pub const CMD_SEARCH_NEXT: &str = "search_next";
pub const CMD_SEARCH_PREV: &str = "search_prev";
+
pub const CMD_SELECT_FILES: &str = "select";
pub const CMD_SET_MODE: &str = "set_mode";
pub const CMD_SORT: &str = "sort";
diff --git a/src/key_command/impl_appcommand.rs b/src/key_command/impl_appcommand.rs
index 329f978..b131a06 100644
--- a/src/key_command/impl_appcommand.rs
+++ b/src/key_command/impl_appcommand.rs
@@ -47,7 +47,7 @@ impl AppCommand for Command {
Self::SearchString(_) => CMD_SEARCH_STRING,
Self::SearchGlob(_) => CMD_SEARCH_GLOB,
- Self::SearchSkim => CMD_SEARCH_SKIM,
+ Self::SearchFzf => CMD_SEARCH_FZF,
Self::SearchNext => CMD_SEARCH_NEXT,
Self::SearchPrev => CMD_SEARCH_PREV,
diff --git a/src/key_command/impl_appexecute.rs b/src/key_command/impl_appexecute.rs
index d678192..74e1517 100644
--- a/src/key_command/impl_appexecute.rs
+++ b/src/key_command/impl_appexecute.rs
@@ -65,7 +65,7 @@ impl AppExecute for Command {
Self::TouchFile(arg) => touch_file::touch_file(context, arg.as_str()),
Self::SearchGlob(pattern) => search_glob::search_glob(context, pattern.as_str()),
Self::SearchString(pattern) => search_string::search_string(context, pattern.as_str()),
- Self::SearchSkim => search_skim::search_skim(context, backend),
+ Self::SearchFzf => search_fzf::search_fzf(context, backend),
Self::SearchNext => search::search_next(context),
Self::SearchPrev => search::search_prev(context),
diff --git a/src/key_command/impl_comment.rs b/src/key_command/impl_comment.rs
index 830cd8c..c6bdd1a 100644
--- a/src/key_command/impl_comment.rs
+++ b/src/key_command/impl_comment.rs
@@ -63,7 +63,7 @@ impl CommandComment for Command {
Self::SearchString(_) => "Search",
Self::SearchGlob(_) => "Search with globbing",
- Self::SearchSkim => "Search via skim",
+ Self::SearchFzf => "Search via fzf",
Self::SearchNext => "Next search entry",
Self::SearchPrev => "Previous search entry",
diff --git a/src/key_command/impl_from_str.rs b/src/key_command/impl_from_str.rs
index c679315..0a27bb8 100644
--- a/src/key_command/impl_from_str.rs
+++ b/src/key_command/impl_from_str.rs
@@ -191,8 +191,8 @@ impl std::str::FromStr for Command {
)),
arg => Ok(Self::SearchGlob(arg.to_string())),
}
- } else if command == CMD_SEARCH_SKIM {
- Ok(Self::SearchSkim)
+ } else if command == CMD_SEARCH_FZF {
+ Ok(Self::SearchFzf)
} else if command == CMD_SEARCH_NEXT {
Ok(Self::SearchNext)
} else if command == CMD_SEARCH_PREV {
diff --git a/src/preview/preview_dir.rs b/src/preview/preview_dir.rs
index 01bf223..957b235 100644
--- a/src/preview/preview_dir.rs
+++ b/src/preview/preview_dir.rs
@@ -7,6 +7,7 @@ use crate::event::AppEvent;
use crate::fs::JoshutoDirList;
use crate::history::DirectoryHistory;
+#[allow(dead_code)]
pub struct Foreground {}
impl Foreground {
diff --git a/src/preview/preview_file.rs b/src/preview/preview_file.rs
index 6ed92a7..6b23a4a 100644
--- a/src/preview/preview_file.rs
+++ b/src/preview/preview_file.rs
@@ -30,6 +30,7 @@ impl std::convert::From<Output> for FilePreview {
}
}
+#[allow(dead_code)]
pub struct Foreground {}
impl Foreground {
diff --git a/src/run.rs b/src/run.rs
index ced61dc..84d8e69 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -84,8 +84,8 @@ pub fn run(
}
},
}
- context.flush_event();
preview_default::load_preview(context, backend);
+ context.flush_event();
}
event => input::process_noninteractive(event, context),
}
diff --git a/src/tab.rs b/src/tab.rs
index fc76ef4..c3f8595 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -65,6 +65,7 @@ impl JoshutoTab {
self.history.get_mut(parent)
}
+ #[allow(dead_code)]
pub fn child_list_mut(&mut self) -> Option<&mut JoshutoDirList> {
let child_path = {
let curr_list = self.curr_list_ref()?;
diff --git a/src/ui/views/tui_textfield.rs b/src/ui/views/tui_textfield.rs
index 348c0f4..d829852 100644
--- a/src/ui/views/tui_textfield.rs
+++ b/src/ui/views/tui_textfield.rs
@@ -16,16 +16,16 @@ use crate::util::input;
struct CompletionTracker {
pub index: usize,
pub pos: usize,
- pub original: String,
+ pub _original: String,
pub candidates: Vec<Pair>,
}
impl CompletionTracker {
- pub fn new(pos: usize, candidates: Vec<Pair>, original: String) -> Self {
+ pub fn new(pos: usize, candidates: Vec<Pair>, _original: String) -> Self {
CompletionTracker {
index: 0,
pos,
- original,
+ _original,
candidates,
}
}
diff --git a/src/ui/widgets/tui_file_preview.rs b/src/ui/widgets/tui_file_preview.rs
index 193ae2d..75e378c 100644
--- a/src/ui/widgets/tui_file_preview.rs
+++ b/src/ui/widgets/tui_file_preview.rs
@@ -7,13 +7,13 @@ use crate::fs::JoshutoDirEntry;
use crate::preview::preview_file::FilePreview;
pub struct TuiFilePreview<'a> {
- entry: &'a JoshutoDirEntry,
+ _entry: &'a JoshutoDirEntry,
preview: &'a FilePreview,
}
impl<'a> TuiFilePreview<'a> {
- pub fn new(entry: &'a JoshutoDirEntry, preview: &'a FilePreview) -> Self {
- Self { entry, preview }
+ pub fn new(_entry: &'a JoshutoDirEntry, preview: &'a FilePreview) -> Self {
+ Self { _entry, preview }
}
}
diff --git a/src/util/sort_option.rs b/src/util/sort_option.rs
index f4fa743..df38702 100644
--- a/src/util/sort_option.rs
+++ b/src/util/sort_option.rs
@@ -1,9 +1,4 @@
use std::cmp;
-use std::collections::VecDeque;
-use std::fs;
-use std::time;
-
-use serde_derive::Deserialize;
use crate::fs::JoshutoDirEntry;
use crate::util::sort_type::{SortType, SortTypes};