mod app; mod component; mod editor; mod explorer; use anyhow::{Context, Result}; use ratatui::Terminal; use ratatui::backend::CrosstermBackend; use ratatui::crossterm::event::{ DisableBracketedPaste, DisableMouseCapture, EnableBracketedPaste, EnableMouseCapture, }; use ratatui::crossterm::terminal::{ EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode, }; use std::io::{Stdout, stdout}; pub struct Tui { terminal: Terminal>, root_path: std::path::PathBuf, } impl Tui { pub fn new(root_path: std::path::PathBuf) -> Self { Self { terminal: Terminal::new(CrosstermBackend::new(stdout())) .expect("Failed to initialize terminal"), root_path, } } pub fn start(self) -> Result<()> { println!("Starting the TUI editor at {:?}", self.root_path); ratatui::crossterm::execute!( stdout(), EnterAlternateScreen, EnableMouseCapture, EnableBracketedPaste )?; enable_raw_mode()?; let app_result = app::App::new(self.root_path) .run(self.terminal) .context("Failed to start the TUI editor."); Self::stop()?; app_result } fn stop() -> Result<()> { disable_raw_mode()?; ratatui::crossterm::execute!( stdout(), LeaveAlternateScreen, DisableMouseCapture, DisableBracketedPaste )?; Ok(()) } }