2026-01-19 09:23:12 -05:00
|
|
|
mod app;
|
2026-01-17 17:09:42 -05:00
|
|
|
mod component;
|
2026-01-17 19:21:14 -05:00
|
|
|
mod editor;
|
2026-01-18 10:09:28 -05:00
|
|
|
mod explorer;
|
2026-01-17 14:04:02 -05:00
|
|
|
|
2026-01-17 11:40:40 -05:00
|
|
|
use anyhow::{Context, Result};
|
2026-01-18 10:09:28 -05:00
|
|
|
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<CrosstermBackend<Stdout>>,
|
|
|
|
|
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()?;
|
|
|
|
|
|
2026-01-19 09:23:12 -05:00
|
|
|
let app_result = app::App::new(self.root_path)
|
2026-01-18 10:09:28 -05:00
|
|
|
.run(self.terminal)
|
|
|
|
|
.context("Failed to start the TUI editor.");
|
|
|
|
|
Self::stop()?;
|
|
|
|
|
app_result
|
|
|
|
|
}
|
2025-04-13 12:17:11 -04:00
|
|
|
|
2026-01-18 10:09:28 -05:00
|
|
|
fn stop() -> Result<()> {
|
|
|
|
|
disable_raw_mode()?;
|
|
|
|
|
ratatui::crossterm::execute!(
|
|
|
|
|
stdout(),
|
|
|
|
|
LeaveAlternateScreen,
|
|
|
|
|
DisableMouseCapture,
|
|
|
|
|
DisableBracketedPaste
|
|
|
|
|
)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2026-01-17 11:40:40 -05:00
|
|
|
}
|