10 个重大版本发布
0.13.0 | 2023 年 5 月 5 日 |
---|---|
0.12.0 | 2023 年 3 月 26 日 |
0.11.0 | 2023 年 3 月 14 日 |
0.9.0 | 2022 年 12 月 30 日 |
0.7.0 | 2022 年 11 月 19 日 |
#18 in #pomodoro-timer
109 个月下载量
在 zentime-rs 中使用
38KB
812 行
zentime-rs-timer
zentime-rs 的计时器组件
lib.rs
:
可以切换到各种状态([暂停]/[运行])的番茄/生产力计时器,跟踪间隔并可以配置。
示例
use std::sync::mpsc::{self, RecvTimeoutError};
use std::sync::mpsc::{Receiver, Sender};
use std::thread;
use std::rc::Rc;
use std::time::Duration;
use zentime_rs_timer::config::PomodoroTimerConfig;
use zentime_rs_timer::pomodoro_timer_action::PomodoroTimerAction;
use zentime_rs_timer::pomodoro_timer::{ PomodoroTimer, TimerKind, ViewState };
let (terminal_input_sender, terminal_input_receiver): (Sender<PomodoroTimerAction>, Receiver<PomodoroTimerAction>) =
mpsc::channel();
let (view_sender, view_receiver): (Sender<ViewState>, Receiver<ViewState>) =
mpsc::channel();
let config = PomodoroTimerConfig::default();
// Run timer in its own thread so it does not block the current one
thread::spawn(move || {
let timer = PomodoroTimer::new(
config,
Rc::new(move |state, msg, _| {
println!("{} {}", state.round, msg.unwrap());
}),
Rc::new(move |view_state| -> Option<PomodoroTimerAction> {
view_sender.send(view_state).unwrap();
let input = terminal_input_receiver.recv_timeout(Duration::from_millis(100));
match input {
Ok(action) => Some(action),
Err(RecvTimeoutError::Disconnected) => std::process::exit(0),
_ => None,
}
}),
);
timer.init();
});
let action_jh = thread::spawn(move || {
// Start the timer
terminal_input_sender.send(PomodoroTimerAction::PlayPause).unwrap();
// Render current timer state three seconds in a row
for _ in 0..3 {
thread::sleep(Duration::from_millis(100));
if let Ok(state) = view_receiver.recv() {
println!("{}", state.time)
}
}
# std::process::exit(0);
});
action_jh.join().unwrap();
依赖项
~0.4–1MB
~23K SLoC