use crate::gui::util; use crossterm::event::{self, Event, KeyCode, KeyModifiers}; use anyhow::Result; use tui::{ backend::Backend, layout::{Alignment, Constraint, Direction, Layout}, widgets::Paragraph, Terminal, }; pub fn show( terminal: &mut Terminal, title: &str, message: &str, wait: bool, ) -> Result<()> { loop { terminal.draw(|f| { let chunks = Layout::default() .direction(Direction::Vertical) .margin(2) .constraints([Constraint::Length(1), Constraint::Percentage(50)].as_ref()) .split(f.size()); let d1 = util::title(title); f.render_widget(d1, chunks[0]); let message = Paragraph::new(util::center_vertically(chunks[1], message)) .alignment(Alignment::Center); f.render_widget(message, chunks[1]); })?; if wait { if let Event::Key(key) = event::read()? { if key.code == KeyCode::Char('q') || key.code == KeyCode::Char('c') && key.modifiers.contains(KeyModifiers::CONTROL) { break; } } } else { break; } } Ok(()) }