(pomodoro) count WORK rounds (#75)

This commit is contained in:
Jens Krause 2025-04-29 16:20:02 +02:00 committed by GitHub
parent 028a067419
commit 90d9988e7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 46 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 174 KiB

View File

@ -10,9 +10,8 @@ Set Padding 0
Set Margin 1 Set Margin 1
# --- START --- # --- START ---
Set LoopOffset 4
Hide Hide
Type "cargo run -- -r -d -m p" Type "cargo run -- -d -m p --blink on"
Enter Enter
Sleep 0.2 Sleep 0.2
Show Show
@ -25,7 +24,7 @@ Sleep 0.2
Down@30ms 80 Down@30ms 80
Sleep 100ms Sleep 100ms
Type "e" Type "e"
Sleep 3 Sleep 4
# --- POMODORO PAUSE --- # --- POMODORO PAUSE ---
Right Right
Sleep 0.5 Sleep 0.5
@ -36,4 +35,4 @@ Sleep 0.2
Down@30ms 60 Down@30ms 60
Sleep 100ms Sleep 100ms
Type "e" Type "e"
Sleep 3 Sleep 4

View File

@ -61,6 +61,7 @@ pub struct AppArgs {
pub app_time_format: AppTimeFormat, pub app_time_format: AppTimeFormat,
pub content: Content, pub content: Content,
pub pomodoro_mode: PomodoroMode, pub pomodoro_mode: PomodoroMode,
pub pomodoro_round: u64,
pub initial_value_work: Duration, pub initial_value_work: Duration,
pub current_value_work: Duration, pub current_value_work: Duration,
pub initial_value_pause: Duration, pub initial_value_pause: Duration,
@ -94,6 +95,7 @@ impl From<FromAppArgs> for App {
content: args.mode.unwrap_or(stg.content), content: args.mode.unwrap_or(stg.content),
style: args.style.unwrap_or(stg.style), style: args.style.unwrap_or(stg.style),
pomodoro_mode: stg.pomodoro_mode, pomodoro_mode: stg.pomodoro_mode,
pomodoro_round: stg.pomodoro_count,
initial_value_work: args.work.unwrap_or(stg.inital_value_work), initial_value_work: args.work.unwrap_or(stg.inital_value_work),
// invalidate `current_value_work` if an initial value is set via args // invalidate `current_value_work` if an initial value is set via args
current_value_work: args.work.unwrap_or(stg.current_value_work), current_value_work: args.work.unwrap_or(stg.current_value_work),
@ -142,6 +144,7 @@ impl App {
content, content,
with_decis, with_decis,
pomodoro_mode, pomodoro_mode,
pomodoro_round,
notification, notification,
blink, blink,
sound_path, sound_path,
@ -183,6 +186,7 @@ impl App {
initial_value_pause, initial_value_pause,
current_value_pause, current_value_pause,
with_decis, with_decis,
round: pomodoro_round,
app_tx: app_tx.clone(), app_tx: app_tx.clone(),
}), }),
footer: FooterState::new(show_menu, app_time_format), footer: FooterState::new(show_menu, app_time_format),
@ -359,6 +363,7 @@ impl App {
style: self.style, style: self.style,
with_decis: self.with_decis, with_decis: self.with_decis,
pomodoro_mode: self.pomodoro.get_mode().clone(), pomodoro_mode: self.pomodoro.get_mode().clone(),
pomodoro_count: self.pomodoro.get_round(),
inital_value_work: Duration::from(*self.pomodoro.get_clock_work().get_initial_value()), inital_value_work: Duration::from(*self.pomodoro.get_clock_work().get_initial_value()),
current_value_work: Duration::from(*self.pomodoro.get_clock_work().get_current_value()), current_value_work: Duration::from(*self.pomodoro.get_clock_work().get_current_value()),
inital_value_pause: Duration::from( inital_value_pause: Duration::from(

View File

@ -18,6 +18,7 @@ pub struct AppStorage {
pub style: Style, pub style: Style,
pub with_decis: bool, pub with_decis: bool,
pub pomodoro_mode: PomodoroMode, pub pomodoro_mode: PomodoroMode,
pub pomodoro_count: u64,
// pomodoro -> work // pomodoro -> work
pub inital_value_work: Duration, pub inital_value_work: Duration,
pub current_value_work: Duration, pub current_value_work: Duration,
@ -46,6 +47,7 @@ impl Default for AppStorage {
style: Style::default(), style: Style::default(),
with_decis: false, with_decis: false,
pomodoro_mode: PomodoroMode::Work, pomodoro_mode: PomodoroMode::Work,
pomodoro_count: 1,
// pomodoro -> work // pomodoro -> work
inital_value_work: DEFAULT_WORK, inital_value_work: DEFAULT_WORK,
current_value_work: DEFAULT_WORK, current_value_work: DEFAULT_WORK,

View File

@ -149,21 +149,25 @@ impl StatefulWidget for Footer {
}), }),
Span::from(SPACE), Span::from(SPACE),
Span::from("[r]eset"), Span::from("[r]eset"),
];
if self.selected_content == Content::Pomodoro {
spans.extend_from_slice(&[
Span::from(SPACE),
Span::from("[^r]eset round"),
Span::from(SPACE),
Span::from("[← →]switch work/pause"),
]);
}
spans.extend_from_slice(&[
Span::from(SPACE), Span::from(SPACE),
Span::from("[e]dit"), Span::from("[e]dit"),
]; ]);
if self.selected_content == Content::Countdown { if self.selected_content == Content::Countdown {
spans.extend_from_slice(&[ spans.extend_from_slice(&[
Span::from(SPACE), Span::from(SPACE),
Span::from("[^e]dit by local time"), Span::from("[^e]dit by local time"),
]); ]);
} }
if self.selected_content == Content::Pomodoro {
spans.extend_from_slice(&[
Span::from(SPACE),
Span::from("[← →]switch work/pause"),
]);
}
spans spans
} }
others => vec![ others => vec![

View File

@ -5,6 +5,7 @@ use crate::{
utils::center, utils::center,
widgets::clock::{ClockState, ClockStateArgs, ClockWidget, Countdown}, widgets::clock::{ClockState, ClockStateArgs, ClockWidget, Countdown},
}; };
use crossterm::event::KeyModifiers;
use ratatui::{ use ratatui::{
buffer::Buffer, buffer::Buffer,
crossterm::event::KeyCode, crossterm::event::KeyCode,
@ -45,6 +46,7 @@ impl ClockMap {
pub struct PomodoroState { pub struct PomodoroState {
mode: Mode, mode: Mode,
clock_map: ClockMap, clock_map: ClockMap,
round: u64,
} }
pub struct PomodoroStateArgs { pub struct PomodoroStateArgs {
@ -55,6 +57,7 @@ pub struct PomodoroStateArgs {
pub current_value_pause: Duration, pub current_value_pause: Duration,
pub with_decis: bool, pub with_decis: bool,
pub app_tx: AppEventTx, pub app_tx: AppEventTx,
pub round: u64,
} }
impl PomodoroState { impl PomodoroState {
@ -67,6 +70,7 @@ impl PomodoroState {
current_value_pause, current_value_pause,
with_decis, with_decis,
app_tx, app_tx,
round,
} = args; } = args;
Self { Self {
mode, mode,
@ -88,6 +92,7 @@ impl PomodoroState {
}) })
.with_name("Pause".to_owned()), .with_name("Pause".to_owned()),
}, },
round,
} }
} }
@ -111,6 +116,10 @@ impl PomodoroState {
&self.mode &self.mode
} }
pub fn get_round(&self) -> u64 {
self.round
}
pub fn set_with_decis(&mut self, with_decis: bool) { pub fn set_with_decis(&mut self, with_decis: bool) {
self.clock_map.work.with_decis = with_decis; self.clock_map.work.with_decis = with_decis;
self.clock_map.pause.with_decis = with_decis; self.clock_map.pause.with_decis = with_decis;
@ -158,7 +167,14 @@ impl TuiEventHandler for PomodoroState {
KeyCode::Down if edit_mode => { KeyCode::Down if edit_mode => {
self.get_clock_mut().edit_down(); self.get_clock_mut().edit_down();
} }
KeyCode::Char('r') if key.modifiers.contains(KeyModifiers::CONTROL) => {
self.round = 1;
}
KeyCode::Char('r') => { KeyCode::Char('r') => {
// count number of finished rounds of WORK before resetting the clock
if self.get_mode() == &Mode::Work && self.get_clock().is_done() {
self.round += 1;
}
self.get_clock_mut().reset(); self.get_clock_mut().reset();
} }
_ => return Some(event), _ => return Some(event),
@ -186,6 +202,7 @@ impl StatefulWidget for PomodoroWidget {
)) ))
.to_uppercase(), .to_uppercase(),
); );
let label_round = Line::raw((format!("round {}", state.get_round(),)).to_uppercase());
let area = center( let area = center(
area, area,
@ -196,13 +213,18 @@ impl StatefulWidget for PomodoroWidget {
), ),
label.width() as u16, label.width() as u16,
)), )),
Constraint::Length(clock_widget.get_height() + 1 /* height of mode_str */), Constraint::Length(
// height of `label` + `label_round`
clock_widget.get_height() + 2,
),
); );
let [v1, v2] = let [v1, v2, v3] =
Layout::vertical(Constraint::from_lengths([clock_widget.get_height(), 1])).areas(area); Layout::vertical(Constraint::from_lengths([clock_widget.get_height(), 1, 1]))
.areas(area);
clock_widget.render(v1, buf, state.get_clock_mut()); clock_widget.render(v1, buf, state.get_clock_mut());
label.centered().render(v2, buf); label.centered().render(v2, buf);
label_round.centered().render(v3, buf);
} }
} }