feat: exclude padding

This commit is contained in:
Pig Fang 2023-08-10 18:24:54 +08:00
parent c0bf888247
commit 6e175cfd7d
No known key found for this signature in database
GPG key ID: A8198F548DADA9E2
2 changed files with 7 additions and 9 deletions

View file

@ -23,12 +23,13 @@ impl<'a> Widget for Tabs<'a> {
.iter() .iter()
.enumerate() .enumerate()
.map(|(i, tab)| { .map(|(i, tab)| {
let mut text = format!(" {} ", i + 1); let mut text = format!("{}", i + 1);
if let Some(dir_name) = tab.current_name() { if let Some(dir_name) = tab.current_name() {
text.push(' ');
text.push_str(dir_name); text.push_str(dir_name);
} }
let threshold = THEME.tab.max_width.max(3) - 1; let threshold = THEME.tab.max_width.max(1);
let truncated = text.chars().try_fold(String::with_capacity(threshold), |mut text, c| { let truncated = text.chars().try_fold(String::with_capacity(threshold), |mut text, c| {
if text.width() > threshold { if text.width() > threshold {
ControlFlow::Break(text) ControlFlow::Break(text)
@ -37,18 +38,15 @@ impl<'a> Widget for Tabs<'a> {
ControlFlow::Continue(text) ControlFlow::Continue(text)
} }
}); });
let mut text = match truncated { let text = match truncated {
ControlFlow::Break(text) => text, ControlFlow::Break(text) => text,
ControlFlow::Continue(text) => text, ControlFlow::Continue(text) => text,
}; };
if !text.ends_with(' ') {
text.push(' ');
}
if i == tabs.idx() { if i == tabs.idx() {
Span::styled(text, THEME.tab.active.get()) Span::styled(format!(" {text} "), THEME.tab.active.get())
} else { } else {
Span::styled(text, THEME.tab.inactive.get()) Span::styled(format!(" {text} "), THEME.tab.inactive.get())
} }
}) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),

View file

@ -1,7 +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 = 3 max_width = 1
[status] [status]
primary = { normal = "#80AEFA", select = "#CD9EFC", unset = "#FFA577" } primary = { normal = "#80AEFA", select = "#CD9EFC", unset = "#FFA577" }