feat: a working crock

This commit is contained in:
Christoph J. Scherr 2024-07-09 12:34:15 +02:00 committed by PlexSheep
parent 7f81f884e4
commit 40d391a266
2 changed files with 20 additions and 10 deletions

View File

@ -15,3 +15,4 @@ keywords = ["time", "clock", "tui"]
[dependencies] [dependencies]
chrono = "0.4.38" chrono = "0.4.38"
ratatui = "0.27.0" ratatui = "0.27.0"
tui-big-text = "0.4.5"

View File

@ -3,7 +3,8 @@ use ratatui::{
backend::CrosstermBackend, backend::CrosstermBackend,
crossterm::event::poll, crossterm::event::poll,
layout::{Constraint, Direction, Layout, Rect}, layout::{Constraint, Direction, Layout, Rect},
widgets::{Block, Borders}, style::Style,
widgets::{Block, Borders, Paragraph},
Terminal, Terminal,
}; };
use ratatui::{ use ratatui::{
@ -27,16 +28,24 @@ fn main() -> Result<(), io::Error> {
let mut terminal = Terminal::new(backend)?; let mut terminal = Terminal::new(backend)?;
loop { loop {
let time = chrono::Utc::now().round_subsecs(0); let raw_time = chrono::Utc::now().round_subsecs(0);
let splits: Vec<String> = raw_time
.naive_local()
.to_string()
.split_whitespace()
.map(str::to_string)
.collect();
let fdate: String = splits[0].clone();
let ftime: String = splits[1].clone();
terminal.draw(|f| { terminal.draw(|f| {
let w = ratatui::widgets::Paragraph::new(format!( let timew = tui_big_text::BigText::builder()
"{}\n\n{}", .style(Style::new().red())
time.time(), .lines(vec![ftime.into()])
time.date_naive() .build()
)) .expect("could not render time widget");
.centered() let datew = Paragraph::new(fdate).blue();
.red(); f.render_widget(datew, centered_rect(f.size(), 45, 80));
f.render_widget(w, centered_rect(f.size(), 40, 20)); f.render_widget(timew, centered_rect(f.size(), 45, 60));
})?; })?;
if poll(Duration::from_millis(100))? { if poll(Duration::from_millis(100))? {
if let Event::Key(key) = event::read()? { if let Event::Key(key) = event::read()? {