fix: align access badges by placing active marker before them

This commit is contained in:
Valdemar Lorenzen
2026-10-20 14:12:10 +02:00
parent 4f472b55f3
commit f3a5984a26
+12 -5
View File
@@ -450,7 +450,7 @@ fn draw_help(frame: &mut Frame, screen: Rect, offset: &mut u16) {
Optional Name sets the sidebar label; blank uses the default.\n\ Optional Name sets the sidebar label; blank uses the default.\n\
Connect saves settings only on success; e edits save without connecting.\n\ Connect saves settings only on success; e edits save without connecting.\n\
Access defaults to READ ONLY, including older saved connections.\n\ Access defaults to READ ONLY, including older saved connections.\n\
[RO]/[RW] badges remain visible when sidebar names truncate.\n\ [RO]/[RW] badges stay right-aligned; * before the badge marks the active connection.\n\
Header/connected badge show live mode; info shows saved Access.\n\ Header/connected badge show live mode; info shows saved Access.\n\
Saved mode edits need R to reconnect before they take effect.\n\ Saved mode edits need R to reconnect before they take effect.\n\
CA bundles come from .pem/.crt files in the dbdash config directory.\n\ CA bundles come from .pem/.crt files in the dbdash config directory.\n\
@@ -516,10 +516,10 @@ fn database_label(label: &str, access: AccessMode, connected: bool, expanded: bo
result.push(' '); result.push(' ');
} }
result.push(' '); result.push(' ');
result.push_str(badge);
if connected { if connected {
result.push_str("* "); result.push_str("* ");
} }
result.push_str(badge);
result result
} }
@@ -1586,7 +1586,6 @@ mod tests {
profiles.save(&saved)?; profiles.save(&saved)?;
assert_eq!(profiles.entries[0].access, AccessMode::ReadOnly); assert_eq!(profiles.entries[0].access, AccessMode::ReadOnly);
assert_eq!(live.access_mode(), AccessMode::ReadWrite); assert_eq!(live.access_mode(), AccessMode::ReadWrite);
assert!(database_label("data", live.access_mode(), true, true, 30).ends_with("[RW] *"));
let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(40, 6))?; let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(40, 6))?;
terminal.draw(|frame| { terminal.draw(|frame| {
let [top, _, bottom] = shell_areas(frame.area()); let [top, _, bottom] = shell_areas(frame.area());
@@ -1769,9 +1768,17 @@ mod tests {
frame.area(), frame.area(),
); );
})?; })?;
assert_eq!(terminal.backend().buffer()[(30, 1)].symbol(), "*"); assert_eq!(terminal.backend().buffer()[(25, 1)].symbol(), "*");
let row: String = (1..31).map(|x| terminal.backend().buffer()[(x, 1)].symbol()).collect(); let row: String = (1..31).map(|x| terminal.backend().buffer()[(x, 1)].symbol()).collect();
assert!(row.ends_with("[RW] *")); assert!(row.ends_with("* [RW]"));
let inactive = database_label("inactive", AccessMode::ReadOnly, false, false, 30);
let active_badge_column = (1..31)
.find(|&x| terminal.backend().buffer()[(x, 1)].symbol() == "[")
.unwrap() - 1;
assert_eq!(
active_badge_column as usize,
Line::raw(&inactive[..inactive.find("[RO]").unwrap()]).width()
);
for width in 4..9 { for width in 4..9 {
assert_eq!(database_label("long", AccessMode::ReadOnly, true, true, width), "[RO]"); assert_eq!(database_label("long", AccessMode::ReadOnly, true, true, width), "[RO]");
} }