summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2022-08-31 11:11:06 -0400
committerGitHub <noreply@github.com>2022-08-31 11:11:06 -0400
commit0ca4ffd657f1a2884ca8422be8a78baa42f00de4 (patch)
tree408c91b138707942b4c7736893e4ecbefbe9a544
parentcd838711107303e4c6076df5bc38b2b74c819480 (diff)
use hashmap and uuid to store tabs (#194)
This is preliminary changes in order to track preview threads and progress. The current setup is we just kick off a new thread to load the given directory whenever we see the directory content does not exist in history. We don't track these threads or which tab these requests came from. When the result is returned, we just assign it to the current tab, instead of the tab that actually initiated the request. By adding uuid, we can now track which tab requested the preview and assign it accordingly. This will also allow us to track the status of the preview, so we can display to the user a loading state, when a directory is taking longer than usual to load. This will also solve the problem of kicking off multiple threads to read the same directory for the same tab. Now these threads can be stored and tracked. - side: fix reload not honouring tab sort options - use tab specific options whenever we need to reload stuff
-rw-r--r--Cargo.lock23
-rw-r--r--Cargo.toml8
-rw-r--r--src/commands/bulk_rename.rs2
-rw-r--r--src/commands/change_directory.rs4
-rw-r--r--src/commands/delete_files.rs12
-rw-r--r--src/commands/flat.rs1
-rw-r--r--src/commands/new_directory.rs8
-rw-r--r--src/commands/open_file.rs2
-rw-r--r--src/commands/reload.rs21
-rw-r--r--src/commands/show_hidden.rs5
-rw-r--r--src/commands/sort.rs2
-rw-r--r--src/commands/sub_process.rs2
-rw-r--r--src/commands/tab_ops.rs10
-rw-r--r--src/context/tab_context.rs57
-rw-r--r--src/event/process_event.rs37
-rw-r--r--src/run.rs5
-rw-r--r--src/tab/homepage.rs6
-rw-r--r--src/tab/mod.rs5
-rw-r--r--src/tab/tab_struct.rs (renamed from src/tab.rs)15
-rw-r--r--src/ui/views/tui_folder_view.rs9
-rw-r--r--src/ui/views/tui_hsplit_view.rs8
21 files changed, 142 insertions, 100 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1e05895..8e88d11 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -392,6 +392,7 @@ dependencies = [
"unicode-segmentation",
"unicode-width",
"users",
+ "uuid",
"walkdir",
"whoami",
"xdg",
@@ -1103,6 +1104,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
[[package]]
+name = "uuid"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f"
+dependencies = [
+ "getrandom",
+ "rand",
+ "uuid-macro-internal",
+]
+
+[[package]]
+name = "uuid-macro-internal"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "548f7181a5990efa50237abb7ebca410828b57a8955993334679f8b50b35c97d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 3a5bf93..c13d362 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -41,6 +41,14 @@ whoami = "^1"
xdg = "^2"
walkdir = "^2"
+[dependencies.uuid]
+version = "^1"
+features = [
+ "v4",
+ "fast-rng",
+ "macro-diagnostics",
+]
+
[features]
devicons = [ "phf" ]
file_mimetype = []
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs
index 3a94f11..b98b0d4 100644
--- a/src/commands/bulk_rename.rs
+++ b/src/commands/bulk_rename.rs
@@ -127,6 +127,6 @@ pub fn bulk_rename(context: &mut AppContext, backend: &mut AppBackend) -> Joshut
backend.terminal_drop();
let res = _bulk_rename(context);
backend.terminal_restore()?;
- reload::reload(context, context.tab_context_ref().index)?;
+ reload::soft_reload_curr_tab(context)?;
res
}
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index bc88afb..b612d34 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -51,7 +51,7 @@ pub fn parent_directory(context: &mut AppContext) -> JoshutoResult {
.tab_context_mut()
.curr_tab_mut()
.set_cwd(parent.as_path());
- reload::soft_reload(context.tab_context_ref().index, context)?;
+ reload::soft_reload_curr_tab(context)?;
}
Ok(())
}
@@ -65,7 +65,7 @@ pub fn previous_directory(context: &mut AppContext) -> JoshutoResult {
.tab_context_mut()
.curr_tab_mut()
.set_cwd(path.as_path());
- reload::soft_reload(context.tab_context_ref().index, context)?;
+ reload::soft_reload_curr_tab(context)?;
}
Ok(())
}
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 59d2b5c..b9eb660 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -80,10 +80,10 @@ fn _delete_selected_files(
let curr_tab = context.tab_context_ref().curr_tab_ref();
let options = context.config_ref().display_options_ref().clone();
let curr_path = curr_tab.cwd().to_path_buf();
- let tab_option = curr_tab.option_ref().clone();
- for tab in context.tab_context_mut().iter_mut() {
+ for (_, tab) in context.tab_context_mut().iter_mut() {
+ let tab_options = tab.option_ref().clone();
tab.history_mut()
- .reload(&curr_path, &options, &tab_option)?;
+ .reload(&curr_path, &options, &tab_options)?;
}
Ok(())
}
@@ -102,10 +102,10 @@ fn _delete_selected_files_background(
let curr_tab = context.tab_context_ref().curr_tab_ref();
let options = context.config_ref().display_options_ref().clone();
let curr_path = curr_tab.cwd().to_path_buf();
- let tab_option = curr_tab.option_ref().clone();
- for tab in context.tab_context_mut().iter_mut() {
+ for (_, tab) in context.tab_context_mut().iter_mut() {
+ let tab_options = tab.option_ref().clone();
tab.history_mut()
- .reload(&curr_path, &options, &tab_option)?;
+ .reload(&curr_path, &options, &tab_options)?;
}
Ok(())
}
diff --git a/src/commands/flat.rs b/src/commands/flat.rs
index b9d0a64..8e40151 100644
--- a/src/commands/flat.rs
+++ b/src/commands/flat.rs
@@ -75,7 +75,6 @@ pub fn flatten(depth: usize, context: &mut AppContext) -> JoshutoResult {
}
let sort_options = tab_options.sort_options_ref();
-
contents.sort_by(|f1, f2| sort_options.compare(f1, f2));
let metadata = JoshutoMetadata::from(path.as_path())?;
diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs
index 482c84e..7fb7190 100644
--- a/src/commands/new_directory.rs
+++ b/src/commands/new_directory.rs
@@ -7,13 +7,9 @@ use crate::history::DirectoryHistory;
pub fn new_directory(context: &mut AppContext, p: &path::Path) -> JoshutoResult {
std::fs::create_dir_all(p)?;
let options = context.config_ref().display_options_ref().clone();
- let tab_options = context
- .tab_context_ref()
- .curr_tab_ref()
- .option_ref()
- .clone();
let curr_path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf();
- for tab in context.tab_context_mut().iter_mut() {
+ for (_, tab) in context.tab_context_mut().iter_mut() {
+ let tab_options = tab.option_ref().clone();
tab.history_mut()
.reload(&curr_path, &options, &tab_options)?;
}
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index 1799f60..030f6ed 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -130,7 +130,7 @@ pub fn open(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult
Some(entry) if entry.file_path().is_dir() => {
let path = entry.file_path().to_path_buf();
change_directory::cd(path.as_path(), context)?;
- reload::soft_reload(context.tab_context_ref().index, context)?;
+ reload::soft_reload_curr_tab(context)?;
}
Some(entry) => {
if context.args.file_chooser {
diff --git a/src/commands/reload.rs b/src/commands/reload.rs
index fa12565..f7197c1 100644
--- a/src/commands/reload.rs
+++ b/src/commands/reload.rs
@@ -2,10 +2,12 @@ use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::history::create_dirlist_with_history;
+use uuid::Uuid;
+
// reload only if we have a queued reload
-pub fn soft_reload(index: usize, context: &mut AppContext) -> std::io::Result<()> {
+pub fn soft_reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> {
let mut paths = Vec::with_capacity(3);
- if let Some(curr_tab) = context.tab_context_ref().tab_ref(index) {
+ if let Some(curr_tab) = context.tab_context_ref().tab_ref(id) {
if let Some(curr_list) = curr_tab.curr_list_ref() {
if curr_list.need_update() {
paths.push(curr_list.file_path().to_path_buf());
@@ -32,7 +34,7 @@ pub fn soft_reload(index: usize, context: &mut AppContext) -> std::io::Result<()
.clone();
if let Some(history) = context
.tab_context_mut()
- .tab_mut(index)
+ .tab_mut(id)
.map(|t| t.history_mut())
{
for path in paths {
@@ -45,9 +47,14 @@ pub fn soft_reload(index: usize, context: &mut AppContext) -> std::io::Result<()
Ok(())
}
-pub fn reload(context: &mut AppContext, index: usize) -> std::io::Result<()> {
+pub fn soft_reload_curr_tab(context: &mut AppContext) -> std::io::Result<()> {
+ let curr_tab_id = context.tab_context_ref().curr_tab_id();
+ soft_reload(context, &curr_tab_id)
+}
+
+pub fn reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> {
let mut paths = Vec::with_capacity(3);
- if let Some(curr_tab) = context.tab_context_ref().tab_ref(index) {
+ if let Some(curr_tab) = context.tab_context_ref().tab_ref(id) {
if let Some(curr_list) = curr_tab.curr_list_ref() {
paths.push(curr_list.file_path().to_path_buf());
}
@@ -68,7 +75,7 @@ pub fn reload(context: &mut AppContext, index: usize) -> std::io::Result<()> {
.clone();
if let Some(history) = context
.tab_context_mut()
- .tab_mut(index)
+ .tab_mut(id)
.map(|t| t.history_mut())
{
for path in paths {
@@ -85,6 +92,6 @@ pub fn reload(context: &mut AppContext, index: usize) -> std::io::Result<()> {
}
pub fn reload_dirlist(context: &mut AppContext) -> JoshutoResult {
- reload(context, context.tab_context_ref().index)?;
+ reload(context, &context.tab_context_ref().curr_tab_id())?;
Ok(())
}
diff --git a/src/commands/show_hidden.rs b/src/commands/show_hidden.rs
index f0c437c..daad000 100644
--- a/src/commands/show_hidden.rs
+++ b/src/commands/show_hidden.rs
@@ -11,7 +11,7 @@ pub fn _toggle_hidden(context: &mut AppContext) {
.display_options_mut()
.set_show_hidden(opposite);
- for tab in context.tab_context_mut().iter_mut() {
+ for (_, tab) in context.tab_context_mut().iter_mut() {
tab.history_mut().depreciate_all_entries();
if let Some(s) = tab.curr_list_mut() {
s.depreciate();
@@ -21,5 +21,6 @@ pub fn _toggle_hidden(context: &mut AppContext) {
pub fn toggle_hidden(context: &mut AppContext) -> JoshutoResult {
_toggle_hidden(context);
- reload::reload_dirlist(context)
+ reload::soft_reload_curr_tab(context)?;
+ Ok(())
}
diff --git a/src/commands/sort.rs b/src/commands/sort.rs
index 51be534..fa350ff 100644
--- a/src/commands/sort.rs
+++ b/src/commands/sort.rs
@@ -24,6 +24,6 @@ pub fn toggle_reverse(context: &mut AppContext) -> JoshutoResult {
}
fn refresh(context: &mut AppContext) -> JoshutoResult {
- reload::soft_reload(context.tab_context_ref().index, context)?;
+ reload::soft_reload_curr_tab(context)?;
Ok(())
}
diff --git a/src/commands/sub_process.rs b/src/commands/sub_process.rs
index e2a33dc..fc31278 100644
--- a/src/commands/sub_process.rs
+++ b/src/commands/sub_process.rs
@@ -55,7 +55,7 @@ pub fn sub_process(
) -> JoshutoResult {
backend.terminal_drop();
let res = execute_sub_process(context, words, spawn);
- reload::soft_reload(context.tab_context_ref().index, context)?;
+ reload::soft_reload_curr_tab(context)?;
context.message_queue_mut().push_info(format!(
"{}: {}",
if spawn { "Spawned" } else { "Finished" },
diff --git a/src/commands/tab_ops.rs b/src/commands/tab_ops.rs
index 2a7f7fb..24a866f 100644
--- a/src/commands/tab_ops.rs
+++ b/src/commands/tab_ops.rs
@@ -1,5 +1,7 @@
use std::path;
+use uuid::Uuid;
+
use crate::context::AppContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::history::DirectoryHistory;
@@ -37,6 +39,7 @@ fn _tab_switch(new_index: usize, context: &mut AppContext) -> std::io::Result<()
.curr_tab_ref()
.option_ref()
.clone();
+
let history = context.tab_context_mut().curr_tab_mut().history_mut();
if history
.create_or_soft_update(cwd.as_path(), &options, &tab_options)
@@ -103,13 +106,13 @@ pub fn new_tab_home_path(context: &AppContext) -> path::PathBuf {
pub fn new_tab(context: &mut AppContext) -> JoshutoResult {
let new_tab_path = new_tab_home_path(context);
-
+ let id = Uuid::new_v4();
let tab = JoshutoTab::new(
new_tab_path,
context.ui_context_ref(),
context.config_ref().display_options_ref(),
)?;
- context.tab_context_mut().push_tab(tab);
+ context.tab_context_mut().insert_tab(id, tab);
let new_index = context.tab_context_ref().len() - 1;
context.tab_context_mut().index = new_index;
_tab_switch(new_index, context)?;
@@ -120,9 +123,10 @@ pub fn close_tab(context: &mut AppContext) -> JoshutoResult {
if context.tab_context_ref().len() <= 1 {
return quit_with_action(context, QuitAction::Noop);
}
+ let curr_tab_id = context.tab_context_ref().curr_tab_id();
let mut tab_index = context.tab_context_ref().index;
- let _ = context.tab_context_mut().pop_tab(tab_index);
+ let _ = context.tab_context_mut().remove_tab(&curr_tab_id);
let num_tabs = context.tab_context_ref().len();
if tab_index >= num_tabs {
tab_index = num_tabs - 1;
diff --git a/src/context/tab_context.rs b/src/context/tab_context.rs
index 77f75a5..1393b06 100644
--- a/src/context/tab_context.rs
+++ b/src/context/tab_context.rs
@@ -1,50 +1,59 @@
-use std::slice::IterMut;
+use std::collections::hash_map::IterMut;
+use std::collections::HashMap;
+
+use uuid::Uuid;
use crate::tab::JoshutoTab;
#[derive(Default)]
pub struct TabContext {
pub index: usize,
- tabs: Vec<JoshutoTab>,
+ pub tab_order: Vec<Uuid>,
+ tabs: HashMap<Uuid, JoshutoTab>,
}
impl TabContext {
pub fn new() -> Self {
Self::default()
}
-
pub fn len(&self) -> usize {
- self.tabs.len()
+ self.tab_order.len()
}
- pub fn tab_ref(&self, i: usize) -> Option<&JoshutoTab> {
- if i >= self.tabs.len() {
- return None;
- }
- Some(&self.tabs[i])
+ pub fn tab_ref(&self, id: &Uuid) -> Option<&JoshutoTab> {
+ self.tabs.get(id)
}
- pub fn tab_mut(&mut self, i: usize) -> Option<&mut JoshutoTab> {
- if i >= self.tabs.len() {
- return None;
- }
- Some(&mut self.tabs[i])
+ pub fn tab_mut(&mut self, id: &Uuid) -> Option<&mut JoshutoTab> {
+ self.tabs.get_mut(id)
}
+ pub fn curr_tab_id(&self) -> Uuid {
+ self.tab_order[self.index]
+ }
pub fn curr_tab_ref(&self) -> &JoshutoTab {
- &self.tabs[self.index]
+ let id = &self.tab_order[self.index];
+ self.tabs.get(id).unwrap()
}
pub fn curr_tab_mut(&mut self) -> &mut JoshutoTab {
- &mut self.tabs[self.index]
- }
- pub fn push_tab(&mut self, tab: JoshutoTab) {
- self.tabs.push(tab);
- self.index = self.tabs.len() - 1;
- }
- pub fn pop_tab(&mut self, index: usize) -> JoshutoTab {
- self.tabs.remove(index)
+ let id = &self.tab_order[self.index];
+ self.tabs.get_mut(id).unwrap()
+ }
+ pub fn insert_tab(&mut self, id: Uuid, tab: JoshutoTab) {
+ self.tabs.insert(id, tab);
+ self.tab_order.push(id);
+ }
+ pub fn remove_tab(&mut self, id: &Uuid) -> Option<JoshutoTab> {
+ let tab = self.tabs.remove(id);
+ for i in 0..self.tab_order.len() {
+ if self.tab_order[i] == *id {
+ self.tab_order.remove(i);
+ break;
+ }
+ }
+ tab
}
- pub fn iter_mut(&mut self) -> IterMut<JoshutoTab> {
+ pub fn iter_mut(&mut self) -> IterMut<Uuid, JoshutoTab> {
self.tabs.iter_mut()
}
}
diff --git a/src/event/process_event.rs b/src/event/process_event.rs
index 0857daa..446b98c 100644
--- a/src/event/process_event.rs
+++ b/src/event/process_event.rs
@@ -70,7 +70,7 @@ pub fn process_noninteractive(event: AppEvent, context: &mut AppContext) {
}
fn process_filesystem_event(_event: notify::Event, context: &mut AppContext) {
- let _ = reload::soft_reload(context.tab_context_ref().index, context);
+ let _ = reload::soft_reload_curr_tab(context);
}
pub fn process_new_worker(context: &mut AppContext) {
@@ -92,28 +92,23 @@ pub fn process_finished_worker(
let worker_context = context.worker_context_mut();
let observer = worker_context.remove_worker().unwrap();
let options = context.config_ref().display_options_ref().clone();
- let tab_options = context
- .tab_context_ref()
- .curr_tab_ref()
- .option_ref()
- .clone();
- for tab in context.tab_context_mut().iter_mut() {
- let _ = tab
- .history_mut()
- .reload(observer.dest_path(), &options, &tab_options);
- let _ = tab
- .history_mut()
- .reload(observer.src_path(), &options, &tab_options);
- }
-
- /* delete
- // remove directory previews
- for tab in context.tab_context_mut().iter_mut() {
- for p in &paths {
- tab.history_mut().remove(p.as_path());
+ for (_, tab) in context.tab_context_mut().iter_mut() {
+ let tab_options = tab.option_ref().clone();
+ if observer.dest_path().exists() {
+ let _ = tab
+ .history_mut()
+ .reload(observer.dest_path(), &options, &tab_options);
+ } else {
+ tab.history_mut().remove(observer.dest_path());
+ }
+ if observer.src_path().exists() {
+ let _ = tab
+ .history_mut()
+ .reload(observer.src_path(), &options, &tab_options);
+ } else {
+ tab.history_mut().remove(observer.src_path());
}
}
- */
observer.join();
match res {
diff --git a/src/run.rs b/src/run.rs
index a2aa497..5f3d396 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -12,6 +12,8 @@ use crate::ui;
use crate::ui::views;
use crate::ui::views::TuiView;
+use uuid::Uuid;
+
use termion::event::{Event, Key};
use tui::layout::Rect;
@@ -28,13 +30,14 @@ pub fn run_loop(
}
{
+ let id = Uuid::new_v4();
// Initialize an initial tab
let tab = JoshutoTab::new(
curr_path,
context.ui_context_ref(),
context.config_ref().display_options_ref(),
)?;
- context.tab_context_mut().push_tab(tab);
+ context.tab_context_mut().insert_tab(id, tab);
// trigger a preview of child
preview_default::load_preview(context);
diff --git a/src/tab/homepage.rs b/src/tab/homepage.rs
new file mode 100644
index 0000000..b762c3b
--- /dev/null
+++ b/src/tab/homepage.rs
@@ -0,0 +1,6 @@
+#[derive(Clone, Copy, Debug)]
+pub enum TabHomePage {
+ Inherit,
+ Home,
+ Root,
+}
diff --git a/src/tab/mod.rs b/src/tab/mod.rs
new file mode 100644
index 0000000..dd7fa2a
--- /dev/null
+++ b/src/tab/mod.rs
@@ -0,0 +1,5 @@
+mod homepage;
+mod tab_struct;
+
+pub use self::homepage::*;
+pub use self::tab_struct::*;
diff --git a/src/tab.rs b/src/tab/tab_struct.rs
index 5a6b63b..b1aee8c 100644
--- a/src/tab.rs
+++ b/src/tab/tab_struct.rs
@@ -5,18 +5,11 @@ use crate::context::UiContext;
use crate::fs::JoshutoDirList;
use crate::history::{DirectoryHistory, JoshutoHistory};
-#[derive(Clone, Copy, Debug)]
-pub enum TabHomePage {
- Inherit,
- Home,
- Root,
-}
-
pub struct JoshutoTab {
- history: JoshutoHistory,
_cwd: path::PathBuf,
// history is just a HashMap, so we have this property to store last workdir
_previous_dir: Option<path::PathBuf>,
+ history: JoshutoHistory,
options: TabDisplayOption,
}
@@ -51,7 +44,6 @@ impl JoshutoTab {
pub fn cwd(&self) -> &path::Path {
self._cwd.as_path()
}
-
pub fn set_cwd(&mut self, cwd: &path::Path) {
self._previous_dir = Some(self._cwd.to_path_buf());
self._cwd = cwd.to_path_buf();
@@ -68,7 +60,6 @@ impl JoshutoTab {
pub fn history_ref(&self) -> &JoshutoHistory {
&self.history
}
-
pub fn history_mut(&mut self) -> &mut JoshutoHistory {
&mut self.history
}
@@ -76,12 +67,10 @@ impl JoshutoTab {
pub fn curr_list_ref(&self) -> Option<&JoshutoDirList> {
self.history.get(self.cwd())
}
-
pub fn parent_list_ref(&self) -> Option<&JoshutoDirList> {
let parent = self.cwd().parent()?;
self.history.get(parent)
}
-
pub fn child_list_ref(&self) -> Option<&JoshutoDirList> {
let curr_list = self.curr_list_ref()?;
let index = curr_list.get_index()?;
@@ -92,12 +81,10 @@ impl JoshutoTab {
pub fn curr_list_mut(&mut self) -> Option<&mut JoshutoDirList> {
self.history.get_mut(self._cwd.as_path())
}
-
pub fn parent_list_mut(&mut self) -> Option<&mut JoshutoDirList> {
let parent = self._cwd.parent()?;
self.history.get_mut(parent)
}
-
#[allow(dead_code)]
pub fn child_list_mut(&mut self) -> Option<&mut JoshutoDirList> {
let child_path = {
diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs
index f19336e..dd5e2e7 100644
--- a/src/ui/views/tui_folder_view.rs
+++ b/src/ui/views/tui_folder_view.rs
@@ -33,6 +33,7 @@ impl<'a> Widget for TuiFolderView<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let preview_context = self.context.preview_context_ref();
let curr_tab = self.context.tab_context_ref().curr_tab_ref();
+ let curr_tab_id = self.context.tab_context_ref().curr_tab_id();
let curr_list = curr_tab.curr_list_ref();
let child_list = curr_tab.child_list_ref();
@@ -180,13 +181,9 @@ impl<'a> Widget for TuiFolderView<'a> {
width: TAB_VIEW_WIDTH,
height: 1,
};
- let name = if let Some(ostr) = curr_tab.cwd().file_name() {
- ostr.to_str().unwrap_or("")
- } else {
- ""
- };
+ let name = curr_tab_id.to_string();
TuiTabBar::new(
- name,
+ &name[..5],
self.context.tab_context_ref().index,
self.context.tab_context_ref().len(),
)
diff --git a/src/ui/views/tui_hsplit_view.rs b/src/ui/views/tui_hsplit_view.rs
index 015ca5a..2c26bd6 100644
--- a/src/ui/views/tui_hsplit_view.rs
+++ b/src/ui/views/tui_hsplit_view.rs
@@ -26,7 +26,6 @@ impl<'a> TuiHSplitView<'a> {
impl<'a> Widget for TuiHSplitView<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let tab_context = self.context.tab_context_ref();
- let tab_index = tab_context.index;
let config = self.context.config_ref();
let display_options = config.display_options_ref();
@@ -66,7 +65,9 @@ impl<'a> Widget for TuiHSplitView<'a> {
calculate_layout(area, constraints)
};
- if let Some(curr_tab) = tab_context.tab_ref(tab_index) {
+ let tab_id = tab_context.curr_tab_id();
+ let tab_index = tab_context.index;
+ if let Some(curr_tab) = tab_context.tab_ref(&tab_id) {
let curr_list = curr_tab.curr_list_ref();
let layout_rect = if tab_index % 2 == 0 {
@@ -143,7 +144,8 @@ impl<'a> Widget for TuiHSplitView<'a> {
tab_index - 1
};
- if let Some(curr_tab) = tab_context.tab_ref(other_tab_index) {
+ let other_tab_id = tab_context.tab_order[other_tab_index];
+ if let Some(curr_tab) = tab_context.tab_ref(&other_tab_id) {
let curr_list = curr_tab.curr_list_ref();
let layout_rect = if other_tab_index % 2 == 0 {