par_term/app/
mod.rs

1//! Application module for par-term
2//!
3//! This module contains the main application logic, including:
4//! - `App`: Entry point that initializes and runs the event loop
5//! - `WindowManager`: Manages multiple windows and coordinates menu events
6//! - `WindowState`: Per-window state including terminal, renderer, and UI
7
8use crate::config::Config;
9use anyhow::Result;
10use std::sync::Arc;
11use tokio::runtime::Runtime;
12use winit::event_loop::{ControlFlow, EventLoop};
13
14pub mod bell;
15pub mod debug_state;
16pub mod handler;
17pub mod input_events;
18pub mod mouse;
19pub mod mouse_events;
20pub mod render_cache;
21pub mod window_manager;
22pub mod window_state;
23
24pub use window_manager::WindowManager;
25
26/// Main application entry point
27pub struct App {
28    config: Config,
29    runtime: Arc<Runtime>,
30}
31
32impl App {
33    /// Create a new application
34    pub fn new(runtime: Arc<Runtime>) -> Result<Self> {
35        let config = Config::load()?;
36        Ok(Self { config, runtime })
37    }
38
39    /// Run the application
40    pub fn run(self) -> Result<()> {
41        let event_loop = EventLoop::new()?;
42        // Use Wait for power-efficient event handling
43        // Combined with WaitUntil in about_to_wait for precise timing
44        event_loop.set_control_flow(ControlFlow::Wait);
45
46        let mut window_manager = WindowManager::new(self.config, self.runtime);
47
48        event_loop.run_app(&mut window_manager)?;
49
50        Ok(())
51    }
52}