2024-07-09 11:58:12 +02:00
|
|
|
use ratatui::crossterm::{
|
|
|
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyModifiers},
|
|
|
|
execute,
|
|
|
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
|
|
|
};
|
|
|
|
use ratatui::{
|
|
|
|
backend::CrosstermBackend,
|
|
|
|
widgets::{Block, Borders},
|
|
|
|
Terminal,
|
|
|
|
};
|
|
|
|
use std::io;
|
|
|
|
|
|
|
|
const TITLE: &str = "Crock";
|
|
|
|
|
|
|
|
fn main() -> Result<(), io::Error> {
|
|
|
|
// setup terminal
|
|
|
|
enable_raw_mode()?;
|
|
|
|
let mut stdout = io::stdout();
|
|
|
|
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
|
|
|
|
let backend = CrosstermBackend::new(stdout);
|
|
|
|
let mut terminal = Terminal::new(backend)?;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
terminal.draw(|f| {
|
|
|
|
let size = f.size();
|
|
|
|
let block = Block::default().title(TITLE).borders(Borders::ALL);
|
|
|
|
let inner = block.inner(size);
|
|
|
|
f.render_widget(block, size);
|
|
|
|
let w = ratatui::widgets::Paragraph::new(format!("{}", chrono::Utc::now()));
|
|
|
|
f.render_widget(w, inner);
|
|
|
|
})?;
|
|
|
|
if let Event::Key(key) = event::read()? {
|
|
|
|
if key.code == KeyCode::Char('q')
|
|
|
|
|| key.code == KeyCode::Esc
|
|
|
|
|| (key.modifiers.contains(KeyModifiers::CONTROL) && key.code == KeyCode::Char('c'))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore terminal
|
|
|
|
disable_raw_mode()?;
|
|
|
|
execute!(
|
|
|
|
terminal.backend_mut(),
|
|
|
|
LeaveAlternateScreen,
|
|
|
|
DisableMouseCapture
|
|
|
|
)?;
|
|
|
|
terminal.show_cursor()?;
|
|
|
|
|
|
|
|
Ok(())
|
2024-03-04 15:14:28 +01:00
|
|
|
}
|