mod overlays;
mod panels;
pub mod theme;
pub mod widgets;
use ratatui::{
Frame,
layout::{Constraint, Direction, Layout},
};
use crate::app::{App, AppMode, ScpState};
pub fn draw(f: &mut Frame, app: &mut App) {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(3), Constraint::Length(3), Constraint::Min(0), Constraint::Length(2), ])
.split(f.area());
panels::draw_search_bar(f, app, chunks[0]);
panels::draw_connection_mode_area(f, app, chunks[1]);
let main_chunks = if app.pinned_server.is_some() {
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage(40), Constraint::Percentage(30), Constraint::Percentage(30), ])
.split(chunks[2])
} else {
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage(67), Constraint::Min(0), ])
.split(chunks[2])
};
panels::draw_tree(f, app, main_chunks[0]);
panels::draw_details(f, app, main_chunks[1]);
if app.pinned_server.is_some() {
panels::draw_pinned_server(f, app, main_chunks[2]);
}
panels::draw_status_bar(f, app, chunks[3]);
if app.tunnel_overlay.is_some() {
overlays::draw_tunnel_overlay(f, app, f.area());
}
if !matches!(app.scp_state, ScpState::Idle | ScpState::Running { .. }) {
overlays::draw_scp_overlay(f, app, f.area());
}
if app.wallix_selector.is_some() {
overlays::draw_wallix_selector_overlay(f, app, f.area());
}
if matches!(&app.app_mode, AppMode::CredentialInput { .. }) {
overlays::draw_credential_input_overlay(f, app, f.area());
}
if app.overview.is_some() {
overlays::draw_overview_overlay(f, app, f.area());
}
if app.show_help {
overlays::draw_help_overlay(f, f.area(), app.theme);
}
if let AppMode::Error(msg) = &app.app_mode {
overlays::draw_error_overlay(f, msg.clone(), f.area(), app.theme);
}
}