Files
tui-cv/src/main.rs
dcorral aeabcb3ddb
All checks were successful
Deploy to VPS / deploy (push) Successful in 1m1s
Use alternate screen for ssh sessions
2025-11-06 21:38:12 +01:00

56 lines
1.5 KiB
Rust

mod app;
mod input;
mod theme;
mod ui;
use crossterm::{
event, execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use ratatui::{backend::CrosstermBackend, Terminal};
use std::io::stdout;
fn main() -> Result<(), Box<dyn std::error::Error>> {
enable_raw_mode()?;
let (mut width, mut height) = crossterm::terminal::size()?;
if width == 0 || height == 0 {
width = 80;
height = 24;
}
println!("Width: {}, Height: {}", width, height);
let use_alternate_screen =
std::env::var("SSH_CLIENT").is_err() && std::env::var("SSH_TTY").is_err();
let mut stdout = stdout();
if use_alternate_screen {
execute!(stdout, EnterAlternateScreen)?;
}
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
let mut app = app::App::new();
let mut blink_counter = 0;
loop {
let blink = (blink_counter / 3) % 2 == 0;
terminal.draw(|f| ui::draw(f, &app, blink))?;
blink_counter += 1;
let timeout = if app.show_welcome {
std::time::Duration::from_millis(70)
} else {
std::time::Duration::from_millis(60)
};
if event::poll(timeout)? {
let event = event::read()?;
if !input::handle_input(&mut app, event) {
break;
}
}
}
disable_raw_mode()?;
if use_alternate_screen {
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
}
Ok(())
}