Files
osui/examples/hello_world.rs
T
2026-01-24 10:44:30 +01:00

40 lines
731 B
Rust

use std::sync::Arc;
use osui::prelude::*;
#[derive(Debug, Clone)]
pub struct KeyPress;
impl Event for KeyPress {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
fn main() {
let console = Console::new();
console.thread(move |ctx| loop {
crossterm::event::read().unwrap();
ctx.emit_event_threaded(&KeyPress);
});
console.run(app);
}
fn app(cx: &Arc<Context>) -> View {
let count = use_state(0);
cx.on_event({
let count = count.clone();
move |_cx, _event: &KeyPress| {
let mut count = count.get();
*count += 1;
}
});
Arc::new(move |ctx| {
println!("Count: {count}, size: {:?}", ctx.available);
})
}