From d54aeaf005aba1d68fcaf1088ff66a444029cfc4 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Mon, 7 Sep 2020 17:32:23 -0500 Subject: [PATCH] chore: Rename methods to improve code clarity --- .gitignore | 3 ++- src/pomodoro.rs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 0f84cc9..bbe4492 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/.vscode \ No newline at end of file +/.vscode +/.idea \ No newline at end of file diff --git a/src/pomodoro.rs b/src/pomodoro.rs index 2e9ef87..e108509 100644 --- a/src/pomodoro.rs +++ b/src/pomodoro.rs @@ -15,8 +15,8 @@ pub struct Pomodoro { static POMODORO_CYCLES: u64 = 5; static WORK_TIME: u64 = 1500; // Default: 1500 (25min) -static SBREAK_TIME: u64 = 300; // Default: 300 (5min) -static LBREAK_TIME: u64 = 600; // Default: 600 (10min) +static SHORT_BREAK_TIME: u64 = 300; // Default: 300 (5min) +static LONG_BREAK_TIME: u64 = 600; // Default: 600 (10min) static POLLING_RATE: Duration = Duration::from_millis(300); impl Pomodoro { @@ -57,7 +57,7 @@ impl Pomodoro { } fn notify(&self) -> Result<(), Box> { - fn pmdr_cycle_count(i: u64) -> String { + fn cycle_count(i: u64) -> String { let i = i / 4; match i { 1 => "After this, you will have completed 1 cycle.".to_string(), @@ -65,7 +65,7 @@ impl Pomodoro { } } - fn work_sesh_num(i: u64) -> &'static str { + fn session_num(i: u64) -> &'static str { match i % 4 { 0 => "Time for your 1st work session.", 1 => "Time for your 2nd work session.", @@ -81,7 +81,7 @@ impl Pomodoro { State::Inactive => {} State::Work => { toast - .summary(work_sesh_num(self.count)) + .summary(session_num(self.count)) .body("Remember to stay focused.") .show()?; } @@ -94,7 +94,7 @@ impl Pomodoro { State::LongBreak => { toast .summary("Enjoy your long break!") - .body(&pmdr_cycle_count(self.count)) + .body(&cycle_count(self.count)) .show()?; } }; @@ -162,7 +162,7 @@ impl Pomodoro { let mut handle = out.lock(); // Empty String so that we can clear line before writing - // from the mostleft side of the terminal again. + // from the most-left side of the terminal again. handle.write_all(b"\r ")?; handle.write_all(text.as_bytes())?; handle.flush()?; @@ -213,8 +213,8 @@ impl Pomodoro { fn wait_times(state: State) -> Duration { match state { State::Work => Duration::from_secs(WORK_TIME), - State::ShortBreak => Duration::from_secs(SBREAK_TIME), - State::LongBreak => Duration::from_secs(LBREAK_TIME), + State::ShortBreak => Duration::from_secs(SHORT_BREAK_TIME), + State::LongBreak => Duration::from_secs(LONG_BREAK_TIME), _ => unreachable!("Can not have Pomodoro state = State::Inactive and wait_start = Some(...) at the same time.") } }