use std::time::{Duration, Instant};
use calloop::EventLoop;
use calloop::channel::Event;
use tablero::producer::ProducerBridge;
use tablero::volume::VolumeProducer;
use tablero::widget::Msg;
fn main() {
env_logger::init();
let seconds: u64 = std::env::args()
.nth(1)
.and_then(|arg| arg.parse().ok())
.unwrap_or(6);
let mut harness = EventLoop::<Vec<Msg>>::try_new().expect("event loop");
let (bridge, channel) = ProducerBridge::new().expect("bridge");
let _source = harness
.handle()
.insert_source(
channel,
|event: Event<Msg>, _: &mut (), msgs: &mut Vec<Msg>| {
if let Event::Msg(msg) = event {
msgs.push(msg);
}
},
)
.expect("channel registers");
bridge.spawn(Box::new(VolumeProducer::new()));
let start = Instant::now();
let deadline = start + Duration::from_secs(seconds);
let step = Duration::from_millis(50);
let mut msgs: Vec<Msg> = Vec::new();
let mut printed = 0;
while Instant::now() < deadline {
harness.dispatch(Some(step), &mut msgs).expect("dispatch");
for msg in &msgs[printed..] {
if let Msg::Volume(snap) = msg {
eprintln!(
"[bridge] +{:.1}s Msg::Volume: {snap:?}",
start.elapsed().as_secs_f32()
);
}
}
printed = msgs.len();
}
}