use std::time::Duration; use crossterm::event; use crossterm::event::{Event, KeyCode, KeyEventKind}; use ratatui::Frame; use ratatui::style::Stylize; use ratatui::text::Line; use ratatui::widgets::{Block, Paragraph}; use crate::tui::ratatui_app::RatatuiApp; use crate::tui::ratatui_screens::RatatuiScreens::Monitoring; use color_eyre::Result; pub struct RatatuiDeletingMode {} impl RatatuiDeletingMode { pub fn render(frame: &mut Frame, state: &mut RatatuiApp) { let title = Line::from("Delete Host").bold().red().centered(); let as_list = state.state.clone(); let mut nice_status = None; for (index, (label, data)) in as_list.iter().enumerate() { if index == state.selected_host { nice_status = Some(data); } } let mut body = format!("Do you really want to delete {} (Y/N)", nice_status.unwrap().name); frame.render_widget( Paragraph::new(body) .block(Block::bordered().title(title)) .centered(), frame.area() ); } pub fn handle_crossterm_events(app: &mut RatatuiApp) -> Result<()> { if event::poll(Duration::from_millis(100))? { match event::read()? { Event::Key(key) if key.kind == KeyEventKind::Press => match key.code { KeyCode::Enter | KeyCode::Char('y') | KeyCode::Char('Y') => { let as_list = &app.state.clone(); for (index, (label, _)) in as_list.iter().enumerate() { if index == app.selected_host { app.state.remove(label).unwrap(); app.set_screen(Monitoring) } } } KeyCode::Esc | KeyCode::Char('n') | KeyCode::Char('N') => { app.set_screen(Monitoring) } _ => {} } _ => {} } } Ok(()) } }