18 Commits

Author SHA1 Message Date
Jens Krause
c370d3096b Prepare v1.3.0 (#80)
* Prepare v1.3.0
* readme: fix keybindings
* update changelog
2025-05-06 11:46:29 +02:00
jk
aae5c38cd6 fix(footer): hide option to save initial value
for timer. Available 4 pomodoro + countdown only.
2025-05-06 11:25:29 +02:00
jk
5ad09b9848 (demo) update menu 2025-05-02 12:52:35 +02:00
Jens Krause
52ed8267be (pomodoro/countdown) Change initial value (#79)
- While editing, an user can apply changes as a new initial value (pomodoro/countdown only).
- New keybinding: `[^s]save initial value` 
- Update keybinding: `[s]ave changes` (instead of `[Enter]`)
- Refactor event handling to re-structure `edit` / `non-edit` modes.
- Refactor footer to reflect latest keybindings
2025-05-02 12:39:26 +02:00
jk
6b068bbd09 fix(pomodoro) add empty line to keep content
centered vertically comparing to other views (which have one label below the clock only)

In addition to #75.
2025-04-30 14:27:30 +02:00
Jens Krause
c96432779a (readme) add keybindings + toc (#78)
* (readme) add keybindings + toc
* update LICENSE
2025-04-30 14:19:13 +02:00
Jens Krause
509cf73cdd (flake) use alsa-lib-with-plugins (#77)
by following an idea from @camuward mentioned here https://github.com/143mailliw/muzak/pull/28#issuecomment-2833601152

Incl. another `nix flake update`.
2025-04-30 12:12:03 +02:00
Jens Krause
e6291a3131 Update keybindings (#76)
* (pomodoro) reset both clocks at once

* quit app by pressing `q` only

* (countdown) enter/esc keybindings

* (timer) enter/esc keybindings

* (pomodoro) enter/esc keybindings

* update footer label

* fix(coundown): don't reset elapsed clock

while skipping editing changes

* fix(clock): order of actions matters for ESC

handling. Set `pause` instead of `initial` mode while toggeling back.

* fix(timer): order of actions matters (ESC key)

* (footer) update order, lowercase standard keys
2025-04-30 11:11:33 +02:00
Jens Krause
90d9988e7a (pomodoro) count WORK rounds (#75) 2025-04-29 16:20:02 +02:00
Jens Krause
028a067419 Prepare v1.2.1 (#74) 2025-04-17 12:26:13 +02:00
jk
675428cfb0 Update README 2025-04-17 08:31:40 +02:00
Jens Krause
28c5d7194c Rust 1.86.0 (#73) 2025-04-13 21:37:47 +02:00
Jens Krause
5b445afe25 fix(countdown): reset MET while editing by local time (#72) 2025-04-13 21:17:56 +02:00
jk
beb12d5ec2 just: run with args 2025-04-13 19:19:46 +02:00
Jens Krause
d9399eafc9 fix(countdown): Reset MET if countdown is set by cli arguments (#71)
* fix: Reset MET if countdown is set by args

* update CHANGELOG
2025-03-03 12:21:17 +01:00
Jens Krause
ffad78e093 fix(just): group commands (#70) 2025-02-26 14:58:54 +01:00
jk
e7a5a1b2da exclude files for packaging 2025-02-26 12:31:18 +01:00
Jens Krause
6f0df4d488 Prepare v1.2.0 (#69)
* prepare v1.2.0

* update README

* update justfile
2025-02-26 12:11:54 +01:00
20 changed files with 847 additions and 467 deletions

View File

@@ -1,12 +1,48 @@
# Changelog # Changelog
## [Unreleased] ## v1.3.0 - 2025-05-06
### Features ### Features
- (notification) Blink clock when it reaches its `done` mode. (optional) [#65](https://github.com/sectore/timr-tui/pull/65) - (pomodoro) Count WORK rounds [#75](https://github.com/sectore/timr-tui/pull/75), [6b068bb](https://github.com/sectore/timr-tui/commit/6b068bbd094d9ec1a36b47598fadfc71296d9590)
- (notification) Native desktop notification (optional, experimental) [#49](https://github.com/sectore/timr-tui/pull/59) - (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
- (countdown) Reset `Mission Elapsed Time (MET)` if `countdown` is set by _cli arguments_ [#71](https://github.com/sectore/timr-tui/pull/71)
- (countdown) Reset `Mission Elapsed Time (MET)` while setting `countdown` by _local time_ [#72](https://github.com/sectore/timr-tui/pull/72)
### Misc.
- (deps) Use latest `Rust 1.86` [#73](https://github.com/sectore/timr-tui/pull/73)
- (cargo) Exclude files for packaging [e7a5a1b](https://github.com/sectore/timr-tui/commit/e7a5a1b2da7a7967f2602a0b92f391ac768ca638)
- (just) `group` commands [#70](https://github.com/sectore/timr-tui/pull/70)
## v1.2.0 - 2025-02-26
### Features
- (notification) Clock animation (blink) by reaching `done` mode (optional) [#65](https://github.com/sectore/timr-tui/pull/65)
- (notification) Native desktop notification (optional, experimental) [#59](https://github.com/sectore/timr-tui/pull/59)
- (notification) Sound notification (optional, experimental, available in local build only) [#62](https://github.com/sectore/timr-tui/pull/62) - (notification) Sound notification (optional, experimental, available in local build only) [#62](https://github.com/sectore/timr-tui/pull/62)
- (logging) Add `--log` arg to enable logs [e094d7d](https://github.com/sectore/timr-tui/commit/e094d7d81b99f58f0d3bc50124859a4e1f6dbe4f)
### Misc.
- (refactor) Extend event handling for using a `mpsc` channel to send `AppEvent`'s from anywhere. [#61](https://github.com/sectore/timr-tui/pull/61)
- (extension) Use `set_panic_hook` for better error handling [#67](https://github.com/sectore/timr-tui/pull/67)
- (deps) Use latest `Rust 1.85` and `Rust 2024 Edition`. Refactor `flake` to consider `rust-toolchain.toml` etc. [#68](https://github.com/sectore/timr-tui/pull/68)
## v1.1.0 - 2025-01-22 ## v1.1.0 - 2025-01-22

581
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,17 @@
[package] [package]
name = "timr-tui" name = "timr-tui"
version = "1.1.0" version = "1.3.0"
description = "TUI to organize your time: Pomodoro, Countdown, Timer." description = "TUI to organize your time: Pomodoro, Countdown, Timer."
edition = "2024" edition = "2024"
# Reminder: Always keep `channel` in `rust-toolchain.toml` in sync with `rust-version`. # Reminder: Always keep `channel` in `rust-toolchain.toml` in sync with `rust-version`.
rust-version = "1.85.0" rust-version = "1.86.0"
homepage = "https://github.com/sectore/timr-tui" homepage = "https://github.com/sectore/timr-tui"
repository = "https://github.com/sectore/timr-tui" repository = "https://github.com/sectore/timr-tui"
readme = "README.md" readme = "README.md"
license = "MIT" license = "MIT"
keywords = ["tui", "timer", "countdown", "pomodoro"] keywords = ["tui", "timer", "countdown", "pomodoro"]
categories = ["command-line-utilities"] categories = ["command-line-utilities"]
exclude = [".github/*", "demo/*.tape", "result/*", "*.mp3"]
[dependencies] [dependencies]
ratatui = "0.29.0" ratatui = "0.29.0"
@@ -35,5 +36,6 @@ rodio = { version = "0.20.1", features = [
], default-features = false, optional = true } ], default-features = false, optional = true }
thiserror = { version = "2.0.11", optional = true } thiserror = { version = "2.0.11", optional = true }
[features] [features]
sound = ["dep:rodio", "dep:thiserror"] sound = ["dep:rodio", "dep:thiserror"]

View File

@@ -1,6 +1,6 @@
MIT License 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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

136
README.md
View File

@@ -8,9 +8,20 @@ TUI to organize your time: Pomodoro, Countdown, Timer.
Built with [Ratatui](https://ratatui.rs/) / [Rust 🦀](https://www.rust-lang.org/). 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 ## Pomodoro
@@ -48,7 +59,7 @@ _Side note:_ Theme colors depend on your terminal preferences.
<img alt="menu" src="demo/menu.gif" /> <img alt="menu" src="demo/menu.gif" />
</a> </a>
## Local time ## Local time (footer)
<a href="demo/local-time.gif"> <a href="demo/local-time.gif">
<img alt="menu" src="demo/local-time.gif" /> <img alt="menu" src="demo/local-time.gif" />
@@ -80,14 +91,72 @@ Options:
--blink <BLINK> Toggle blink mode to animate a clock when it reaches its finished mode. [possible values: on, off] --blink <BLINK> Toggle blink mode to animate a clock when it reaches its finished mode. [possible values: on, off]
--log [<LOG>] Directory to store log file. If not set, standard application log directory is used (check README for details). --log [<LOG>] Directory to store log file. If not set, standard application log directory is used (check README for details).
-h, --help Print help -h, --help Print help
-V, --version Print version
``` ```
Extra option (if `--features sound` is enabled by local build only): Extra option (if `--features sound` is enabled by local build only):
```sh ```sh
--sound <SOUND> Path to sound file (.mp3 or .wav) to play as notification. Experimental. --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 # Installation
@@ -113,12 +182,10 @@ Install [from the AUR](https://aur.archlinux.org/packages/timr/):
paru -S timr paru -S timr
``` ```
## Release binaries ## Release binaries
Pre-built artifacts are available to download from [latest GitHub release](https://github.com/sectore/timr-tui/releases). Pre-built artifacts are available to download from [latest GitHub release](https://github.com/sectore/timr-tui/releases).
# Development # Development
## Requirements ## Requirements
@@ -129,7 +196,6 @@ Pre-built artifacts are available to download from [latest GitHub release](https
If you have [`direnv`](https://direnv.net) installed, run `direnv allow` once to install dependencies. In other case run `nix develop`. If you have [`direnv`](https://direnv.net) installed, run `direnv allow` once to install dependencies. In other case run `nix develop`.
### Non Nix users ### Non Nix users
- [`Rust`](https://www.rust-lang.org/learn/get-started) - [`Rust`](https://www.rust-lang.org/learn/get-started)
@@ -140,34 +206,62 @@ If you have [`direnv`](https://direnv.net) installed, run `direnv allow` once to
### Commands ### Commands
```sh ```sh
just --list just
Available recipes: Available recipes:
build # build app default # list commands
b # alias for `build`
default [build]
format # format files build # build app [alias: b]
f # alias for `format`
lint # lint [demo]
l # alias for `lint` demo-blink # build demo: blink animation [alias: db]
run # run app demo-countdown # build demo: countdown [alias: dc]
r # alias for `run` demo-countdown-met # build demo: countdown + met [alias: dcm]
test # run tests demo-decis # build demo: deciseconds [alias: dd]
t # alias for `test` demo-local-time # build demo: local time [alias: dlt]
demo-menu # build demo: menu [alias: dm]
demo-pomodoro # build demo: pomodoro [alias: dp]
demo-rocket-countdown # build demo: rocket countdown [alias: drc]
demo-style # build demo: styles [alias: ds]
demo-timer # build demo: timer [alias: dt]
[dev]
run # run app [alias: r]
run-args args # run app with arguments. It expects arguments as a string (e.g. "-c 5:00"). [alias: ra]
run-sound path # run app while sound feature is enabled. It expects a path to a sound file. [alias: rs]
run-sound-args path args # run app while sound feature is enabled by adding a path to a sound file and other arguments as string (e.g. "-c 5:00"). [alias: rsa]
[misc]
format # format files [alias: f]
lint # lint [alias: l]
[test]
test # run tests [alias: t]
``` ```
### Build ### Build
- Linux - Linux
```sh ```sh
nix build nix build
# or for bulding w/ statically linked binaries
nix build .#linuxStatic
``` ```
- Windows (cross-compilation) - Windows (cross-compilation)
```sh ```sh
nix build .#windows nix build .#windows
``` ```
### Run tests
```sh
cargo test
```
# Misc. # Misc.
## Persistant app state ## Persistant app state
@@ -199,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. Optional: You can use a custom directory by passing it via `--log` arg.
# License
[MIT License](./LICENSE)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 130 KiB

View File

@@ -12,19 +12,15 @@ Set Margin 1
# --- START --- # --- START ---
Set LoopOffset 4 Set LoopOffset 4
Hide Hide
Type "cargo run -- -r -m p" Type "cargo run -- -r -m p --menu"
Enter Enter
Sleep 0.2 Type@200ms "m"
Show Show
# --- STYLES --- # --- STYLES ---
Sleep 0.5 Sleep 0.3s
Type "m" Type@0.3s "m"
Sleep 0.5 Type@0.3s "t"
Type@0.5s "t" Type@0.3s "c"
Type@0.5s "c" Type@0.3s "p"
Type@0.5s "p" Type@0.3s "e"
Type@0.5s "e" Escape@0.3s
Right@0.5s
Left@0.5s
Type@0.5s "e"
Sleep 0.5

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

24
flake.lock generated
View File

@@ -2,11 +2,11 @@
"nodes": { "nodes": {
"crane": { "crane": {
"locked": { "locked": {
"lastModified": 1739936662, "lastModified": 1745454774,
"narHash": "sha256-x4syUjNUuRblR07nDPeLDP7DpphaBVbUaSoeZkFbGSk=", "narHash": "sha256-oLvmxOnsEKGtwczxp/CwhrfmQUG2ym24OMWowcoRhH8=",
"owner": "ipetkov", "owner": "ipetkov",
"repo": "crane", "repo": "crane",
"rev": "19de14aaeb869287647d9461cbd389187d8ecdb7", "rev": "efd36682371678e2b6da3f108fdb5c613b3ec598",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -23,11 +23,11 @@
"rust-analyzer-src": "rust-analyzer-src" "rust-analyzer-src": "rust-analyzer-src"
}, },
"locked": { "locked": {
"lastModified": 1740378829, "lastModified": 1745995211,
"narHash": "sha256-cwmm7F73aQFJY6YN1roNibNKwxT6FlfXkG3MEbpSp7Q=", "narHash": "sha256-hf6Xu3KS06WyE/3dqV96iLGx3jIYQq9e68iCEFHrt04=",
"owner": "nix-community", "owner": "nix-community",
"repo": "fenix", "repo": "fenix",
"rev": "92823f1b0c919d7e2d806956aaf98e90f3761ab7", "rev": "0db04339c4e4c0fd42dbbaebe3590a67cbd12aa3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -56,11 +56,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1740367490, "lastModified": 1745930157,
"narHash": "sha256-WGaHVAjcrv+Cun7zPlI41SerRtfknGQap281+AakSAw=", "narHash": "sha256-y3h3NLnzRSiUkYpnfvnS669zWZLoqqI6NprtLQ+5dck=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "0196c0175e9191c474c26ab5548db27ef5d34b05", "rev": "46e634be05ce9dc6d4db8e664515ba10b78151ae",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -81,11 +81,11 @@
"rust-analyzer-src": { "rust-analyzer-src": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1740329432, "lastModified": 1745949276,
"narHash": "sha256-eKQ7aBkNvF5AhUpyJ1cW450jxomZ4gTIaYir5qsNl7Y=", "narHash": "sha256-9ZK31t2HUiGdLLnDafrRnSrrO12JwqcAFbrJ9nRwh0Y=",
"owner": "rust-lang", "owner": "rust-lang",
"repo": "rust-analyzer", "repo": "rust-analyzer",
"rev": "6d68c475c7aaf7534251182662456a4bf4216dfe", "rev": "78a488dd5e7e4f17162001519665795e6e68b6f8",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -24,7 +24,7 @@
{ {
file = ./rust-toolchain.toml; file = ./rust-toolchain.toml;
# sha256 = nixpkgs.lib.fakeSha256; # sha256 = nixpkgs.lib.fakeSha256;
sha256 = "sha256-AJ6LX/Q/Er9kS15bn9iflkUwcgYqRQxiOIL2ToVAXaU="; sha256 = "sha256-X/4ZBHO3iW0fOenQ3foEvscgAPJYl2abspaBThDOukI=";
}; };
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
@@ -88,16 +88,12 @@
# some extra pkgs needed to play sound on Linux # some extra pkgs needed to play sound on Linux
++ lib.optionals stdenv.isLinux [ ++ lib.optionals stdenv.isLinux [
pkgs.pkg-config pkgs.pkg-config
pkgs.alsa-lib.dev (pkgs.alsa-lib-with-plugins.override {
pkgs.pipewire plugins = [pkgs.alsa-plugins pkgs.pipewire];
})
]; ];
inherit (commonArgs) src; inherit (commonArgs) src;
ALSA_PLUGIN_DIR =
if stdenv.isLinux
then "${pkgs.pipewire}/lib/alsa-lib/"
else "";
}; };
}); });
} }

View File

@@ -2,24 +2,28 @@
set unstable := true set unstable := true
# list commands
default: default:
@just --list @just --list
alias b := build alias b := build
# build app # build app
[group('build')]
build: build:
cargo build cargo build
alias t := test alias t := test
# run tests # run tests
[group('test')]
test: test:
cargo test cargo test
alias f := format alias f := format
# format files # format files
[group('misc')]
format: format:
just --fmt just --fmt
cargo fmt cargo fmt
@@ -27,69 +31,106 @@ format:
alias l := lint alias l := lint
# lint # lint
[group('misc')]
lint: lint:
cargo clippy --no-deps cargo clippy --no-deps
alias r := run alias r := run
# run app # run app
[group('dev')]
run: run:
cargo run cargo run
alias ra := run-args
# run app with arguments. It expects arguments as a string (e.g. "-c 5:00").
[group('dev')]
run-args args:
cargo run -- {{ args }}
alias rs := run-sound alias rs := run-sound
# run app while sound feature is enabled. It expects a path to a sound file. # run app while sound feature is enabled. It expects a path to a sound file.
[group('dev')]
run-sound path: run-sound path:
cargo run --features sound -- --sound={{ path }} cargo run --features sound -- --sound={{ path }}
alias rsa := run-sound-args
# run app while sound feature is enabled by adding a path to a sound file and other arguments as string (e.g. "-c 5:00").
[group('dev')]
run-sound-args path args:
cargo run --features sound -- --sound={{ path }} {{ args }}
# demos # demos
alias dp := demo-pomodoro alias dp := demo-pomodoro
# build demo: pomodoro
[group('demo')]
demo-pomodoro: demo-pomodoro:
vhs demo/pomodoro.tape vhs demo/pomodoro.tape
alias dt := demo-timer alias dt := demo-timer
# build demo: timer
[group('demo')]
demo-timer: demo-timer:
vhs demo/timer.tape vhs demo/timer.tape
alias dc := demo-countdown alias dc := demo-countdown
# build demo: countdown
[group('demo')]
demo-countdown: demo-countdown:
vhs demo/countdown.tape vhs demo/countdown.tape
alias dcm := demo-countdown-met alias dcm := demo-countdown-met
# build demo: countdown + met
[group('demo')]
demo-countdown-met: demo-countdown-met:
vhs demo/countdown-met.tape vhs demo/countdown-met.tape
alias ds := demo-style alias ds := demo-style
# build demo: styles
[group('demo')]
demo-style: demo-style:
vhs demo/style.tape vhs demo/style.tape
alias dd := demo-decis alias dd := demo-decis
# build demo: deciseconds
[group('demo')]
demo-decis: demo-decis:
vhs demo/decis.tape vhs demo/decis.tape
alias dm := demo-menu alias dm := demo-menu
# build demo: menu
[group('demo')]
demo-menu: demo-menu:
vhs demo/menu.tape vhs demo/menu.tape
alias dlt := demo-local-time alias dlt := demo-local-time
# build demo: local time
[group('demo')]
demo-local-time: demo-local-time:
vhs demo/local-time.tape vhs demo/local-time.tape
alias drc := demo-rocket-countdown alias drc := demo-rocket-countdown
# build demo: rocket countdown
[group('demo')]
demo-rocket-countdown: demo-rocket-countdown:
vhs demo/met.tape vhs demo/met.tape
alias db := demo-blink alias db := demo-blink
# build demo: blink animation
[group('demo')]
demo-blink: demo-blink:
vhs demo/blink.tape vhs demo/blink.tape

View File

@@ -1,6 +1,6 @@
[toolchain] [toolchain]
# Reminder: Always keep `rust-version` in `Cargo.toml` in sync with `channel`. # Reminder: Always keep `rust-version` in `Cargo.toml` in sync with `channel`.
channel = "1.85.0" channel = "1.86.0"
components = ["clippy", "rustfmt", "rust-src", "rust-analyzer"] components = ["clippy", "rustfmt", "rust-src", "rust-analyzer"]
targets = ["x86_64-pc-windows-gnu", "x86_64-unknown-linux-musl"] targets = ["x86_64-pc-windows-gnu", "x86_64-unknown-linux-musl"]
profile = "minimal" profile = "minimal"

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),
@@ -103,7 +105,11 @@ impl From<FromAppArgs> for App {
initial_value_countdown: args.countdown.unwrap_or(stg.inital_value_countdown), initial_value_countdown: args.countdown.unwrap_or(stg.inital_value_countdown),
// invalidate `current_value_countdown` if an initial value is set via args // invalidate `current_value_countdown` if an initial value is set via args
current_value_countdown: args.countdown.unwrap_or(stg.current_value_countdown), current_value_countdown: args.countdown.unwrap_or(stg.current_value_countdown),
elapsed_value_countdown: stg.elapsed_value_countdown, elapsed_value_countdown: match args.countdown {
// reset value if countdown is set by arguments
Some(_) => Duration::ZERO,
None => stg.elapsed_value_countdown,
},
current_value_timer: stg.current_value_timer, current_value_timer: stg.current_value_timer,
app_tx, app_tx,
#[cfg(feature = "sound")] #[cfg(feature = "sound")]
@@ -138,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,
@@ -179,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),
@@ -194,7 +202,7 @@ impl App {
let handle_key_event = |app: &mut Self, key: KeyEvent| { let handle_key_event = |app: &mut Self, key: KeyEvent| {
debug!("Received key {:?}", key.code); debug!("Received key {:?}", key.code);
match 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('c') => app.content = Content::Countdown,
KeyCode::Char('t') => app.content = Content::Timer, KeyCode::Char('t') => app.content = Content::Timer,
KeyCode::Char('p') => app.content = Content::Pomodoro, KeyCode::Char('p') => app.content = Content::Pomodoro,
@@ -355,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(
@@ -405,7 +414,7 @@ impl StatefulWidget for AppWidget {
let [v0, v1, v2] = Layout::vertical([ let [v0, v1, v2] = Layout::vertical([
Constraint::Length(1), Constraint::Length(1),
Constraint::Percentage(100), 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); .areas(area);

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

@@ -74,6 +74,7 @@ pub struct ClockState<T> {
name: Option<String>, name: Option<String>,
initial_value: DurationEx, initial_value: DurationEx,
current_value: DurationEx, current_value: DurationEx,
prev_value: DurationEx,
tick_value: DurationEx, tick_value: DurationEx,
mode: Mode, mode: Mode,
format: Format, format: Format,
@@ -142,6 +143,10 @@ impl<T> ClockState<T> {
&self.initial_value &self.initial_value
} }
pub fn set_initial_value(&mut self, duration: DurationEx) {
self.initial_value = duration;
}
pub fn get_current_value(&self) -> &DurationEx { pub fn get_current_value(&self) -> &DurationEx {
&self.current_value &self.current_value
} }
@@ -151,14 +156,18 @@ impl<T> ClockState<T> {
self.update_format(); self.update_format();
} }
pub fn get_prev_value(&self) -> &DurationEx {
&self.prev_value
}
pub fn toggle_edit(&mut self) { pub fn toggle_edit(&mut self) {
self.mode = match self.mode.clone() { self.mode = match self.mode.clone() {
Mode::Editable(_, prev) => { Mode::Editable(_, prev) => {
let p = *prev; let p = *prev;
// special cases: Should `Mode` be updated? // Update `Mode`
// 1. `Done` -> `Initial` ? // 1. `Done` -> `Pause`
if p == Mode::Done && self.current_value.gt(&Duration::ZERO.into()) { if p == Mode::Done && self.current_value.gt(&Duration::ZERO.into()) {
Mode::Initial Mode::Pause
} }
// 2. `_` -> `Done` ? // 2. `_` -> `Done` ?
else if p != Mode::Done && self.current_value.eq(&Duration::ZERO.into()) { else if p != Mode::Done && self.current_value.eq(&Duration::ZERO.into()) {
@@ -170,6 +179,8 @@ impl<T> ClockState<T> {
} }
} }
mode => { mode => {
// store prev. value
self.prev_value = self.current_value;
if self.format <= Format::Ss { if self.format <= Format::Ss {
Mode::Editable(Time::Seconds, Box::new(mode)) Mode::Editable(Time::Seconds, Box::new(mode))
} else { } else {
@@ -402,6 +413,7 @@ impl ClockState<Countdown> {
name: None, name: None,
initial_value: initial_value.into(), initial_value: initial_value.into(),
current_value: current_value.into(), current_value: current_value.into(),
prev_value: current_value.into(),
tick_value: tick_value.into(), tick_value: tick_value.into(),
mode: if current_value == Duration::ZERO { mode: if current_value == Duration::ZERO {
Mode::Done Mode::Done
@@ -475,6 +487,7 @@ impl ClockState<Timer> {
name: None, name: None,
initial_value: initial_value.into(), initial_value: initial_value.into(),
current_value: current_value.into(), current_value: current_value.into(),
prev_value: current_value.into(),
tick_value: tick_value.into(), tick_value: tick_value.into(),
mode: if current_value == initial_value { mode: if current_value == initial_value {
Mode::Initial Mode::Initial

View File

@@ -144,8 +144,6 @@ impl CountdownState {
impl TuiEventHandler for CountdownState { impl TuiEventHandler for CountdownState {
fn update(&mut self, event: TuiEvent) -> Option<TuiEvent> { fn update(&mut self, event: TuiEvent) -> Option<TuiEvent> {
let is_edit_clock = self.clock.is_edit_mode();
let is_edit_time = self.edit_time.is_some();
match event { match event {
TuiEvent::Tick => { TuiEvent::Tick => {
if !self.clock.is_done() { if !self.clock.is_done() {
@@ -164,6 +162,96 @@ impl TuiEventHandler for CountdownState {
edit_time.set_max_time(max_time); 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 { TuiEvent::Key(key) => match key.code {
KeyCode::Char('r') => { KeyCode::Char('r') => {
// reset both clocks to use intial values // reset both clocks to use intial values
@@ -189,85 +277,29 @@ impl TuiEventHandler for CountdownState {
self.edit_time_done(edit_time); 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) => { KeyCode::Char('e') if key.modifiers.contains(KeyModifiers::CONTROL) => {
// stop editing clock // set `edit_time`
if self.clock.is_edit_mode() {
// toggle edit mode
self.clock.toggle_edit();
}
if let Some(edit_time) = &mut self.edit_time.clone() {
self.edit_time_done(edit_time)
} else {
// update `edit_time`
self.edit_time = Some(EditTimeState::new(EditTimeStateArgs { self.edit_time = Some(EditTimeState::new(EditTimeStateArgs {
time: self.time_to_edit(), time: self.time_to_edit(),
min: self.min_time_to_edit(), min: self.min_time_to_edit(),
max: self.max_time_to_edit(), max: self.max_time_to_edit(),
})); }));
}
// stop `clock` // pause `elapsed_clock`
if self.clock.is_running() {
self.clock.toggle_pause();
}
// stop `elapsed_clock`
if self.elapsed_clock.is_running() { if self.elapsed_clock.is_running() {
self.elapsed_clock.toggle_pause(); self.elapsed_clock.toggle_pause();
} }
} }
// STRG + e => toggle edit clock // Enter edit clock mode
KeyCode::Char('e') => { KeyCode::Char('e') => {
// toggle edit mode // toggle edit mode
self.clock.toggle_edit(); self.clock.toggle_edit();
// stop `elapsed_clock` // pause `elapsed_clock`
if self.elapsed_clock.is_running() { if self.elapsed_clock.is_running() {
self.elapsed_clock.toggle_pause(); self.elapsed_clock.toggle_pause();
} }
// finish `edit_time` and continue for using `clock`
if let Some(edit_time) = &mut self.edit_time.clone() {
self.edit_time_done(edit_time);
}
}
KeyCode::Left if is_edit_clock => {
self.clock.edit_next();
}
KeyCode::Left if is_edit_time => {
// safe unwrap because of previous check in `is_edit_time`
self.edit_time.as_mut().unwrap().next();
}
KeyCode::Right if is_edit_clock => {
self.clock.edit_prev();
}
KeyCode::Right if is_edit_time => {
// safe unwrap because of previous check in `is_edit_time`
self.edit_time.as_mut().unwrap().prev();
}
KeyCode::Up if is_edit_clock => {
self.clock.edit_up();
// whenever `clock`'s value is changed, reset `elapsed_clock`
self.elapsed_clock.reset();
}
KeyCode::Up if is_edit_time => {
// safe unwrap because of previous check in `is_edit_time`
self.edit_time.as_mut().unwrap().up();
// whenever `clock`'s value is changed, reset `elapsed_clock`
self.elapsed_clock.reset();
}
KeyCode::Down if is_edit_clock => {
self.clock.edit_down();
// whenever clock value is changed, reset timer
self.elapsed_clock.reset();
}
KeyCode::Down if is_edit_time => {
// safe unwrap because of previous check in `is_edit_time`
self.edit_time.as_mut().unwrap().down();
// whenever clock value is changed, reset timer
self.elapsed_clock.reset();
} }
_ => return Some(event), _ => return Some(event),
}, },

View File

@@ -104,7 +104,7 @@ impl StatefulWidget for Footer {
let widths = [Constraint::Length(12), Constraint::Percentage(100)]; let widths = [Constraint::Length(12), Constraint::Percentage(100)];
let table = Table::new( let table = Table::new(
[ [
// content // screens
Row::new(vec![ Row::new(vec![
Cell::from(Span::styled( Cell::from(Span::styled(
"screens", "screens",
@@ -112,7 +112,7 @@ impl StatefulWidget for Footer {
)), )),
Cell::from(Line::from(content_labels)), Cell::from(Line::from(content_labels)),
]), ]),
// format // appearance
Row::new(vec![ Row::new(vec![
Cell::from(Span::styled( Cell::from(Span::styled(
"appearance", "appearance",
@@ -132,7 +132,7 @@ impl StatefulWidget for Footer {
)), )),
])), ])),
]), ]),
// edit // controls - 1. row
Row::new(vec![ Row::new(vec![
Cell::from(Span::styled( Cell::from(Span::styled(
"controls", "controls",
@@ -141,47 +141,85 @@ impl StatefulWidget for Footer {
Cell::from(Line::from({ Cell::from(Line::from({
match self.app_edit_mode { match self.app_edit_mode {
AppEditMode::None => { AppEditMode::None => {
let mut spans = vec![ let mut spans = vec![Span::from(if self.running_clock {
Span::from(if self.running_clock {
"[s]top" "[s]top"
} else { } else {
"[s]tart" "[s]tart"
}), })];
Span::from(SPACE), spans.extend_from_slice(&[
Span::from("[r]eset"),
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"),
]); ]);
} }
spans.extend_from_slice(&[
Span::from(SPACE),
Span::from("[r]eset"),
]);
if self.selected_content == Content::Pomodoro { if self.selected_content == Content::Pomodoro {
spans.extend_from_slice(&[ spans.extend_from_slice(&[
Span::from(SPACE), Span::from(SPACE),
Span::from("[← →]switch work/pause"), Span::from("[^r]eset round"),
]); ]);
} }
spans spans
} }
others => vec![ _ => {
Span::from(match others { let mut spans = vec![Span::from("[s]ave changes")];
AppEditMode::Clock => "[e]dit done", if self.selected_content == Content::Countdown
AppEditMode::Time => "[^e]dit done", || self.selected_content == Content::Pomodoro
_ => "", {
}), spans.extend_from_slice(&[
Span::from(SPACE), 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!( Span::from(format!(
"[{} {}]edit selection", // ← →,
"[{} {}]change selection",
scrollbar::HORIZONTAL.begin, scrollbar::HORIZONTAL.begin,
scrollbar::HORIZONTAL.end scrollbar::HORIZONTAL.end
)), // ← →, )),
Span::from(SPACE), Span::from(SPACE),
Span::from(format!("[{}]edit up", scrollbar::VERTICAL.begin)), // ↑ Span::from(format!(
// ↑
"[{}]edit up",
scrollbar::VERTICAL.begin
)),
Span::from(SPACE), Span::from(SPACE),
Span::from(format!("[{}]edit up", scrollbar::VERTICAL.end)), // ↓, Span::from(format!(
// ↓
"[{}]edit up",
scrollbar::VERTICAL.end
)),
], ],
} }
})), })),

View File

@@ -5,9 +5,9 @@ use crate::{
utils::center, utils::center,
widgets::clock::{ClockState, ClockStateArgs, ClockWidget, Countdown}, widgets::clock::{ClockState, ClockStateArgs, ClockWidget, Countdown},
}; };
use crossterm::event::{KeyCode, KeyModifiers};
use ratatui::{ use ratatui::{
buffer::Buffer, buffer::Buffer,
crossterm::event::KeyCode,
layout::{Constraint, Layout, Rect}, layout::{Constraint, Layout, Rect},
text::Line, text::Line,
widgets::{StatefulWidget, Widget}, widgets::{StatefulWidget, Widget},
@@ -45,6 +45,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 +56,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 +69,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 +91,7 @@ impl PomodoroState {
}) })
.with_name("Pause".to_owned()), .with_name("Pause".to_owned()),
}, },
round,
} }
} }
@@ -111,6 +115,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;
@@ -132,34 +140,77 @@ impl TuiEventHandler for PomodoroState {
self.get_clock_mut().tick(); self.get_clock_mut().tick();
self.get_clock_mut().update_done_count(); 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 { TuiEvent::Key(key) => match key.code {
// Toggle run/pause
KeyCode::Char('s') => { KeyCode::Char('s') => {
self.get_clock_mut().toggle_pause(); self.get_clock_mut().toggle_pause();
} }
// Enter edit mode
KeyCode::Char('e') => { KeyCode::Char('e') => {
self.get_clock_mut().toggle_edit(); self.get_clock_mut().toggle_edit();
} }
KeyCode::Left if edit_mode => { // toggle WORK/PAUSE
self.get_clock_mut().edit_next();
}
KeyCode::Left => { 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(); self.next();
} }
KeyCode::Right if edit_mode => { // toggle WORK/PAUSE
self.get_clock_mut().edit_prev();
}
KeyCode::Right => { KeyCode::Right => {
self.next(); self.next();
} }
KeyCode::Up if edit_mode => { // reset round
self.get_clock_mut().edit_up(); KeyCode::Char('r') if key.modifiers.contains(KeyModifiers::CONTROL) => {
} self.round = 1;
KeyCode::Down if edit_mode => {
self.get_clock_mut().edit_down();
} }
// reset values
KeyCode::Char('r') => { 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), _ => return Some(event),
}, },
@@ -186,6 +237,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 +248,25 @@ 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(
// empty label + height of `label` + `label_round`
clock_widget.get_height() + 3,
),
); );
let [v1, v2] = let [v1, v2, v3, v4] = Layout::vertical(Constraint::from_lengths([
Layout::vertical(Constraint::from_lengths([clock_widget.get_height(), 1])).areas(area); 1,
clock_widget.get_height(),
1,
1,
]))
.areas(area);
clock_widget.render(v1, buf, state.get_clock_mut()); // empty line keep everything in center vertically comparing to other
label.centered().render(v2, buf); // 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);
} }
} }

View File

@@ -39,28 +39,51 @@ impl TuiEventHandler for TimerState {
self.clock.tick(); self.clock.tick();
self.clock.update_done_count(); 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 { TuiEvent::Key(key) => match key.code {
// Toggle run/pause
KeyCode::Char('s') => { KeyCode::Char('s') => {
self.clock.toggle_pause(); self.clock.toggle_pause();
} }
// reset clock
KeyCode::Char('r') => { KeyCode::Char('r') => {
self.clock.reset(); self.clock.reset();
} }
// enter edit mode
KeyCode::Char('e') => { KeyCode::Char('e') => {
self.clock.toggle_edit(); 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),
}, },
_ => return Some(event), _ => return Some(event),