diff --git a/src/app.rs b/src/app.rs index deaa35f..5533434 100644 --- a/src/app.rs +++ b/src/app.rs @@ -87,9 +87,24 @@ impl App { } pub fn new() -> anyhow::Result { + let config = Config::load()?; + let mut state = AppState::load()?; + + // Initialize current_pane to first enabled section + let enabled = [ + config.show_permanent, + config.show_recurring, + config.show_recent, + ]; + + // Find first enabled pane + if let Some(first_enabled) = enabled.iter().position(|&x| x) { + state.current_pane = first_enabled; + } + Ok(Self { - state: AppState::load()?, - config: Config::load()?, + state, + config, current_screen: Screen::Main, needs_clear: false, new_entry_buffer: String::new(), @@ -1213,7 +1228,29 @@ impl App { } fn change_pane(&mut self, delta: i32) { - self.state.current_pane = ((self.state.current_pane as i32 + delta).rem_euclid(3)) as usize; + // Find next enabled pane + let mut next_pane = self.state.current_pane; + let enabled = [ + self.config.show_permanent, + self.config.show_recurring, + self.config.show_recent, + ]; + + // Count enabled panes + let enabled_count = enabled.iter().filter(|&&x| x).count(); + if enabled_count == 0 { + return; // No panes to switch to + } + + // Find next enabled pane + for _ in 0..3 { + next_pane = ((next_pane as i32 + delta).rem_euclid(3)) as usize; + if enabled[next_pane] { + break; + } + } + + self.state.current_pane = next_pane; self.state.current_column = 0; } diff --git a/src/config.rs b/src/config.rs index 1ddb538..240617f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,6 +11,12 @@ pub struct Config { pub strict_projects: bool, #[serde(default = "default_multi_column")] pub multi_column: bool, + #[serde(default = "default_true")] + pub show_permanent: bool, + #[serde(default = "default_true")] + pub show_recurring: bool, + #[serde(default = "default_true")] + pub show_recent: bool, } fn default_show_help_hint() -> bool { @@ -25,6 +31,10 @@ fn default_multi_column() -> bool { true } +fn default_true() -> bool { + true +} + impl Default for Config { fn default() -> Self { Self { @@ -32,6 +42,9 @@ impl Default for Config { projects: Vec::new(), strict_projects: default_strict_projects(), multi_column: default_multi_column(), + show_permanent: default_true(), + show_recurring: default_true(), + show_recent: default_true(), } } } diff --git a/src/ui.rs b/src/ui.rs index d7ab0f5..df721af 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -43,74 +43,92 @@ fn render_main(frame: &mut Frame, app: &App) { } }; - let constraints = if bottom_height > 0 { - vec![ - Constraint::Min(3), // At least 3 lines for each section - Constraint::Min(3), - Constraint::Min(3), - Constraint::Length(bottom_height), // Command bar + optional status - ] - } else { - vec![Constraint::Min(3), Constraint::Min(3), Constraint::Min(3)] - }; + // Count enabled sections + let enabled_sections = [ + app.config.show_permanent, + app.config.show_recurring, + app.config.show_recent, + ] + .iter() + .filter(|&&x| x) + .count(); + + if enabled_sections == 0 { + // No sections enabled - show a message + let block = Block::default() + .borders(Borders::ALL) + .title("WAT") + .style(Style::default().fg(ACTIVE_COLOR)); + + let text = Paragraph::new("No sections enabled. Edit config (press 'c') to enable sections.") + .block(block) + .style(Style::default().fg(Color::Yellow)) + .alignment(Alignment::Center); + + frame.render_widget(text, frame.size()); + return; + } + + // Build constraints for enabled sections + let section_percentage = 100 / enabled_sections as u16; + let mut constraints = vec![Constraint::Percentage(section_percentage); enabled_sections]; + if bottom_height > 0 { + constraints.push(Constraint::Length(bottom_height)); + } let chunks = Layout::default() .direction(Direction::Vertical) .constraints(constraints) .split(frame.size()); - let main_height = if bottom_height > 0 { - chunks[0].height + chunks[1].height + chunks[2].height - } else { - frame.size().height - }; + // Render enabled sections + let mut chunk_idx = 0; + + if app.config.show_permanent { + render_section( + frame, + chunks[chunk_idx], + "Permanent Items", + &app.state.permanent_items, + app.state.current_pane == 0, + app.state.selected_indices[0], + app.state.current_column, + app.config.multi_column, + ); + chunk_idx += 1; + } - let section_height = main_height / 3; + if app.config.show_recurring { + render_section( + frame, + chunks[chunk_idx], + "Recurring Items", + &app.state.recurring_items, + app.state.current_pane == 1, + app.state.selected_indices[1], + app.state.current_column, + app.config.multi_column, + ); + chunk_idx += 1; + } - // Create sections with equal height - let sections = vec![ - Rect::new(0, 0, frame.size().width, section_height), - Rect::new(0, section_height, frame.size().width, section_height), - Rect::new(0, section_height * 2, frame.size().width, section_height), - ]; - - // Render main sections - render_section( - frame, - sections[0], - "Permanent Items", - &app.state.permanent_items, - app.state.current_pane == 0, - app.state.selected_indices[0], - app.state.current_column, - app.config.multi_column, - ); - - render_section( - frame, - sections[1], - "Recurring Items", - &app.state.recurring_items, - app.state.current_pane == 1, - app.state.selected_indices[1], - app.state.current_column, - app.config.multi_column, - ); - - render_section( - frame, - sections[2], - "Ad-Hoc Items", - &app.state.recent_items, - app.state.current_pane == 2, - app.state.selected_indices[2], - app.state.current_column, - app.config.multi_column, - ); + if app.config.show_recent { + render_section( + frame, + chunks[chunk_idx], + "Ad-Hoc Items", + &app.state.recent_items, + app.state.current_pane == 2, + app.state.selected_indices[2], + app.state.current_column, + app.config.multi_column, + ); + chunk_idx += 1; + } // Render bottom bar if needed if bottom_height > 0 { - let bottom_area = chunks[3]; + let bottom_area = chunks[chunk_idx]; render_bottom_bar(frame, bottom_area, app); } }