diff options
author | Caleb Bassi <calebjbassi@gmail.com> | 2019-01-31 01:06:26 -0800 |
---|---|---|
committer | Caleb Bassi <calebjbassi@gmail.com> | 2019-01-31 08:29:22 -0800 |
commit | 2328c56d103f76f212261701be7fbb3d363994e5 (patch) | |
tree | f5cdbd136c2d63b58ed6a6462277edaa4a9191d7 | |
parent | 065ea17795144d91d475664e7a352b79530cb5d9 (diff) |
Add tilde_in_titlebar option
-rw-r--r-- | config/joshuto.toml | 2 | ||||
-rw-r--r-- | src/joshuto/command/cursor_move.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/delete_file.rs | 2 | ||||
-rw-r--r-- | src/joshuto/config/config.rs | 6 | ||||
-rw-r--r-- | src/joshuto/tab.rs | 15 |
5 files changed, 20 insertions, 7 deletions
diff --git a/config/joshuto.toml b/config/joshuto.toml index 5d7db60..4aefd07 100644 --- a/config/joshuto.toml +++ b/config/joshuto.toml @@ -2,6 +2,8 @@ ## currently only supports: natural, mtime sort_type = "natural" +tilde_in_titlebar = true + [sort_option] show_hidden = false case_sensitive = false diff --git a/src/joshuto/command/cursor_move.rs b/src/joshuto/command/cursor_move.rs index e08638a..c449594 100644 --- a/src/joshuto/command/cursor_move.rs +++ b/src/joshuto/command/cursor_move.rs @@ -47,7 +47,7 @@ impl CursorMove { } curr_tab.refresh_curr(&context.views.mid_win, context.config_t.scroll_offset); curr_tab.refresh_file_status(&context.views.bot_win); - curr_tab.refresh_path_status(&context.views.top_win, &context.username, &context.hostname); + curr_tab.refresh_path_status(&context.views.top_win, &context.username, &context.hostname, context.config_t.tilde_in_titlebar); } preview::preview_file(context); ncurses::doupdate(); diff --git a/src/joshuto/command/delete_file.rs b/src/joshuto/command/delete_file.rs index 0a7afca..c3a7ddf 100644 --- a/src/joshuto/command/delete_file.rs +++ b/src/joshuto/command/delete_file.rs @@ -65,7 +65,7 @@ impl JoshutoRunnable for DeleteFiles { let curr_tab = &context.tabs[context.curr_tab_index]; curr_tab.refresh_file_status(&context.views.bot_win); curr_tab.refresh_path_status(&context.views.top_win, - &context.username, &context.hostname); + &context.username, &context.hostname, context.config_t.tilde_in_titlebar); } ncurses::doupdate(); } diff --git a/src/joshuto/config/config.rs b/src/joshuto/config/config.rs index 793bb06..a581ca6 100644 --- a/src/joshuto/config/config.rs +++ b/src/joshuto/config/config.rs @@ -17,6 +17,7 @@ pub struct SortRawOption { #[derive(Clone, Debug, Deserialize)] pub struct JoshutoRawConfig { scroll_offset: Option<usize>, + tilde_in_titlebar: Option<bool>, sort_type: Option<String>, sort_option: Option<SortRawOption>, column_ratio: Option<[usize; 3]>, @@ -28,6 +29,7 @@ impl JoshutoRawConfig { { JoshutoRawConfig { scroll_offset: Some(8), + tilde_in_titlebar: Some(true), sort_type: Some(String::from("natural")), sort_option: None, column_ratio: Some([1, 3, 4]), @@ -44,6 +46,7 @@ impl Flattenable<JoshutoConfig> for JoshutoRawConfig { }; let scroll_offset: usize = self.scroll_offset.unwrap_or(6); + let tilde_in_titlebar: bool = self.tilde_in_titlebar.unwrap_or(true); let show_hidden: bool; let case_sensitive: bool; @@ -85,6 +88,7 @@ impl Flattenable<JoshutoConfig> for JoshutoRawConfig { JoshutoConfig { scroll_offset, + tilde_in_titlebar, sort_type, column_ratio, } @@ -94,6 +98,7 @@ impl Flattenable<JoshutoConfig> for JoshutoRawConfig { #[derive(Debug, Clone)] pub struct JoshutoConfig { pub scroll_offset: usize, + pub tilde_in_titlebar: bool, pub sort_type: joshuto::sort::SortType, pub column_ratio: (usize, usize, usize), } @@ -112,6 +117,7 @@ impl JoshutoConfig { JoshutoConfig { scroll_offset: 6, + tilde_in_titlebar: true, sort_type, column_ratio: (1, 3, 4), } diff --git a/src/joshuto/tab.rs b/src/joshuto/tab.rs index 07c4e82..94217b4 100644 --- a/src/joshuto/tab.rs +++ b/src/joshuto/tab.rs @@ -70,15 +70,15 @@ impl JoshutoTab { pub fn refresh(&mut self, views: &JoshutoView, config_t: &config::JoshutoConfig, username: &str, hostname: &str) { - self.refresh_(views, config_t.scroll_offset, username, hostname); + self.refresh_(views, config_t.tilde_in_titlebar, config_t.scroll_offset, username, hostname); } - pub fn refresh_(&mut self, views: &JoshutoView, scroll_offset: usize, + pub fn refresh_(&mut self, views: &JoshutoView, tilde_in_titlebar: bool, scroll_offset: usize, username: &str, hostname: &str) { self.refresh_curr(&views.mid_win, scroll_offset); self.refresh_parent(&views.left_win, scroll_offset); - self.refresh_path_status(&views.top_win, username, hostname); + self.refresh_path_status(&views.top_win, username, hostname, tilde_in_titlebar); self.refresh_file_status(&views.bot_win); } @@ -115,7 +115,7 @@ impl JoshutoTab { } } - pub fn refresh_path_status(&self, win: &JoshutoPanel, username: &str, hostname: &str) + pub fn refresh_path_status(&self, win: &JoshutoPanel, username: &str, hostname: &str, tilde_in_titlebar: bool) { let path_str: &str = self.curr_path.to_str().unwrap(); @@ -128,7 +128,12 @@ impl JoshutoTab { ncurses::waddstr(win.win, " "); ncurses::wattron(win.win, ncurses::COLOR_PAIR(theme_t.directory.colorpair)); - ncurses::waddstr(win.win, path_str); + if tilde_in_titlebar { + let path_str = &path_str.replace(&format!("/home/{}", username), "~"); + ncurses::waddstr(win.win, path_str); + } else { + ncurses::waddstr(win.win, path_str); + } ncurses::waddstr(win.win, "/"); ncurses::wattroff(win.win, ncurses::COLOR_PAIR(theme_t.directory.colorpair)); if let Some(ref dirlist) = self.curr_list { |