feat: show current dir name in tab

This commit is contained in:
Pig Fang 2023-08-09 17:50:12 +08:00
parent 4823c0abc4
commit 6b65b7a62c
No known key found for this signature in database
GPG key ID: A8198F548DADA9E2
4 changed files with 20 additions and 7 deletions

View file

@ -19,11 +19,18 @@ impl<'a> Widget for Tabs<'a> {
tabs tabs
.iter() .iter()
.enumerate() .enumerate()
.map(|(i, _)| { .map(|(i, tab)| {
let mut text = format!(" {} ", i + 1);
if THEME.tab.max_width > 0 {
text
.push_str(&tab.current_name().chars().take(THEME.tab.max_width).collect::<String>());
text.push(' ');
}
if i == tabs.idx() { if i == tabs.idx() {
Span::styled(format!(" {} ", i + 1), THEME.tab.active.get()) Span::styled(text, THEME.tab.active.get())
} else { } else {
Span::styled(format!(" {} ", i + 1), THEME.tab.inactive.get()) Span::styled(text, THEME.tab.inactive.get())
} }
}) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),

View file

@ -1,6 +1,7 @@
[tab] [tab]
active = { fg = "#1E2031", bg = "#80AEFA" } active = { fg = "#1E2031", bg = "#80AEFA" }
inactive = { fg = "#C8D3F8", bg = "#484D66" } inactive = { fg = "#C8D3F8", bg = "#484D66" }
max_width = 0
[status] [status]
primary = { normal = "#80AEFA", select = "#CD9EFC", unset = "#FFA577" } primary = { normal = "#80AEFA", select = "#CD9EFC", unset = "#FFA577" }

View file

@ -8,8 +8,9 @@ use crate::MERGED_THEME;
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Tab { pub struct Tab {
pub active: Style, pub active: Style,
pub inactive: Style, pub inactive: Style,
pub max_width: usize,
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -270,6 +270,10 @@ impl Tab {
}; };
true true
} }
pub fn current_name(&self) -> &str {
self.current.cwd.file_name().and_then(|name| name.to_str()).unwrap_or_default()
}
} }
impl Tab { impl Tab {