Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c370d3096b | ||
|
|
aae5c38cd6 | ||
|
|
5ad09b9848 | ||
|
|
52ed8267be | ||
|
|
6b068bbd09 | ||
|
|
c96432779a | ||
|
|
509cf73cdd | ||
|
|
e6291a3131 | ||
|
|
90d9988e7a | ||
|
|
028a067419 |
18
CHANGELOG.md
18
CHANGELOG.md
@@ -1,6 +1,22 @@
|
||||
# Changelog
|
||||
|
||||
## [Unreleased]
|
||||
## v1.3.0 - 2025-05-06
|
||||
|
||||
### Features
|
||||
|
||||
- (pomodoro) Count WORK rounds [#75](https://github.com/sectore/timr-tui/pull/75), [6b068bb](https://github.com/sectore/timr-tui/commit/6b068bbd094d9ec1a36b47598fadfc71296d9590)
|
||||
- (pomodoro/countdown) Change initial value [#79](https://github.com/sectore/timr-tui/pull/79), [aae5c38](https://github.com/sectore/timr-tui/commit/aae5c38cd6a666d5ba418b12fb67879a2146b9a2)
|
||||
|
||||
### Changes
|
||||
|
||||
- Update keybindings [#76](https://github.com/sectore/timr-tui/pull/76)
|
||||
|
||||
### Misc.
|
||||
|
||||
- (flake) use alsa-lib-with-plugins [#77](https://github.com/sectore/timr-tui/pull/77)
|
||||
- (readme) add keybindings + toc [#78](https://github.com/sectore/timr-tui/pull/78)
|
||||
|
||||
## v1.2.1 - 2025-04-17
|
||||
|
||||
### Fixes
|
||||
|
||||
|
||||
581
Cargo.lock
generated
581
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "timr-tui"
|
||||
version = "1.2.0"
|
||||
version = "1.3.0"
|
||||
description = "TUI to organize your time: Pomodoro, Countdown, Timer."
|
||||
edition = "2024"
|
||||
# Reminder: Always keep `channel` in `rust-toolchain.toml` in sync with `rust-version`.
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Jens K.
|
||||
Copyright (c) 2024-2025 Jens Krause
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
77
README.md
77
README.md
@@ -8,9 +8,20 @@ TUI to organize your time: Pomodoro, Countdown, Timer.
|
||||
|
||||
Built with [Ratatui](https://ratatui.rs/) / [Rust 🦀](https://www.rust-lang.org/).
|
||||
|
||||
# Features
|
||||
|
||||
_Side note:_ Theme colors depend on your terminal preferences.
|
||||
# Table of Contents
|
||||
|
||||
- [Preview](./#preview)
|
||||
- [CLI](./#cli)
|
||||
- [Keybindings](./#keybindings)
|
||||
- [Installation](./#installation)
|
||||
- [Development](./#development)
|
||||
- [Misc](./#misc)
|
||||
- [License](./#license)
|
||||
|
||||
# Preview
|
||||
|
||||
_(theme depends on your terminal preferences)_
|
||||
|
||||
## Pomodoro
|
||||
|
||||
@@ -89,6 +100,64 @@ Extra option (if `--features sound` is enabled by local build only):
|
||||
--sound <SOUND> Path to sound file (.mp3 or .wav) to play as notification. Experimental.
|
||||
```
|
||||
|
||||
# Keybindings
|
||||
|
||||
## Menu
|
||||
|
||||
| Key | Description |
|
||||
| --- | --- |
|
||||
| <kbd>↑</kbd> / <kbd>↓</kbd> or <kbd>m</kbd> | Toggle menu |
|
||||
|
||||
## Screens
|
||||
|
||||
| Key | Description |
|
||||
| --- | --- |
|
||||
| <kbd>p</kbd> | Pomodoro |
|
||||
| <kbd>c</kbd> | Countdown |
|
||||
| <kbd>t</kbd> | Timer |
|
||||
|
||||
## Controls
|
||||
|
||||
| Key | Description |
|
||||
| --- | --- |
|
||||
| <kbd>s</kbd> | start |
|
||||
| <kbd>r</kbd> | reset |
|
||||
| <kbd>e</kbd> | enter edit mode |
|
||||
| <kbd>q</kbd> | quit |
|
||||
|
||||
**In `edit` mode only:**
|
||||
|
||||
| Key | Description |
|
||||
| --- | --- |
|
||||
| <kbd>s</kbd> | save changes |
|
||||
| <kbd>Esc</kbd> | skip changes |
|
||||
| <kbd>←</kbd> or <kbd>→</kbd> | change selection |
|
||||
| <kbd>↑</kbd> | edit to go up |
|
||||
| <kbd>↓</kbd> | edit to go down |
|
||||
|
||||
**In `Pomodoro` screen only**
|
||||
|
||||
| Key | Description |
|
||||
| --- | --- |
|
||||
| <kbd>←</kbd> or <kbd>→</kbd> | switch work/pause |
|
||||
| <kbd>^r</kbd> | reset round |
|
||||
| <kbd>^s</kbd> | save initial value |
|
||||
|
||||
**In `Countdown` screen only:**
|
||||
|
||||
| Key | Description |
|
||||
| --- | --- |
|
||||
| <kbd>^e</kbd> | edit by local time |
|
||||
| <kbd>^s</kbd> | save initial value |
|
||||
|
||||
## Appearance
|
||||
|
||||
| Key | Description |
|
||||
| --- | --- |
|
||||
| <kbd>,</kbd> | toggle styles |
|
||||
| <kbd>.</kbd> | toggle deciseconds |
|
||||
| <kbd>:</kbd> | toggle local time in footer |
|
||||
|
||||
# Installation
|
||||
|
||||
## Cargo
|
||||
@@ -224,3 +293,7 @@ C:/Users/{user}/AppData/Local/timr-tui/logs/app.log
|
||||
```
|
||||
|
||||
Optional: You can use a custom directory by passing it via `--log` arg.
|
||||
|
||||
# License
|
||||
|
||||
[MIT License](./LICENSE)
|
||||
|
||||
BIN
demo/menu.gif
BIN
demo/menu.gif
Binary file not shown.
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 130 KiB |
@@ -12,19 +12,15 @@ Set Margin 1
|
||||
# --- START ---
|
||||
Set LoopOffset 4
|
||||
Hide
|
||||
Type "cargo run -- -r -m p"
|
||||
Type "cargo run -- -r -m p --menu"
|
||||
Enter
|
||||
Sleep 0.2
|
||||
Type@200ms "m"
|
||||
Show
|
||||
# --- STYLES ---
|
||||
Sleep 0.5
|
||||
Type "m"
|
||||
Sleep 0.5
|
||||
Type@0.5s "t"
|
||||
Type@0.5s "c"
|
||||
Type@0.5s "p"
|
||||
Type@0.5s "e"
|
||||
Right@0.5s
|
||||
Left@0.5s
|
||||
Type@0.5s "e"
|
||||
Sleep 0.5
|
||||
Sleep 0.3s
|
||||
Type@0.3s "m"
|
||||
Type@0.3s "t"
|
||||
Type@0.3s "c"
|
||||
Type@0.3s "p"
|
||||
Type@0.3s "e"
|
||||
Escape@0.3s
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 174 KiB |
@@ -10,9 +10,8 @@ Set Padding 0
|
||||
Set Margin 1
|
||||
|
||||
# --- START ---
|
||||
Set LoopOffset 4
|
||||
Hide
|
||||
Type "cargo run -- -r -d -m p"
|
||||
Type "cargo run -- -d -m p --blink on"
|
||||
Enter
|
||||
Sleep 0.2
|
||||
Show
|
||||
@@ -25,7 +24,7 @@ Sleep 0.2
|
||||
Down@30ms 80
|
||||
Sleep 100ms
|
||||
Type "e"
|
||||
Sleep 3
|
||||
Sleep 4
|
||||
# --- POMODORO PAUSE ---
|
||||
Right
|
||||
Sleep 0.5
|
||||
@@ -36,4 +35,4 @@ Sleep 0.2
|
||||
Down@30ms 60
|
||||
Sleep 100ms
|
||||
Type "e"
|
||||
Sleep 3
|
||||
Sleep 4
|
||||
|
||||
24
flake.lock
generated
24
flake.lock
generated
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"locked": {
|
||||
"lastModified": 1744386647,
|
||||
"narHash": "sha256-DXwQEJllxpYeVOiSlBhQuGjfvkoGHTtILLYO2FvcyzQ=",
|
||||
"lastModified": 1745454774,
|
||||
"narHash": "sha256-oLvmxOnsEKGtwczxp/CwhrfmQUG2ym24OMWowcoRhH8=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "d02c1cdd7ec539699aa44e6ff912e15535969803",
|
||||
"rev": "efd36682371678e2b6da3f108fdb5c613b3ec598",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -23,11 +23,11 @@
|
||||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1744231114,
|
||||
"narHash": "sha256-60gLl2rJFt6SRwqWimsTAeHgfsIE1iV0zChdJFOvx8w=",
|
||||
"lastModified": 1745995211,
|
||||
"narHash": "sha256-hf6Xu3KS06WyE/3dqV96iLGx3jIYQq9e68iCEFHrt04=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "0ccfe532b1433da8e5a23cd513ff6847e0f6a8c2",
|
||||
"rev": "0db04339c4e4c0fd42dbbaebe3590a67cbd12aa3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -56,11 +56,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1744463964,
|
||||
"narHash": "sha256-LWqduOgLHCFxiTNYi3Uj5Lgz0SR+Xhw3kr/3Xd0GPTM=",
|
||||
"lastModified": 1745930157,
|
||||
"narHash": "sha256-y3h3NLnzRSiUkYpnfvnS669zWZLoqqI6NprtLQ+5dck=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2631b0b7abcea6e640ce31cd78ea58910d31e650",
|
||||
"rev": "46e634be05ce9dc6d4db8e664515ba10b78151ae",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -81,11 +81,11 @@
|
||||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1742296961,
|
||||
"narHash": "sha256-gCpvEQOrugHWLimD1wTFOJHagnSEP6VYBDspq96Idu0=",
|
||||
"lastModified": 1745949276,
|
||||
"narHash": "sha256-9ZK31t2HUiGdLLnDafrRnSrrO12JwqcAFbrJ9nRwh0Y=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "15d87419f1a123d8f888d608129c3ce3ff8f13d4",
|
||||
"rev": "78a488dd5e7e4f17162001519665795e6e68b6f8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
10
flake.nix
10
flake.nix
@@ -88,16 +88,12 @@
|
||||
# some extra pkgs needed to play sound on Linux
|
||||
++ lib.optionals stdenv.isLinux [
|
||||
pkgs.pkg-config
|
||||
pkgs.alsa-lib.dev
|
||||
pkgs.pipewire
|
||||
(pkgs.alsa-lib-with-plugins.override {
|
||||
plugins = [pkgs.alsa-plugins pkgs.pipewire];
|
||||
})
|
||||
];
|
||||
|
||||
inherit (commonArgs) src;
|
||||
|
||||
ALSA_PLUGIN_DIR =
|
||||
if stdenv.isLinux
|
||||
then "${pkgs.pipewire}/lib/alsa-lib/"
|
||||
else "";
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ pub struct AppArgs {
|
||||
pub app_time_format: AppTimeFormat,
|
||||
pub content: Content,
|
||||
pub pomodoro_mode: PomodoroMode,
|
||||
pub pomodoro_round: u64,
|
||||
pub initial_value_work: Duration,
|
||||
pub current_value_work: Duration,
|
||||
pub initial_value_pause: Duration,
|
||||
@@ -94,6 +95,7 @@ impl From<FromAppArgs> for App {
|
||||
content: args.mode.unwrap_or(stg.content),
|
||||
style: args.style.unwrap_or(stg.style),
|
||||
pomodoro_mode: stg.pomodoro_mode,
|
||||
pomodoro_round: stg.pomodoro_count,
|
||||
initial_value_work: args.work.unwrap_or(stg.inital_value_work),
|
||||
// invalidate `current_value_work` if an initial value is set via args
|
||||
current_value_work: args.work.unwrap_or(stg.current_value_work),
|
||||
@@ -142,6 +144,7 @@ impl App {
|
||||
content,
|
||||
with_decis,
|
||||
pomodoro_mode,
|
||||
pomodoro_round,
|
||||
notification,
|
||||
blink,
|
||||
sound_path,
|
||||
@@ -183,6 +186,7 @@ impl App {
|
||||
initial_value_pause,
|
||||
current_value_pause,
|
||||
with_decis,
|
||||
round: pomodoro_round,
|
||||
app_tx: app_tx.clone(),
|
||||
}),
|
||||
footer: FooterState::new(show_menu, app_time_format),
|
||||
@@ -198,7 +202,7 @@ impl App {
|
||||
let handle_key_event = |app: &mut Self, key: KeyEvent| {
|
||||
debug!("Received key {:?}", key.code);
|
||||
match key.code {
|
||||
KeyCode::Char('q') | KeyCode::Esc => app.mode = Mode::Quit,
|
||||
KeyCode::Char('q') => app.mode = Mode::Quit,
|
||||
KeyCode::Char('c') => app.content = Content::Countdown,
|
||||
KeyCode::Char('t') => app.content = Content::Timer,
|
||||
KeyCode::Char('p') => app.content = Content::Pomodoro,
|
||||
@@ -359,6 +363,7 @@ impl App {
|
||||
style: self.style,
|
||||
with_decis: self.with_decis,
|
||||
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()),
|
||||
current_value_work: Duration::from(*self.pomodoro.get_clock_work().get_current_value()),
|
||||
inital_value_pause: Duration::from(
|
||||
@@ -409,7 +414,7 @@ impl StatefulWidget for AppWidget {
|
||||
let [v0, v1, v2] = Layout::vertical([
|
||||
Constraint::Length(1),
|
||||
Constraint::Percentage(100),
|
||||
Constraint::Length(if state.footer.get_show_menu() { 4 } else { 1 }),
|
||||
Constraint::Length(if state.footer.get_show_menu() { 5 } else { 1 }),
|
||||
])
|
||||
.areas(area);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ pub struct AppStorage {
|
||||
pub style: Style,
|
||||
pub with_decis: bool,
|
||||
pub pomodoro_mode: PomodoroMode,
|
||||
pub pomodoro_count: u64,
|
||||
// pomodoro -> work
|
||||
pub inital_value_work: Duration,
|
||||
pub current_value_work: Duration,
|
||||
@@ -46,6 +47,7 @@ impl Default for AppStorage {
|
||||
style: Style::default(),
|
||||
with_decis: false,
|
||||
pomodoro_mode: PomodoroMode::Work,
|
||||
pomodoro_count: 1,
|
||||
// pomodoro -> work
|
||||
inital_value_work: DEFAULT_WORK,
|
||||
current_value_work: DEFAULT_WORK,
|
||||
|
||||
@@ -74,6 +74,7 @@ pub struct ClockState<T> {
|
||||
name: Option<String>,
|
||||
initial_value: DurationEx,
|
||||
current_value: DurationEx,
|
||||
prev_value: DurationEx,
|
||||
tick_value: DurationEx,
|
||||
mode: Mode,
|
||||
format: Format,
|
||||
@@ -142,6 +143,10 @@ impl<T> ClockState<T> {
|
||||
&self.initial_value
|
||||
}
|
||||
|
||||
pub fn set_initial_value(&mut self, duration: DurationEx) {
|
||||
self.initial_value = duration;
|
||||
}
|
||||
|
||||
pub fn get_current_value(&self) -> &DurationEx {
|
||||
&self.current_value
|
||||
}
|
||||
@@ -151,14 +156,18 @@ impl<T> ClockState<T> {
|
||||
self.update_format();
|
||||
}
|
||||
|
||||
pub fn get_prev_value(&self) -> &DurationEx {
|
||||
&self.prev_value
|
||||
}
|
||||
|
||||
pub fn toggle_edit(&mut self) {
|
||||
self.mode = match self.mode.clone() {
|
||||
Mode::Editable(_, prev) => {
|
||||
let p = *prev;
|
||||
// special cases: Should `Mode` be updated?
|
||||
// 1. `Done` -> `Initial` ?
|
||||
// Update `Mode`
|
||||
// 1. `Done` -> `Pause`
|
||||
if p == Mode::Done && self.current_value.gt(&Duration::ZERO.into()) {
|
||||
Mode::Initial
|
||||
Mode::Pause
|
||||
}
|
||||
// 2. `_` -> `Done` ?
|
||||
else if p != Mode::Done && self.current_value.eq(&Duration::ZERO.into()) {
|
||||
@@ -170,6 +179,8 @@ impl<T> ClockState<T> {
|
||||
}
|
||||
}
|
||||
mode => {
|
||||
// store prev. value
|
||||
self.prev_value = self.current_value;
|
||||
if self.format <= Format::Ss {
|
||||
Mode::Editable(Time::Seconds, Box::new(mode))
|
||||
} else {
|
||||
@@ -402,6 +413,7 @@ impl ClockState<Countdown> {
|
||||
name: None,
|
||||
initial_value: initial_value.into(),
|
||||
current_value: current_value.into(),
|
||||
prev_value: current_value.into(),
|
||||
tick_value: tick_value.into(),
|
||||
mode: if current_value == Duration::ZERO {
|
||||
Mode::Done
|
||||
@@ -475,6 +487,7 @@ impl ClockState<Timer> {
|
||||
name: None,
|
||||
initial_value: initial_value.into(),
|
||||
current_value: current_value.into(),
|
||||
prev_value: current_value.into(),
|
||||
tick_value: tick_value.into(),
|
||||
mode: if current_value == initial_value {
|
||||
Mode::Initial
|
||||
|
||||
@@ -162,6 +162,96 @@ impl TuiEventHandler for CountdownState {
|
||||
edit_time.set_max_time(max_time);
|
||||
}
|
||||
}
|
||||
// EDIT CLOCK mode
|
||||
TuiEvent::Key(key) if self.is_clock_edit_mode() => match key.code {
|
||||
// skip editing
|
||||
KeyCode::Esc => {
|
||||
// Important: set current value first
|
||||
self.clock.set_current_value(*self.clock.get_prev_value());
|
||||
// before toggling back to non-edit mode
|
||||
self.clock.toggle_edit();
|
||||
}
|
||||
// Apply changes and set new initial value
|
||||
KeyCode::Char('s') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
// toggle edit mode
|
||||
self.clock.toggle_edit();
|
||||
// set initial value
|
||||
self.clock
|
||||
.set_initial_value(*self.clock.get_current_value());
|
||||
// always reset `elapsed_clock`
|
||||
self.elapsed_clock.reset();
|
||||
}
|
||||
// Apply changes
|
||||
KeyCode::Char('s') => {
|
||||
// toggle edit mode
|
||||
self.clock.toggle_edit();
|
||||
// always reset `elapsed_clock`
|
||||
self.elapsed_clock.reset();
|
||||
}
|
||||
KeyCode::Right => {
|
||||
self.clock.edit_prev();
|
||||
}
|
||||
KeyCode::Left => {
|
||||
self.clock.edit_next();
|
||||
}
|
||||
KeyCode::Up => {
|
||||
self.clock.edit_up();
|
||||
}
|
||||
KeyCode::Down => {
|
||||
self.clock.edit_down();
|
||||
}
|
||||
_ => return Some(event),
|
||||
},
|
||||
// EDIT LOCAL TIME mode
|
||||
TuiEvent::Key(key) if self.is_time_edit_mode() => match key.code {
|
||||
// skip editing
|
||||
KeyCode::Esc => {
|
||||
self.edit_time = None;
|
||||
}
|
||||
// Apply changes and set new initial value
|
||||
KeyCode::Char('s') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
if let Some(edit_time) = &mut self.edit_time.clone() {
|
||||
// Order matters:
|
||||
// 1. update current value
|
||||
self.edit_time_done(edit_time);
|
||||
// 2. set initial value
|
||||
self.clock
|
||||
.set_initial_value(*self.clock.get_current_value());
|
||||
}
|
||||
// always reset `elapsed_clock`
|
||||
self.elapsed_clock.reset();
|
||||
}
|
||||
// Apply changes of editing by local time
|
||||
KeyCode::Char('s') => {
|
||||
if let Some(edit_time) = &mut self.edit_time.clone() {
|
||||
self.edit_time_done(edit_time)
|
||||
}
|
||||
// always reset `elapsed_clock`
|
||||
self.elapsed_clock.reset();
|
||||
}
|
||||
// move edit position to the left
|
||||
KeyCode::Left => {
|
||||
// safe unwrap because we are in `is_time_edit_mode`
|
||||
self.edit_time.as_mut().unwrap().next();
|
||||
}
|
||||
// move edit position to the right
|
||||
KeyCode::Right => {
|
||||
// safe unwrap because we are in `is_time_edit_mode`
|
||||
self.edit_time.as_mut().unwrap().prev();
|
||||
}
|
||||
// Value up
|
||||
KeyCode::Up => {
|
||||
// safe unwrap because of previous check in `is_time_edit_mode`
|
||||
self.edit_time.as_mut().unwrap().up();
|
||||
}
|
||||
// Value down
|
||||
KeyCode::Down => {
|
||||
// safe unwrap because of previous check in `is_time_edit_mode`
|
||||
self.edit_time.as_mut().unwrap().down();
|
||||
}
|
||||
_ => return Some(event),
|
||||
},
|
||||
// default mode
|
||||
TuiEvent::Key(key) => match key.code {
|
||||
KeyCode::Char('r') => {
|
||||
// reset both clocks to use intial values
|
||||
@@ -187,64 +277,29 @@ impl TuiEventHandler for CountdownState {
|
||||
self.edit_time_done(edit_time);
|
||||
}
|
||||
}
|
||||
// STRG + e => toggle edit time
|
||||
// Enter edit by local time mode
|
||||
KeyCode::Char('e') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
// reset both clocks
|
||||
self.clock.reset();
|
||||
self.elapsed_clock.reset();
|
||||
|
||||
if let Some(edit_time) = &mut self.edit_time.clone() {
|
||||
self.edit_time_done(edit_time)
|
||||
} else {
|
||||
// update `edit_time`
|
||||
// set `edit_time`
|
||||
self.edit_time = Some(EditTimeState::new(EditTimeStateArgs {
|
||||
time: self.time_to_edit(),
|
||||
min: self.min_time_to_edit(),
|
||||
max: self.max_time_to_edit(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
// e => toggle edit clock
|
||||
KeyCode::Char('e') => {
|
||||
// toggle edit mode
|
||||
self.clock.toggle_edit();
|
||||
|
||||
// stop `elapsed_clock`
|
||||
// pause `elapsed_clock`
|
||||
if self.elapsed_clock.is_running() {
|
||||
self.elapsed_clock.toggle_pause();
|
||||
}
|
||||
}
|
||||
KeyCode::Left if self.is_clock_edit_mode() => {
|
||||
self.clock.edit_next();
|
||||
// Enter edit clock mode
|
||||
KeyCode::Char('e') => {
|
||||
// toggle edit mode
|
||||
self.clock.toggle_edit();
|
||||
|
||||
// pause `elapsed_clock`
|
||||
if self.elapsed_clock.is_running() {
|
||||
self.elapsed_clock.toggle_pause();
|
||||
}
|
||||
KeyCode::Left if self.is_time_edit_mode() => {
|
||||
// safe unwrap because of previous check in `is_time_edit_mode`
|
||||
self.edit_time.as_mut().unwrap().next();
|
||||
}
|
||||
KeyCode::Right if self.is_clock_edit_mode() => {
|
||||
self.clock.edit_prev();
|
||||
}
|
||||
KeyCode::Right if self.is_time_edit_mode() => {
|
||||
// safe unwrap because of previous check in `is_time_edit_mode`
|
||||
self.edit_time.as_mut().unwrap().prev();
|
||||
}
|
||||
KeyCode::Up if self.is_clock_edit_mode() => {
|
||||
self.clock.edit_up();
|
||||
// whenever `clock`'s value is changed, reset `elapsed_clock`
|
||||
self.elapsed_clock.reset();
|
||||
}
|
||||
KeyCode::Up if self.is_time_edit_mode() => {
|
||||
// safe unwrap because of previous check in `is_time_edit_mode`
|
||||
self.edit_time.as_mut().unwrap().up();
|
||||
}
|
||||
KeyCode::Down if self.is_clock_edit_mode() => {
|
||||
self.clock.edit_down();
|
||||
// whenever clock value is changed, reset timer
|
||||
self.elapsed_clock.reset();
|
||||
}
|
||||
KeyCode::Down if self.is_time_edit_mode() => {
|
||||
// safe unwrap because of previous check in `is_time_edit_mode`
|
||||
self.edit_time.as_mut().unwrap().down();
|
||||
}
|
||||
_ => return Some(event),
|
||||
},
|
||||
|
||||
@@ -104,7 +104,7 @@ impl StatefulWidget for Footer {
|
||||
let widths = [Constraint::Length(12), Constraint::Percentage(100)];
|
||||
let table = Table::new(
|
||||
[
|
||||
// content
|
||||
// screens
|
||||
Row::new(vec![
|
||||
Cell::from(Span::styled(
|
||||
"screens",
|
||||
@@ -112,7 +112,7 @@ impl StatefulWidget for Footer {
|
||||
)),
|
||||
Cell::from(Line::from(content_labels)),
|
||||
]),
|
||||
// format
|
||||
// appearance
|
||||
Row::new(vec![
|
||||
Cell::from(Span::styled(
|
||||
"appearance",
|
||||
@@ -132,7 +132,7 @@ impl StatefulWidget for Footer {
|
||||
)),
|
||||
])),
|
||||
]),
|
||||
// edit
|
||||
// controls - 1. row
|
||||
Row::new(vec![
|
||||
Cell::from(Span::styled(
|
||||
"controls",
|
||||
@@ -141,47 +141,85 @@ impl StatefulWidget for Footer {
|
||||
Cell::from(Line::from({
|
||||
match self.app_edit_mode {
|
||||
AppEditMode::None => {
|
||||
let mut spans = vec![
|
||||
Span::from(if self.running_clock {
|
||||
let mut spans = vec![Span::from(if self.running_clock {
|
||||
"[s]top"
|
||||
} else {
|
||||
"[s]tart"
|
||||
}),
|
||||
Span::from(SPACE),
|
||||
Span::from("[r]eset"),
|
||||
})];
|
||||
spans.extend_from_slice(&[
|
||||
Span::from(SPACE),
|
||||
Span::from("[e]dit"),
|
||||
];
|
||||
]);
|
||||
if self.selected_content == Content::Countdown {
|
||||
spans.extend_from_slice(&[
|
||||
Span::from(SPACE),
|
||||
Span::from("[^e]dit by local time"),
|
||||
]);
|
||||
}
|
||||
spans.extend_from_slice(&[
|
||||
Span::from(SPACE),
|
||||
Span::from("[r]eset"),
|
||||
]);
|
||||
if self.selected_content == Content::Pomodoro {
|
||||
spans.extend_from_slice(&[
|
||||
Span::from(SPACE),
|
||||
Span::from("[← →]switch work/pause"),
|
||||
Span::from("[^r]eset round"),
|
||||
]);
|
||||
}
|
||||
spans
|
||||
}
|
||||
others => vec![
|
||||
Span::from(match others {
|
||||
AppEditMode::Clock => "[e]dit done",
|
||||
AppEditMode::Time => "[^e]dit done",
|
||||
_ => "",
|
||||
}),
|
||||
_ => {
|
||||
let mut spans = vec![Span::from("[s]ave changes")];
|
||||
if self.selected_content == Content::Countdown
|
||||
|| self.selected_content == Content::Pomodoro
|
||||
{
|
||||
spans.extend_from_slice(&[
|
||||
Span::from(SPACE),
|
||||
Span::from("[^s]ave initial value"),
|
||||
]);
|
||||
}
|
||||
spans.extend_from_slice(&[
|
||||
Span::from(SPACE),
|
||||
Span::from("[esc]skip changes"),
|
||||
]);
|
||||
spans
|
||||
}
|
||||
}
|
||||
})),
|
||||
]),
|
||||
// controls - 2. row
|
||||
Row::new(vec![
|
||||
Cell::from(Line::from("")),
|
||||
Cell::from(Line::from({
|
||||
match self.app_edit_mode {
|
||||
AppEditMode::None => {
|
||||
let mut spans = vec![];
|
||||
if self.selected_content == Content::Pomodoro {
|
||||
spans.extend_from_slice(&[Span::from(
|
||||
"[← →]switch work/pause",
|
||||
)]);
|
||||
}
|
||||
spans
|
||||
}
|
||||
_ => vec![
|
||||
Span::from(format!(
|
||||
"[{} {}]edit selection",
|
||||
// ← →,
|
||||
"[{} {}]change selection",
|
||||
scrollbar::HORIZONTAL.begin,
|
||||
scrollbar::HORIZONTAL.end
|
||||
)), // ← →,
|
||||
)),
|
||||
Span::from(SPACE),
|
||||
Span::from(format!("[{}]edit up", scrollbar::VERTICAL.begin)), // ↑
|
||||
Span::from(format!(
|
||||
// ↑
|
||||
"[{}]edit up",
|
||||
scrollbar::VERTICAL.begin
|
||||
)),
|
||||
Span::from(SPACE),
|
||||
Span::from(format!("[{}]edit up", scrollbar::VERTICAL.end)), // ↓,
|
||||
Span::from(format!(
|
||||
// ↓
|
||||
"[{}]edit up",
|
||||
scrollbar::VERTICAL.end
|
||||
)),
|
||||
],
|
||||
}
|
||||
})),
|
||||
|
||||
@@ -5,9 +5,9 @@ use crate::{
|
||||
utils::center,
|
||||
widgets::clock::{ClockState, ClockStateArgs, ClockWidget, Countdown},
|
||||
};
|
||||
use crossterm::event::{KeyCode, KeyModifiers};
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
crossterm::event::KeyCode,
|
||||
layout::{Constraint, Layout, Rect},
|
||||
text::Line,
|
||||
widgets::{StatefulWidget, Widget},
|
||||
@@ -45,6 +45,7 @@ impl ClockMap {
|
||||
pub struct PomodoroState {
|
||||
mode: Mode,
|
||||
clock_map: ClockMap,
|
||||
round: u64,
|
||||
}
|
||||
|
||||
pub struct PomodoroStateArgs {
|
||||
@@ -55,6 +56,7 @@ pub struct PomodoroStateArgs {
|
||||
pub current_value_pause: Duration,
|
||||
pub with_decis: bool,
|
||||
pub app_tx: AppEventTx,
|
||||
pub round: u64,
|
||||
}
|
||||
|
||||
impl PomodoroState {
|
||||
@@ -67,6 +69,7 @@ impl PomodoroState {
|
||||
current_value_pause,
|
||||
with_decis,
|
||||
app_tx,
|
||||
round,
|
||||
} = args;
|
||||
Self {
|
||||
mode,
|
||||
@@ -88,6 +91,7 @@ impl PomodoroState {
|
||||
})
|
||||
.with_name("Pause".to_owned()),
|
||||
},
|
||||
round,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +115,10 @@ impl PomodoroState {
|
||||
&self.mode
|
||||
}
|
||||
|
||||
pub fn get_round(&self) -> u64 {
|
||||
self.round
|
||||
}
|
||||
|
||||
pub fn set_with_decis(&mut self, with_decis: bool) {
|
||||
self.clock_map.work.with_decis = with_decis;
|
||||
self.clock_map.pause.with_decis = with_decis;
|
||||
@@ -132,34 +140,77 @@ impl TuiEventHandler for PomodoroState {
|
||||
self.get_clock_mut().tick();
|
||||
self.get_clock_mut().update_done_count();
|
||||
}
|
||||
// EDIT mode
|
||||
TuiEvent::Key(key) if edit_mode => match key.code {
|
||||
// Skip changes
|
||||
KeyCode::Esc => {
|
||||
let clock = self.get_clock_mut();
|
||||
// Important: set current value first
|
||||
clock.set_current_value(*clock.get_prev_value());
|
||||
// before toggling back to non-edit mode
|
||||
clock.toggle_edit();
|
||||
}
|
||||
// Apply changes and update initial value
|
||||
KeyCode::Char('s') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
self.get_clock_mut().toggle_edit();
|
||||
// update initial value
|
||||
let c = *self.get_clock().get_current_value();
|
||||
self.get_clock_mut().set_initial_value(c);
|
||||
}
|
||||
// Apply changes
|
||||
KeyCode::Char('s') => {
|
||||
self.get_clock_mut().toggle_edit();
|
||||
}
|
||||
// Value up
|
||||
KeyCode::Up => {
|
||||
self.get_clock_mut().edit_up();
|
||||
}
|
||||
// Value down
|
||||
KeyCode::Down => {
|
||||
self.get_clock_mut().edit_down();
|
||||
}
|
||||
// move edit position to the left
|
||||
KeyCode::Left => {
|
||||
self.get_clock_mut().edit_next();
|
||||
}
|
||||
// move edit position to the right
|
||||
KeyCode::Right => {
|
||||
self.get_clock_mut().edit_prev();
|
||||
}
|
||||
_ => return Some(event),
|
||||
},
|
||||
// default mode
|
||||
TuiEvent::Key(key) => match key.code {
|
||||
// Toggle run/pause
|
||||
KeyCode::Char('s') => {
|
||||
self.get_clock_mut().toggle_pause();
|
||||
}
|
||||
// Enter edit mode
|
||||
KeyCode::Char('e') => {
|
||||
self.get_clock_mut().toggle_edit();
|
||||
}
|
||||
KeyCode::Left if edit_mode => {
|
||||
self.get_clock_mut().edit_next();
|
||||
}
|
||||
// toggle WORK/PAUSE
|
||||
KeyCode::Left => {
|
||||
// `next` is acting as same as a `prev` function, we don't have
|
||||
// `next` is acting as same as a "prev" function we don't have
|
||||
self.next();
|
||||
}
|
||||
KeyCode::Right if edit_mode => {
|
||||
self.get_clock_mut().edit_prev();
|
||||
}
|
||||
// toggle WORK/PAUSE
|
||||
KeyCode::Right => {
|
||||
self.next();
|
||||
}
|
||||
KeyCode::Up if edit_mode => {
|
||||
self.get_clock_mut().edit_up();
|
||||
}
|
||||
KeyCode::Down if edit_mode => {
|
||||
self.get_clock_mut().edit_down();
|
||||
// reset round
|
||||
KeyCode::Char('r') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
self.round = 1;
|
||||
}
|
||||
// reset values
|
||||
KeyCode::Char('r') => {
|
||||
self.get_clock_mut().reset();
|
||||
// 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;
|
||||
}
|
||||
// reset both clocks
|
||||
self.clock_map.pause.reset();
|
||||
self.clock_map.work.reset();
|
||||
}
|
||||
_ => return Some(event),
|
||||
},
|
||||
@@ -186,6 +237,7 @@ impl StatefulWidget for PomodoroWidget {
|
||||
))
|
||||
.to_uppercase(),
|
||||
);
|
||||
let label_round = Line::raw((format!("round {}", state.get_round(),)).to_uppercase());
|
||||
|
||||
let area = center(
|
||||
area,
|
||||
@@ -196,13 +248,25 @@ impl StatefulWidget for PomodoroWidget {
|
||||
),
|
||||
label.width() as u16,
|
||||
)),
|
||||
Constraint::Length(clock_widget.get_height() + 1 /* height of mode_str */),
|
||||
Constraint::Length(
|
||||
// empty label + height of `label` + `label_round`
|
||||
clock_widget.get_height() + 3,
|
||||
),
|
||||
);
|
||||
|
||||
let [v1, v2] =
|
||||
Layout::vertical(Constraint::from_lengths([clock_widget.get_height(), 1])).areas(area);
|
||||
let [v1, v2, v3, v4] = Layout::vertical(Constraint::from_lengths([
|
||||
1,
|
||||
clock_widget.get_height(),
|
||||
1,
|
||||
1,
|
||||
]))
|
||||
.areas(area);
|
||||
|
||||
clock_widget.render(v1, buf, state.get_clock_mut());
|
||||
label.centered().render(v2, buf);
|
||||
// empty line keep everything in center vertically comparing to other
|
||||
// views (which have one label below the clock only)
|
||||
Line::raw("").centered().render(v1, buf);
|
||||
clock_widget.render(v2, buf, state.get_clock_mut());
|
||||
label.centered().render(v3, buf);
|
||||
label_round.centered().render(v4, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,28 +39,51 @@ impl TuiEventHandler for TimerState {
|
||||
self.clock.tick();
|
||||
self.clock.update_done_count();
|
||||
}
|
||||
// EDIT mode
|
||||
TuiEvent::Key(key) if edit_mode => match key.code {
|
||||
// Skip changes
|
||||
KeyCode::Esc => {
|
||||
// Important: set current value first
|
||||
self.clock.set_current_value(*self.clock.get_prev_value());
|
||||
// before toggling back to non-edit mode
|
||||
self.clock.toggle_edit();
|
||||
}
|
||||
// Apply changes
|
||||
KeyCode::Char('s') => {
|
||||
self.clock.toggle_edit();
|
||||
}
|
||||
// move change position to the left
|
||||
KeyCode::Left => {
|
||||
self.clock.edit_next();
|
||||
}
|
||||
// move change position to the right
|
||||
KeyCode::Right => {
|
||||
self.clock.edit_prev();
|
||||
}
|
||||
// change value up
|
||||
KeyCode::Up => {
|
||||
self.clock.edit_up();
|
||||
}
|
||||
// change value down
|
||||
KeyCode::Down => {
|
||||
self.clock.edit_down();
|
||||
}
|
||||
_ => return Some(event),
|
||||
},
|
||||
// default mode
|
||||
TuiEvent::Key(key) => match key.code {
|
||||
// Toggle run/pause
|
||||
KeyCode::Char('s') => {
|
||||
self.clock.toggle_pause();
|
||||
}
|
||||
// reset clock
|
||||
KeyCode::Char('r') => {
|
||||
self.clock.reset();
|
||||
}
|
||||
// enter edit mode
|
||||
KeyCode::Char('e') => {
|
||||
self.clock.toggle_edit();
|
||||
}
|
||||
KeyCode::Left if edit_mode => {
|
||||
self.clock.edit_next();
|
||||
}
|
||||
KeyCode::Right if edit_mode => {
|
||||
self.clock.edit_prev();
|
||||
}
|
||||
KeyCode::Up if edit_mode => {
|
||||
self.clock.edit_up();
|
||||
}
|
||||
KeyCode::Down if edit_mode => {
|
||||
self.clock.edit_down();
|
||||
}
|
||||
_ => return Some(event),
|
||||
},
|
||||
_ => return Some(event),
|
||||
|
||||
Reference in New Issue
Block a user