Add weather API
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Isaac Mills 2025-07-28 15:15:55 -06:00
parent 3a6b9713f9
commit 265f8d8dc3
Signed by: fnmain
GPG key ID: B67D7410F33A0F61
5 changed files with 154 additions and 44 deletions

View file

@ -1,37 +1,63 @@
use std::time::Duration;
use std::{future::Future, time::Duration};
use futures_util::FutureExt;
use ratatui::crossterm::event;
use thecockpit::app::App;
use thecockpit::app::{App, AppExecutor};
struct TokioExecutor;
impl AppExecutor for TokioExecutor {
fn execute<T: 'static>(
&self,
future: impl Future<Output = T> + 'static,
sender: std::sync::mpsc::Sender<T>,
) {
tokio::task::spawn_local(future.map(move |output| sender.send(output).unwrap()));
}
}
fn main() {
let mut terminal = ratatui::init();
let mut app = App::new();
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
loop {
terminal.draw(|frame| app.draw(frame)).unwrap();
let local = tokio::task::LocalSet::new();
if event::poll(Duration::from_secs(0)).unwrap() {
match event::read().unwrap() {
event::Event::Key(event::KeyEvent {
code: event::KeyCode::Char('q'),
..
}) => break,
event::Event::Key(event::KeyEvent {
code: event::KeyCode::Left,
..
}) => app.prev_tab(),
event::Event::Key(event::KeyEvent {
code: event::KeyCode::Right,
..
}) => app.next_tab(),
event::Event::Key(event::KeyEvent {
code: event::KeyCode::Char(c),
..
}) => app.add_char_to_number_guess(c),
_ => {}
local.spawn_local(async {
let mut terminal = ratatui::init();
let mut app = App::new(TokioExecutor);
loop {
terminal.draw(|frame| app.draw(frame)).unwrap();
if event::poll(Duration::from_secs(0)).unwrap() {
match event::read().unwrap() {
event::Event::Key(event::KeyEvent {
code: event::KeyCode::Char('q'),
..
}) => break,
event::Event::Key(event::KeyEvent {
code: event::KeyCode::Left,
..
}) => app.prev_tab(),
event::Event::Key(event::KeyEvent {
code: event::KeyCode::Right,
..
}) => app.next_tab(),
event::Event::Key(event::KeyEvent {
code: event::KeyCode::Char(c),
..
}) => app.add_char_to_number_guess(c),
_ => {}
}
}
}
}
ratatui::restore();
tokio::task::yield_now().await;
}
ratatui::restore();
});
rt.block_on(local);
}