zentime_rs_timer/lib.rs
1#![warn(
2 missing_docs,
3 missing_copy_implementations,
4 missing_debug_implementations
5)]
6
7//! Pomodoro/Productivity timer that can transition between various states ([Paused]/[Running]),
8//! tracks intervals and can be configured.
9//!
10//! ## Example
11//!
12//! ```
13//! use std::sync::mpsc::{self, RecvTimeoutError};
14//! use std::sync::mpsc::{Receiver, Sender};
15//! use std::thread;
16//! use std::rc::Rc;
17//! use std::time::Duration;
18//! use zentime_rs_timer::config::PomodoroTimerConfig;
19//! use zentime_rs_timer::pomodoro_timer_action::PomodoroTimerAction;
20//! use zentime_rs_timer::pomodoro_timer::{ PomodoroTimer, TimerKind, ViewState };
21//!
22//! let (terminal_input_sender, terminal_input_receiver): (Sender<PomodoroTimerAction>, Receiver<PomodoroTimerAction>) =
23//! mpsc::channel();
24//! let (view_sender, view_receiver): (Sender<ViewState>, Receiver<ViewState>) =
25//! mpsc::channel();
26//!
27//! let config = PomodoroTimerConfig::default();
28//!
29//! // Run timer in its own thread so it does not block the current one
30//! thread::spawn(move || {
31//! let timer = PomodoroTimer::new(
32//! config,
33//! Rc::new(move |state, msg, _| {
34//! println!("{} {}", state.round, msg.unwrap());
35//! }),
36//! Rc::new(move |view_state| -> Option<PomodoroTimerAction> {
37//! view_sender.send(view_state).unwrap();
38//!
39//! let input = terminal_input_receiver.recv_timeout(Duration::from_millis(100));
40//!
41//! match input {
42//! Ok(action) => Some(action),
43//! Err(RecvTimeoutError::Disconnected) => std::process::exit(0),
44//! _ => None,
45//! }
46//! }),
47//! );
48//!
49//! timer.init();
50//! });
51//!
52//! let action_jh = thread::spawn(move || {
53//! // Start the timer
54//! terminal_input_sender.send(PomodoroTimerAction::PlayPause).unwrap();
55//!
56//! // Render current timer state three seconds in a row
57//! for _ in 0..3 {
58//! thread::sleep(Duration::from_millis(100));
59//! if let Ok(state) = view_receiver.recv() {
60//! println!("{}", state.time)
61//! }
62//! }
63//!
64//! # std::process::exit(0);
65//! });
66//!
67//! action_jh.join().unwrap();
68//! ```
69
70pub use timer::Timer;
71pub use timer_action::TimerAction;
72
73pub mod config;
74pub mod pomodoro_timer;
75pub mod pomodoro_timer_action;
76pub mod timer;
77pub mod timer_action;
78pub mod util;