summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-12-15 11:48:20 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-12-15 11:48:20 -0500
commit12eb9eed1aeb4f3045b78dd19ae20d07bfea7de9 (patch)
treea2204b1fbef5f1ed93312f94196ded9a5a8c6ec5 /src
parentf5902708a6e597064482edfc076248a67882b7c5 (diff)
add option to not collapse preview
- add methods to access config_t - add back home dir path shortening option
Diffstat (limited to 'src')
-rw-r--r--src/commands/change_directory.rs2
-rw-r--r--src/commands/cursor_move.rs2
-rw-r--r--src/commands/delete_files.rs2
-rw-r--r--src/commands/new_directory.rs2
-rw-r--r--src/commands/parent_cursor_move.rs2
-rw-r--r--src/commands/reload.rs4
-rw-r--r--src/commands/rename_file.rs2
-rw-r--r--src/commands/show_hidden.rs4
-rw-r--r--src/commands/sort.rs4
-rw-r--r--src/commands/tab_ops.rs4
-rw-r--r--src/config/config.rs9
-rw-r--r--src/context/context.rs14
-rw-r--r--src/run.rs2
-rw-r--r--src/ui/views/tui_folder_view.rs15
-rw-r--r--src/ui/widgets/tui_topbar.rs18
-rw-r--r--src/ui/widgets/tui_worker.rs2
-rw-r--r--src/util/event.rs11
-rw-r--r--src/util/load_child.rs2
-rw-r--r--src/util/worker.rs2
19 files changed, 66 insertions, 37 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index 1094111..e1c1167 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -13,7 +13,7 @@ pub fn cd(path: &path::Path, context: &mut JoshutoContext) -> std::io::Result<()
pub fn change_directories(path: &path::Path, context: &mut JoshutoContext) -> std::io::Result<()> {
cd(path, context)?;
- let sort_options = context.config_t.sort_option.clone();
+ let sort_options = context.config_ref().sort_option.clone();
context
.tab_context_mut()
.curr_tab_mut()
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index bad885f..3b9aeda 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -24,7 +24,7 @@ pub fn cursor_move(new_index: usize, context: &mut JoshutoContext) -> JoshutoRes
// get preview
if let Some(path) = path {
if path.is_dir() {
- let sort_options = context.config_t.sort_option.clone();
+ let sort_options = context.config_ref().sort_option.clone();
context
.tab_context_mut()
.curr_tab_mut()
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index bc070f1..ed73e18 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -77,7 +77,7 @@ pub fn delete_selected_files(
) -> std::io::Result<()> {
delete_files(context, backend)?;
- let options = context.config_t.sort_option.clone();
+ let options = context.config_ref().sort_option.clone();
let curr_path = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf();
for tab in context.tab_context_mut().iter_mut() {
tab.history_mut().reload(&curr_path, &options)?;
diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs
index 2c5fd57..6b17817 100644
--- a/src/commands/new_directory.rs
+++ b/src/commands/new_directory.rs
@@ -7,7 +7,7 @@ use crate::util::load_child::LoadChild;
pub fn new_directory(context: &mut JoshutoContext, p: &path::Path) -> JoshutoResult<()> {
std::fs::create_dir_all(p)?;
- let options = context.config_t.sort_option.clone();
+ let options = context.config_ref().sort_option.clone();
let curr_path = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf();
for tab in context.tab_context_mut().iter_mut() {
tab.history_mut().reload(&curr_path, &options)?;
diff --git a/src/commands/parent_cursor_move.rs b/src/commands/parent_cursor_move.rs
index 87f6d11..9656ad8 100644
--- a/src/commands/parent_cursor_move.rs
+++ b/src/commands/parent_cursor_move.rs
@@ -30,7 +30,7 @@ pub fn parent_cursor_move(new_index: usize, context: &mut JoshutoContext) -> Jos
// get preview
if let Some(path) = path {
if path.is_dir() {
- let sort_options = context.config_t.sort_option.clone();
+ let sort_options = context.config_ref().sort_option.clone();
context
.tab_context_mut()
.curr_tab_mut()
diff --git a/src/commands/reload.rs b/src/commands/reload.rs
index b05d538..fbd17ec 100644
--- a/src/commands/reload.rs
+++ b/src/commands/reload.rs
@@ -3,7 +3,7 @@ use crate::error::JoshutoResult;
use crate::util::load_child::LoadChild;
pub fn soft_reload(index: usize, context: &mut JoshutoContext) -> std::io::Result<()> {
- let sort_option = context.config_t.sort_option.clone();
+ let sort_option = context.config_ref().sort_option.clone();
if let Some(curr_tab) = context.tab_context_mut().tab_mut(index) {
if let Some(curr_list) = curr_tab.curr_list_mut() {
if curr_list.need_update() {
@@ -25,7 +25,7 @@ pub fn soft_reload(index: usize, context: &mut JoshutoContext) -> std::io::Resul
}
pub fn reload(context: &mut JoshutoContext, index: usize) -> std::io::Result<()> {
- let sort_option = context.config_t.sort_option.clone();
+ let sort_option = context.config_ref().sort_option.clone();
if let Some(curr_tab) = context.tab_context_mut().tab_mut(index) {
if let Some(curr_list) = curr_tab.curr_list_mut() {
curr_list.reload_contents(&sort_option)?;
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index 593df97..790068b 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -18,7 +18,7 @@ pub fn _rename_file(
return Err(err);
}
std::fs::rename(&src, &dest)?;
- let options = context.config_t.sort_option.clone();
+ let options = context.config_ref().sort_option.clone();
if let Some(curr_list) = context.tab_context_mut().curr_tab_mut().curr_list_mut() {
curr_list.reload_contents(&options)?;
}
diff --git a/src/commands/show_hidden.rs b/src/commands/show_hidden.rs
index aabc000..f2c9c02 100644
--- a/src/commands/show_hidden.rs
+++ b/src/commands/show_hidden.rs
@@ -5,8 +5,8 @@ use crate::history::DirectoryHistory;
use super::reload;
pub fn _toggle_hidden(context: &mut JoshutoContext) {
- let opposite = !context.config_t.sort_option.show_hidden;
- context.config_t.sort_option.show_hidden = opposite;
+ let opposite = !context.config_ref().sort_option.show_hidden;
+ context.config_mut().sort_option.show_hidden = opposite;
for tab in context.tab_context_mut().iter_mut() {
tab.history_mut().depreciate_all_entries();
diff --git a/src/commands/sort.rs b/src/commands/sort.rs
index e44280e..dff0fd3 100644
--- a/src/commands/sort.rs
+++ b/src/commands/sort.rs
@@ -8,7 +8,7 @@ use crate::util::sort::SortType;
use super::reload;
pub fn set_sort(context: &mut JoshutoContext, method: SortType) -> JoshutoResult<()> {
- context.config_t.sort_option.sort_method = method;
+ context.config_mut().sort_option.sort_method = method;
for tab in context.tab_context_mut().iter_mut() {
tab.history_mut().depreciate_all_entries();
}
@@ -18,7 +18,7 @@ pub fn set_sort(context: &mut JoshutoContext, method: SortType) -> JoshutoResult
}
pub fn toggle_reverse(context: &mut JoshutoContext) -> JoshutoResult<()> {
- context.config_t.sort_option.reverse = !context.config_t.sort_option.reverse;
+ context.config_mut().sort_option.reverse = !context.config_ref().sort_option.reverse;
for tab in context.tab_context_mut().iter_mut() {
tab.history_mut().depreciate_all_entries();
}
diff --git a/src/commands/tab_ops.rs b/src/commands/tab_ops.rs
index a5789cf..a1815a4 100644
--- a/src/commands/tab_ops.rs
+++ b/src/commands/tab_ops.rs
@@ -15,7 +15,7 @@ fn _tab_switch(new_index: usize, context: &mut JoshutoContext) -> std::io::Resul
let path = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf();
std::env::set_current_dir(path.as_path())?;
- let options = context.config_t.sort_option.clone();
+ let options = context.config_ref().sort_option.clone();
context
.tab_context_mut()
.curr_tab_mut()
@@ -39,7 +39,7 @@ pub fn new_tab(context: &mut JoshutoContext) -> JoshutoResult<()> {
None => path::PathBuf::from("/"),
};
- let tab = JoshutoTab::new(curr_path, &context.config_t.sort_option)?;
+ let tab = JoshutoTab::new(curr_path, &context.config_ref().sort_option)?;
context.tab_context_mut().push_tab(tab);
let new_index = context.tab_context_ref().len() - 1;
context.tab_context_mut().set_index(new_index);
diff --git a/src/config/config.rs b/src/config/config.rs
index 8b63c60..c4a3fcc 100644
--- a/src/config/config.rs
+++ b/src/config/config.rs
@@ -65,6 +65,8 @@ pub struct JoshutoRawConfig {
tilde_in_titlebar: bool,
#[serde(default = "default_true")]
show_preview: bool,
+ #[serde(default = "default_true")]
+ collapse_preview: bool,
#[serde(default)]
xdg_open: bool,
#[serde(default = "default_max_preview_size")]
@@ -95,6 +97,7 @@ impl Flattenable<JoshutoConfig> for JoshutoRawConfig {
scroll_offset: self.scroll_offset,
tilde_in_titlebar: self.tilde_in_titlebar,
show_preview: self.show_preview,
+ collapse_preview: self.collapse_preview,
xdg_open: self.xdg_open,
max_preview_size: self.max_preview_size,
column_ratio,
@@ -108,6 +111,7 @@ pub struct JoshutoConfig {
pub scroll_offset: usize,
pub tilde_in_titlebar: bool,
pub show_preview: bool,
+ pub collapse_preview: bool,
pub xdg_open: bool,
pub max_preview_size: u64,
pub sort_option: sort::SortOption,
@@ -127,8 +131,9 @@ impl std::default::Default for JoshutoConfig {
Self {
scroll_offset: default_scroll_offset(),
- tilde_in_titlebar: default_true(),
- show_preview: default_true(),
+ tilde_in_titlebar: true,
+ show_preview: true,
+ collapse_preview: true,
xdg_open: false,
max_preview_size: default_max_preview_size(),
sort_option,
diff --git a/src/context/context.rs b/src/context/context.rs
index 520f77c..95c9d1d 100644
--- a/src/context/context.rs
+++ b/src/context/context.rs
@@ -10,7 +10,7 @@ use crate::util::event::{Event, Events};
pub struct JoshutoContext {
pub exit: bool,
- pub config_t: config::JoshutoConfig,
+ config: config::JoshutoConfig,
events: Events,
tab_context: TabContext,
local_state: Option<LocalStateContext>,
@@ -21,7 +21,7 @@ pub struct JoshutoContext {
}
impl JoshutoContext {
- pub fn new(config_t: config::JoshutoConfig) -> Self {
+ pub fn new(config: config::JoshutoConfig) -> Self {
Self {
exit: false,
events: Events::new(),
@@ -31,10 +31,18 @@ impl JoshutoContext {
message_queue: VecDeque::with_capacity(4),
worker_queue: VecDeque::new(),
worker: None,
- config_t,
+ config,
}
}
+ pub fn config_ref(&self) -> &config::JoshutoConfig {
+ &self.config
+ }
+
+ pub fn config_mut(&mut self) -> &mut config::JoshutoConfig {
+ &mut self.config
+ }
+
pub fn tab_context_ref(&self) -> &TabContext {
&self.tab_context
}
diff --git a/src/run.rs b/src/run.rs
index 496175e..9549bf1 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -16,7 +16,7 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io:
let curr_path = std::env::current_dir()?;
{
// Initialize an initial tab
- let tab = JoshutoTab::new(curr_path, &context.config_t.sort_option)?;
+ let tab = JoshutoTab::new(curr_path, &context.config_ref().sort_option)?;
context.tab_context_mut().push_tab(tab);
// trigger a preview of child
diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs
index 83af048..55966ef 100644
--- a/src/ui/views/tui_folder_view.rs
+++ b/src/ui/views/tui_folder_view.rs
@@ -35,10 +35,15 @@ impl<'a> Widget for TuiFolderView<'a> {
let parent_list = curr_tab.parent_list_ref();
let child_list = curr_tab.child_list_ref();
- let constraints = match child_list {
- Some(_) => DEFAULT_LAYOUT,
- None => NO_PREVIEW_LAYOUT,
+ let constraints = if !self.context.config_ref().collapse_preview {
+ DEFAULT_LAYOUT
+ } else {
+ match child_list {
+ Some(_) => DEFAULT_LAYOUT,
+ None => NO_PREVIEW_LAYOUT,
+ }
};
+
let layout_rect = Layout::default()
.direction(Direction::Horizontal)
.vertical_margin(1)
@@ -59,7 +64,7 @@ impl<'a> Widget for TuiFolderView<'a> {
width: topbar_width,
height: 1,
};
- TuiTopBar::new(curr_tab.pwd()).render(rect, buf);
+ TuiTopBar::new(self.context, curr_tab.pwd()).render(rect, buf);
let rect = Rect {
x: topbar_width,
@@ -87,7 +92,7 @@ impl<'a> Widget for TuiFolderView<'a> {
width: topbar_width,
height: 1,
};
- TuiTopBar::new(curr_tab.pwd()).render(rect, buf);
+ TuiTopBar::new(self.context, curr_tab.pwd()).render(rect, buf);
}
// render parent view
diff --git a/src/ui/widgets/tui_topbar.rs b/src/ui/widgets/tui_topbar.rs
index be35c7f..0b9c7e8 100644
--- a/src/ui/widgets/tui_topbar.rs
+++ b/src/ui/widgets/tui_topbar.rs
@@ -6,15 +6,17 @@ use tui::style::{Color, Modifier, Style};
use tui::text::{Span, Spans};
use tui::widgets::{Paragraph, Widget};
-use crate::{HOSTNAME, USERNAME};
+use crate::context::JoshutoContext;
+use crate::{HOME_DIR, HOSTNAME, USERNAME};
pub struct TuiTopBar<'a> {
+ pub context: &'a JoshutoContext,
path: &'a Path,
}
impl<'a> TuiTopBar<'a> {
- pub fn new(path: &'a Path) -> Self {
- Self { path }
+ pub fn new(context: &'a JoshutoContext, path: &'a Path) -> Self {
+ Self { context, path }
}
}
@@ -29,17 +31,23 @@ impl<'a> Widget for TuiTopBar<'a> {
.add_modifier(Modifier::BOLD);
let mut ellipses = None;
- let mut curr_path_str = self.path.to_string_lossy();
+ let mut curr_path_str = self.path.to_string_lossy().into_owned();
if curr_path_str.len() > area.width as usize {
match self.path.file_name() {
Some(s) => {
- curr_path_str = s.to_string_lossy();
+ curr_path_str = s.to_string_lossy().into_owned();
ellipses = Some(Span::styled("…", path_style));
}
None => {}
}
}
+ if self.context.config_ref().tilde_in_titlebar {
+ if let Some(home_dir) = HOME_DIR.as_ref() {
+ let home_dir_str = home_dir.to_string_lossy().into_owned();
+ curr_path_str = curr_path_str.replace(&home_dir_str, "~");
+ }
+ }
let text = match ellipses {
Some(s) => Spans::from(vec![
diff --git a/src/ui/widgets/tui_worker.rs b/src/ui/widgets/tui_worker.rs
index 68abee0..24f5fdf 100644
--- a/src/ui/widgets/tui_worker.rs
+++ b/src/ui/widgets/tui_worker.rs
@@ -30,7 +30,7 @@ impl<'a> Widget for TuiWorker<'a> {
width: topbar_width,
height: 1,
};
- TuiTopBar::new(curr_tab.pwd()).render(rect, buf);
+ TuiTopBar::new(self.context, curr_tab.pwd()).render(rect, buf);
match self.context.worker_ref() {
Some(io_obs) => {
diff --git a/src/util/event.rs b/src/util/event.rs
index 3d89503..9e7f120 100644
--- a/src/util/event.rs
+++ b/src/util/event.rs
@@ -12,6 +12,7 @@ pub enum Event {
Input(Key),
IOWorkerProgress(IOWorkerProgress),
IOWorkerResult(io::Result<IOWorkerProgress>),
+ // Filesystem(notify::Result),
}
#[derive(Debug, Clone, Copy)]
@@ -29,7 +30,7 @@ pub struct Events {
pub event_tx: mpsc::Sender<Event>,
event_rx: mpsc::Receiver<Event>,
pub input_tx: mpsc::SyncSender<()>,
- // fileio_handle: thread::JoinHandle<()>,
+ fileio_handle: thread::JoinHandle<()>,
}
impl Events {
@@ -42,7 +43,8 @@ impl Events {
let (event_tx, event_rx) = mpsc::channel();
let event_tx2 = event_tx.clone();
- thread::spawn(move || {
+
+ let fileio_handle = thread::spawn(move || {
let stdin = io::stdin();
let mut keys = stdin.keys();
match keys.next() {
@@ -53,9 +55,9 @@ impl Events {
return;
}
}
- _ => return,
+ Err(_) => return,
},
- _ => return,
+ None => return,
}
while input_rx.recv().is_ok() {
@@ -74,6 +76,7 @@ impl Events {
event_tx,
event_rx,
input_tx,
+ fileio_handle,
}
}
diff --git a/src/util/load_child.rs b/src/util/load_child.rs
index 4d293fc..7d3482c 100644
--- a/src/util/load_child.rs
+++ b/src/util/load_child.rs
@@ -18,7 +18,7 @@ impl LoadChild {
// get preview
if let Some(path) = path {
if path.is_dir() {
- let options = context.config_t.sort_option.clone();
+ let options = context.config_ref().sort_option.clone();
context
.tab_context_mut()
.curr_tab_mut()
diff --git a/src/util/worker.rs b/src/util/worker.rs
index bd062c9..3844a3e 100644
--- a/src/util/worker.rs
+++ b/src/util/worker.rs
@@ -14,7 +14,7 @@ pub fn process_finished_worker(
res: std::io::Result<IOWorkerProgress>,
) {
let observer = context.remove_job().unwrap();
- let options = context.config_t.sort_option.clone();
+ let options = context.config_ref().sort_option.clone();
for tab in context.tab_context_mut().iter_mut() {
let _ = tab.history_mut().reload(observer.dest_path(), &options);
let _ = tab.history_mut().reload(observer.src_path(), &options);