From 1ed981b43d377d1b08999f93d2b8374a6bc9858a Mon Sep 17 00:00:00 2001 From: Valdemar Lorenzen Date: Tue, 20 Oct 2026 16:30:53 +0200 Subject: [PATCH] fix: right-align connection access in the header --- src/connection.rs | 32 +++++++++++++++++++++++++++++--- src/main.rs | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/connection.rs b/src/connection.rs index 4139ab3..fe62782 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -546,16 +546,21 @@ fn draw_bars( let base = Style::default(); let badge = Style::default().bg(Color::Cyan).fg(Color::Black); let edge = base.fg(Color::Cyan); + let access = access.map_or("NOT CONNECTED", AccessMode::label); + let [brand_area, access_area] = Layout::horizontal([ + Constraint::Min(0), + Constraint::Length(access.len() as u16), + ]) + .areas(top); frame.render_widget( Paragraph::new(Line::from(vec![ Span::styled(" dbdash ", badge), Span::styled("▓░", edge), - Span::raw(" "), - Span::raw(access.map_or("NOT CONNECTED", AccessMode::label)), ])) .style(base), - top, + brand_area, ); + frame.render_widget(Paragraph::new(access).right_aligned().style(base), access_area); frame.render_widget(Paragraph::new("").style(base), bottom); let position = position.map(|(line, column)| format!(" {line}:{column} ")); let position = position.as_deref().unwrap_or(" N/A "); @@ -1597,6 +1602,27 @@ mod tests { Ok(()) } + #[test] + fn access_status_stays_at_the_top_right() -> Result<()> { + for width in [24, 80] { + for access in [Some(AccessMode::ReadOnly), Some(AccessMode::ReadWrite), None] { + let mut terminal = ratatui::Terminal::new( + ratatui::backend::TestBackend::new(width, 6), + )?; + terminal.draw(|frame| { + let [top, _, bottom] = shell_areas(frame.area()); + draw_bars(frame, top, bottom, "", "", access, false, None); + })?; + let header: String = (0..width) + .map(|x| terminal.backend().buffer()[(x, 0)].symbol()) + .collect(); + assert!(header.starts_with(" dbdash ▓░")); + assert!(header.ends_with(access.map_or("NOT CONNECTED", AccessMode::label))); + } + } + Ok(()) + } + #[test] fn ca_selector_persists_per_profile_and_keeps_missing_selections_fail_closed() -> Result<()> { let directory = tempfile::tempdir()?; diff --git a/src/main.rs b/src/main.rs index 383f86c..e8df42d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,7 +82,7 @@ Navigation: Enter on the connected database collapses/expands it without reconnecting. Keybindings float above the workspace; Up/Down/jk scroll, Home/End/g/G jump. Query Insert mode and connection/password fields keep ? as literal text. - Full-width bars show dbdash/live READ ONLY or READ WRITE above and mode/database below. + Full-width bars show dbdash at top-left, live access mode at top-right, and mode/database below. Saved PostgreSQL connections show database · user@host:port beside the mode, regardless of custom sidebar names; passwords are never included. The database provider sits immediately left of the bottom-right position badge.