pub mod agent;
pub mod config;
pub mod shortcuts_bar;
pub mod status_bar;
pub mod welcome;
pub use agent::{
AUTO_COMPACT_MAX_ROWS, ActivePane, AgentViewLayout, LayoutInput, PaneAreas,
SHORT_TERMINAL_ROWS, effective_compact,
};
pub use config::{LayoutConfig, ScrollbarConfig};
pub use shortcuts_bar::{
CompactConfig, HintItem, PendingHint, ShortcutBarStyling, ShortcutsBar, compute_effective_hints,
};
pub use status_bar::{StatusBar, StatusBarBuilder, StatusBarStyling};
pub use welcome::{HERO_BOX_MIN_WIDTH, PROMPT_HEIGHT, WelcomeLayout, WelcomePromptFocus};
use ratatui::layout::Rect;
use crate::design::constants::{COMPACT_MAX_COLS, COMPACT_MAX_ROWS, WIDE_MIN_COLS, WIDE_MIN_ROWS};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum LayoutMode {
Compact,
Standard,
Wide,
}
impl LayoutMode {
pub(crate) fn from_area(area: Rect) -> Self {
if area.width <= COMPACT_MAX_COLS || area.height <= COMPACT_MAX_ROWS {
LayoutMode::Compact
} else if area.width >= WIDE_MIN_COLS && area.height >= WIDE_MIN_ROWS {
LayoutMode::Wide
} else {
LayoutMode::Standard
}
}
pub(crate) fn show_borders(self) -> bool {
!matches!(self, LayoutMode::Compact)
}
pub(crate) fn show_titles(self) -> bool {
!matches!(self, LayoutMode::Compact)
}
pub(crate) fn allow_sidebar(self) -> bool {
matches!(self, LayoutMode::Wide)
}
pub(crate) fn show_logs_panel(self) -> bool {
!matches!(self, LayoutMode::Compact)
}
pub(crate) fn footer_height(self) -> u16 {
0
}
pub(crate) fn show_footer(self) -> bool {
false
}
pub(crate) fn max_header_percent(self) -> f32 {
match self {
LayoutMode::Compact => 0.2,
_ => 0.3,
}
}
pub(crate) fn sidebar_width_percent(self) -> u16 {
match self {
LayoutMode::Wide => 25,
_ => 0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn compact_mode_for_small_terminals() {
assert_eq!(
LayoutMode::from_area(Rect::new(0, 0, 60, 20)),
LayoutMode::Compact
);
assert_eq!(
LayoutMode::from_area(Rect::new(0, 0, 80, 15)),
LayoutMode::Compact
);
}
#[test]
fn standard_mode_for_normal_terminals() {
assert_eq!(
LayoutMode::from_area(Rect::new(0, 0, 100, 22)),
LayoutMode::Standard
);
}
#[test]
fn wide_mode_for_large_terminals() {
assert_eq!(
LayoutMode::from_area(Rect::new(0, 0, 140, 30)),
LayoutMode::Wide
);
}
}