feat: better listing of timers
This commit is contained in:
parent
1a10f620b4
commit
739f76fa90
2 changed files with 20 additions and 4 deletions
|
@ -19,10 +19,11 @@ impl Display for Pomodoro {
|
|||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Pomodoro ({}, {}, {}) currently {} with {} remaining.\n",
|
||||
"Pomodoro ({}, {}, {}) currently {} {} with {} remaining.\n",
|
||||
humantime::format_duration(self.work),
|
||||
humantime::format_duration(self.pause),
|
||||
humantime::format_duration(self.long_pause),
|
||||
self.timer.state,
|
||||
self.status,
|
||||
humantime::format_duration(self.timer.remaining())
|
||||
)
|
||||
|
|
21
src/timer.rs
21
src/timer.rs
|
@ -11,7 +11,7 @@ pub struct Timer {
|
|||
#[serde(with = "approx_instant")]
|
||||
start: Instant,
|
||||
duration: Duration,
|
||||
state: State,
|
||||
pub state: State,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
|
@ -20,6 +20,16 @@ pub enum State {
|
|||
Paused,
|
||||
}
|
||||
|
||||
impl Display for State {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
let string = match self {
|
||||
State::Running => "running",
|
||||
State::Paused => "paused",
|
||||
};
|
||||
write!(f, "{}", string)
|
||||
}
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
/// Create a new [`Timer`] with the supplied name and duration
|
||||
/// The timer is instantly started.
|
||||
|
@ -72,10 +82,16 @@ impl Timer {
|
|||
|
||||
impl Display for Timer {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
let state_message = match self.state {
|
||||
State::Running => "has",
|
||||
State::Paused => "is paused and has",
|
||||
};
|
||||
|
||||
write!(
|
||||
f,
|
||||
"{} has {} remaining.",
|
||||
"'{}' {} {} remaining.",
|
||||
self.name,
|
||||
state_message,
|
||||
humantime::format_duration(self.remaining())
|
||||
)
|
||||
}
|
||||
|
@ -107,4 +123,3 @@ mod approx_instant {
|
|||
Ok(instant)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue