fix: lead the bottom position indicator with one margin column

This commit is contained in:
Valdemar Lorenzen
2026-10-13 11:24:42 +02:00
parent 9f33104cb2
commit 002f071b0f
5 changed files with 79 additions and 23 deletions
+50 -10
View File
@@ -1244,7 +1244,8 @@ fn chrome_items<'a>(
for item in &mut items {
item.width = item.text.width()
+ item.config.padding * 2
+ item.config.margin * 2
+ item.config.margin[0]
+ item.config.margin[1]
+ if item.tab.is_none() || item.accent {
item.leading_edge().width() + item.config.trailing_edge.width()
} else {
@@ -1359,11 +1360,12 @@ fn draw_chrome(frame: &mut Frame, mut groups: [Vec<ChromeItem<'_>>; 3], area: Re
const PADDING: &str =
" ";
let padding = &PADDING[..item.config.padding];
let margin = &PADDING[..item.config.margin];
let leading_margin = &PADDING[..item.config.margin[0]];
let trailing_margin = &PADDING[..item.config.margin[1]];
let edges = item.tab.is_none() || item.accent;
let edge = Style::default().fg(Color::Cyan);
Line::from(vec![
Span::styled(margin, Style::reset()),
Span::styled(leading_margin, Style::reset()),
Span::styled(if edges { item.leading_edge() } else { "" }, edge),
Span::styled(padding, style),
Span::styled(item.text.as_ref(), style),
@@ -1376,7 +1378,7 @@ fn draw_chrome(frame: &mut Frame, mut groups: [Vec<ChromeItem<'_>>; 3], area: Re
},
edge,
),
Span::styled(margin, Style::reset()),
Span::styled(trailing_margin, Style::reset()),
])
};
let cells = item_width.min(available);
@@ -5975,6 +5977,44 @@ mod tests {
}
}
#[test]
fn bottom_position_has_only_a_leading_margin_and_lsp_has_none() {
let mut editor = Editor::open(None, vec![]).unwrap();
editor.set_lsp_names(vec!["server".into()]);
configure_chrome(&mut editor, |top, bottom| {
top.left.clear();
top.center.clear();
top.right = vec!["position".into()];
bottom.left.clear();
bottom.center.clear();
bottom.right = vec!["lsp".into(), "position".into()];
});
let mut terminal = Terminal::new(ratatui::backend::TestBackend::new(40, 2)).unwrap();
terminal
.draw(|frame| {
for (line, y) in [
(editor.top_bar_config(), 0),
(editor.bottom_bar_config(), 1),
] {
let groups = chrome_groups(&editor, line, &SyntaxCache::new());
let start = 40 - chrome_group_width(&groups[2]) as u16;
if y == 1 {
let gap = start + groups[2][0].width as u16;
draw_chrome(frame, groups, Rect::new(0, y, 40, 1));
assert_eq!(frame.buffer_mut()[(start, y)].bg, Color::Cyan);
assert_eq!(frame.buffer_mut()[(gap, y)].symbol(), " ");
assert_eq!(frame.buffer_mut()[(gap, y)].bg, Color::Reset);
assert_eq!(frame.buffer_mut()[(gap + 1, y)].symbol(), "░");
} else {
draw_chrome(frame, groups, Rect::new(0, y, 40, 1));
assert_eq!(frame.buffer_mut()[(start, y)].symbol(), "░");
}
assert_eq!(frame.buffer_mut()[(39, y)].bg, Color::Cyan);
}
})
.unwrap();
}
#[test]
fn bar_margins_surround_styling_and_keep_anchors_and_narrow_content() {
let directory = Directory::new();
@@ -5983,7 +6023,7 @@ mod tests {
r#"
Vamp.configure do |config|
options = {left: [:badge], center: [:lsp], right: [:badge],
badge: {padding: 0, margin: 2, leading_edge: "<", trailing_edge: ">"}, lsp: {padding: 0}}
badge: {padding: 0, margin: 2, leading_edge: "<", trailing_edge: ">"}, lsp: {padding: 0, margin: 1}}
config.bar.top = options
config.bar.bottom = options
end
@@ -6036,7 +6076,7 @@ end
line.center.clear();
line.right.clear();
let lsp = line.segments.get_mut("lsp").unwrap();
lsp.margin = 64;
lsp.margin = [64; 2];
lsp.padding = 64;
}
});
@@ -6749,7 +6789,7 @@ end
SegmentConfig {
title: String::new(),
padding: 0,
margin: 0,
margin: [0; 2],
leading_edge: String::new(),
trailing_edge: String::new(),
first_leading_edge: None,
@@ -6913,7 +6953,7 @@ end
SegmentConfig {
title: "{index}".into(),
padding: 2,
margin: 0,
margin: [0; 2],
leading_edge: "界▌".into(),
trailing_edge: "▐界".into(),
first_leading_edge: Some("<".into()),
@@ -6924,7 +6964,7 @@ end
SegmentConfig {
title: String::new(),
padding: 2,
margin: 0,
margin: [0; 2],
leading_edge: "界(".into(),
trailing_edge: ")界".into(),
first_leading_edge: None,
@@ -7021,7 +7061,7 @@ end
SegmentConfig {
title: "Not visible without a value".into(),
padding: 64,
margin: 0,
margin: [0; 2],
leading_edge: "░▒▓".into(),
trailing_edge: "▓▒░".into(),
first_leading_edge: None,