From 3189ede2b9225b1b930cc43368248c6b4f3a4daf Mon Sep 17 00:00:00 2001 From: "CHIH,GODLEE" <61595521+ChihGodlee@users.noreply.github.com> Date: Mon, 18 May 2026 20:27:43 +0800 Subject: feat: configure sidebar min/max width via [ui] (#135) * feat: configure sidebar min/max width via [ui] Expose the previously hardcoded MIN_SIDEBAR_WIDTH / MAX_SIDEBAR_WIDTH clamps as [ui] sidebar_min_width / sidebar_max_width. Defaults remain 18 / 36 so existing configs are unchanged. Hot-reload is wired through the existing [ui] block; reload re-clamps the live width to the new bounds so tightening takes effect immediately. Reject inverted bounds (min > max) at every entry point so a bad config can never reach u16::clamp(min, max), which panics: App::new falls back to defaults, and apply_live_config treats the whole [ui] section as invalid and returns a partial reload report. refs #132 * test: keep sidebar reload width within bounds refs #132 --------- Co-authored-by: Ogulcan Celik --- src/ui.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/ui.rs') diff --git a/src/ui.rs b/src/ui.rs index a92eb1fe..846979da 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -71,8 +71,6 @@ use crate::app::state::ViewLayout; use crate::app::{AppState, Mode}; const COLLAPSED_WIDTH: u16 = 4; // num + space + dot + separator -pub(crate) const MIN_SIDEBAR_WIDTH: u16 = 18; -pub(crate) const MAX_SIDEBAR_WIDTH: u16 = 36; // Braille spinner frames — smooth rotation const SPINNERS: &[&str] = &["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; @@ -147,7 +145,7 @@ fn compute_view_internal( COLLAPSED_WIDTH } else { app.sidebar_width - .clamp(MIN_SIDEBAR_WIDTH, MAX_SIDEBAR_WIDTH) + .clamp(app.sidebar_min_width, app.sidebar_max_width) }; let [sidebar_area, main_area] = @@ -450,6 +448,36 @@ mod tests { ); } + #[test] + fn compute_view_clamps_sidebar_width_to_configured_max() { + let mut app = crate::app::state::AppState::test_new(); + app.workspaces = vec![Workspace::test_new("one")]; + app.active = Some(0); + app.selected = 0; + app.mode = Mode::Terminal; + app.sidebar_max_width = 30; + app.sidebar_width = 999; + + compute_view(&mut app, Rect::new(0, 0, 100, 20)); + + assert_eq!(app.view.sidebar_rect.width, 30); + } + + #[test] + fn compute_view_clamps_sidebar_width_to_configured_min() { + let mut app = crate::app::state::AppState::test_new(); + app.workspaces = vec![Workspace::test_new("one")]; + app.active = Some(0); + app.selected = 0; + app.mode = Mode::Terminal; + app.sidebar_min_width = 22; + app.sidebar_width = 5; + + compute_view(&mut app, Rect::new(0, 0, 100, 20)); + + assert_eq!(app.view.sidebar_rect.width, 22); + } + #[test] fn collapsed_sidebar_keeps_active_workspace_highlight_in_terminal_mode() { let mut app = crate::app::state::AppState::test_new(); -- cgit v1.2.3