Skip to content

Commit fb926d4

Browse files
committed
refactor: use Display trait instead of custom println
1 parent 8b4d364 commit fb926d4

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/cli.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::fmt::Display;
33
use std::fs::File;
44
use std::process::Command as ProcessCommand;
55

6-
use chrono_humanize::HumanTime;
76
use clap::{Parser, Subcommand};
87

98
use crate::common::NonEmptyString;
@@ -303,12 +302,7 @@ impl<T: FrameStore> CommandExecutor<T> {
303302
match self.frame_store.get_ongoing_frame() {
304303
None => Err(CliError::NoOngoingRecording),
305304
Some(frame) => {
306-
println!(
307-
"Project {} started {}, ({})",
308-
frame.project(),
309-
HumanTime::from(*frame.start()),
310-
frame.start()
311-
);
305+
println!("{}", frame);
312306
Ok(())
313307
}
314308
}

src/frame.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
use std::hash::{DefaultHasher, Hasher};
1+
use std::{
2+
fmt::Display,
3+
hash::{DefaultHasher, Hasher},
4+
};
25

36
use chrono::{DateTime, Local, TimeZone};
7+
use chrono_humanize::HumanTime;
48

59
use crate::{
610
common::NonEmptyString,
@@ -107,6 +111,18 @@ impl Frame {
107111
}
108112
}
109113

114+
impl Display for Frame {
115+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
116+
write!(
117+
f,
118+
"Project {} started {} ({})",
119+
self.project,
120+
HumanTime::from(self.start),
121+
self.start
122+
)
123+
}
124+
}
125+
110126
/// Represents a completed frame.
111127
/// A completed frame is guaranteed to have an end time.
112128
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)