Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e700691ba | ||
|
|
c29f8c5d1b | ||
|
|
ad11ff2c48 |
2
.github/workflows/release.yml
vendored
@@ -4,6 +4,8 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- "release/**"
|
- "release/**"
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
get-version:
|
get-version:
|
||||||
|
|||||||
55
CHANGELOG.md
@@ -1,59 +1,5 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## v1.4.0 - 2025-09-02
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
- (screen): Local Time [#89](https://github.com/sectore/timr-tui/pull/89), [#90](https://github.com/sectore/timr-tui/pull/90), [#91](https://github.com/sectore/timr-tui/pull/91)
|
|
||||||
|
|
||||||
### Misc.
|
|
||||||
|
|
||||||
- (deps) Rust 1.89.0 [#87](https://github.com/sectore/timr-tui/pull/87)
|
|
||||||
|
|
||||||
## v1.3.1 - 2025-07-03
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
- (args) set `content` by given duration [#81](https://github.com/sectore/timr-tui/pull/81)
|
|
||||||
|
|
||||||
### Fixes
|
|
||||||
|
|
||||||
- (pomodoro) `ctrl+r` resets rounds AND both clocks [#83](https://github.com/sectore/timr-tui/pull/83)
|
|
||||||
- (pomodoro) reset active clock only [#82](https://github.com/sectore/timr-tui/pull/82)
|
|
||||||
|
|
||||||
### Misc.
|
|
||||||
|
|
||||||
- (deps) Rust 1.88.0 [#85](https://github.com/sectore/timr-tui/pull/85)
|
|
||||||
|
|
||||||
## v1.3.0 - 2025-05-06
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
- (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
|
|
||||||
|
|
||||||
- (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
|
## v1.2.0 - 2025-02-26
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
@@ -69,6 +15,7 @@
|
|||||||
- (extension) Use `set_panic_hook` for better error handling [#67](https://github.com/sectore/timr-tui/pull/67)
|
- (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)
|
- (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
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|||||||
722
Cargo.lock
generated
22
Cargo.toml
@@ -1,41 +1,39 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "timr-tui"
|
name = "timr-tui"
|
||||||
version = "1.4.0"
|
version = "1.2.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.89.0"
|
rust-version = "1.85.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"
|
||||||
crossterm = { version = "0.28.1", features = ["event-stream", "serde"] }
|
crossterm = { version = "0.28.1", features = ["event-stream", "serde"] }
|
||||||
color-eyre = "0.6.5"
|
color-eyre = "0.6.2"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
strum = { version = "0.26.3", features = ["derive"] }
|
strum = { version = "0.26.3", features = ["derive"] }
|
||||||
tokio = { version = "1.45.1", features = ["full"] }
|
tokio = { version = "1.41.1", features = ["full"] }
|
||||||
tokio-stream = "0.1.17"
|
tokio-stream = "0.1.16"
|
||||||
tokio-util = "0.7.15"
|
tokio-util = "0.7.12"
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
|
||||||
directories = "5.0.1"
|
directories = "5.0.1"
|
||||||
clap = { version = "4.5.40", features = ["derive"] }
|
clap = { version = "4.5.23", features = ["derive"] }
|
||||||
time = { version = "0.3.41", features = ["formatting", "local-offset"] }
|
time = { version = "0.3.37", features = ["formatting", "local-offset"] }
|
||||||
notify-rust = "4.11.7"
|
notify-rust = "4.11.4"
|
||||||
rodio = { version = "0.20.1", features = [
|
rodio = { version = "0.20.1", features = [
|
||||||
"symphonia-mp3",
|
"symphonia-mp3",
|
||||||
"symphonia-wav",
|
"symphonia-wav",
|
||||||
], default-features = false, optional = true }
|
], default-features = false, optional = true }
|
||||||
thiserror = { version = "2.0.12", optional = true }
|
thiserror = { version = "2.0.11", optional = true }
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
sound = ["dep:rodio", "dep:thiserror"]
|
sound = ["dep:rodio", "dep:thiserror"]
|
||||||
|
|||||||
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024-2025 Jens Krause
|
Copyright (c) 2024 Jens K.
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
177
README.md
@@ -8,20 +8,9 @@ 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
|
||||||
|
|
||||||
# Table of Contents
|
_Side note:_ Theme colors depend on your terminal preferences.
|
||||||
|
|
||||||
- [Preview](./#preview)
|
|
||||||
- [CLI](./#cli)
|
|
||||||
- [Keybindings](./#keybindings)
|
|
||||||
- [Installation](./#installation)
|
|
||||||
- [Development](./#development)
|
|
||||||
- [Misc](./#misc)
|
|
||||||
- [License](./#license)
|
|
||||||
|
|
||||||
# Preview
|
|
||||||
|
|
||||||
_(theme depends on your terminal preferences)_
|
|
||||||
|
|
||||||
## Pomodoro
|
## Pomodoro
|
||||||
|
|
||||||
@@ -41,23 +30,10 @@ _(theme depends on your terminal preferences)_
|
|||||||
<img alt="countdown" src="demo/countdown.gif" />
|
<img alt="countdown" src="demo/countdown.gif" />
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
## Countdown: Mission Elapsed Time ([MET](https://en.wikipedia.org/wiki/Mission_Elapsed_Time))
|
## Change style
|
||||||
|
|
||||||
<a href="demo/countdown-met.gif">
|
<a href="demo/style.gif">
|
||||||
<img alt="menu" src="demo/countdown-met.gif" />
|
<img alt="style" src="demo/style.gif" />
|
||||||
</a>
|
|
||||||
|
|
||||||
|
|
||||||
## Local time
|
|
||||||
|
|
||||||
<a href="demo/local-time.gif">
|
|
||||||
<img alt="menu" src="demo/local-time.gif" />
|
|
||||||
</a>
|
|
||||||
|
|
||||||
## Local time (footer)
|
|
||||||
|
|
||||||
<a href="demo/local-time-footer.gif">
|
|
||||||
<img alt="menu" src="demo/local-time-footer.gif" />
|
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
## Toggle deciseconds
|
## Toggle deciseconds
|
||||||
@@ -66,18 +42,24 @@ _(theme depends on your terminal preferences)_
|
|||||||
<img alt="deciseconds" src="demo/decis.gif" />
|
<img alt="deciseconds" src="demo/decis.gif" />
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
## Change style
|
|
||||||
|
|
||||||
<a href="demo/style.gif">
|
|
||||||
<img alt="style" src="demo/style.gif" />
|
|
||||||
</a>
|
|
||||||
|
|
||||||
## Menu
|
## Menu
|
||||||
|
|
||||||
<a href="demo/menu.gif">
|
<a href="demo/menu.gif">
|
||||||
<img alt="menu" src="demo/menu.gif" />
|
<img alt="menu" src="demo/menu.gif" />
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
## Local time
|
||||||
|
|
||||||
|
<a href="demo/local-time.gif">
|
||||||
|
<img alt="menu" src="demo/local-time.gif" />
|
||||||
|
</a>
|
||||||
|
|
||||||
|
## Mission Elapsed Time ([MET](https://en.wikipedia.org/wiki/Mission_Elapsed_Time))
|
||||||
|
|
||||||
|
<a href="demo/countdown-met.gif">
|
||||||
|
<img alt="menu" src="demo/countdown-met.gif" />
|
||||||
|
</a>
|
||||||
|
|
||||||
# CLI
|
# CLI
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -90,7 +72,7 @@ Options:
|
|||||||
-w, --work <WORK> Work time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'
|
-w, --work <WORK> Work time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'
|
||||||
-p, --pause <PAUSE> Pause time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'
|
-p, --pause <PAUSE> Pause time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'
|
||||||
-d, --decis Show deciseconds.
|
-d, --decis Show deciseconds.
|
||||||
-m, --mode <MODE> Mode to start with. [possible values: countdown, timer, pomodoro, localtime]
|
-m, --mode <MODE> Mode to start with. [possible values: countdown, timer, pomodoro]
|
||||||
-s, --style <STYLE> Style to display time with. [possible values: full, light, medium, dark, thick, cross, braille]
|
-s, --style <STYLE> Style to display time with. [possible values: full, light, medium, dark, thick, cross, braille]
|
||||||
--menu Open the menu.
|
--menu Open the menu.
|
||||||
-r, --reset Reset stored values to default values.
|
-r, --reset Reset stored values to default values.
|
||||||
@@ -98,73 +80,14 @@ 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 |
|
|
||||||
| <kbd>l</kbd> | Local Time |
|
|
||||||
|
|
||||||
## 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 |
|
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
@@ -190,10 +113,12 @@ 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
|
||||||
@@ -204,6 +129,7 @@ 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)
|
||||||
@@ -217,42 +143,28 @@ If you have [`direnv`](https://direnv.net) installed, run `direnv allow` once to
|
|||||||
just
|
just
|
||||||
|
|
||||||
Available recipes:
|
Available recipes:
|
||||||
default # list commands
|
build # build app [alias: b]
|
||||||
|
default # list commands
|
||||||
[build]
|
demo-blink # build demo: blink animation [alias: db]
|
||||||
build # build app [alias: b]
|
demo-countdown # build demo: countdown [alias: dc]
|
||||||
|
demo-countdown-met # build demo: countdown + met [alias: dcm]
|
||||||
[demo]
|
demo-decis # build demo: deciseconds [alias: dd]
|
||||||
demo-blink # build demo: blink animation [alias: db]
|
demo-local-time # build demo: local time [alias: dlt]
|
||||||
demo-countdown # build demo: countdown [alias: dc]
|
demo-menu # build demo: menu [alias: dm]
|
||||||
demo-countdown-met # build demo: countdown + met [alias: dcm]
|
demo-pomodoro # build demo: pomodoro [alias: dp]
|
||||||
demo-decis # build demo: deciseconds [alias: dd]
|
demo-rocket-countdown # build demo: rocket countdown [alias: drc]
|
||||||
demo-local-time # build demo: local time [alias: dlt]
|
demo-style # build demo: styles [alias: ds]
|
||||||
demo-local-time-footer # build demo: local time (footer) [alias: dltf]
|
demo-timer # build demo: timer [alias: dt]
|
||||||
demo-menu # build demo: menu [alias: dm]
|
format # format files [alias: f]
|
||||||
demo-pomodoro # build demo: pomodoro [alias: dp]
|
lint # lint [alias: l]
|
||||||
demo-rocket-countdown # build demo: rocket countdown [alias: drc]
|
run # run app [alias: r]
|
||||||
demo-style # build demo: styles [alias: ds]
|
run-sound path # run app while sound feature is enabled. It expects a path to a sound file. [alias: rs]
|
||||||
demo-timer # build demo: timer [alias: dt]
|
test # run tests [alias: t]
|
||||||
|
|
||||||
[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
|
# or for bulding w/ statically linked binaries
|
||||||
@@ -260,17 +172,10 @@ 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
|
||||||
@@ -302,7 +207,3 @@ 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)
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 15 KiB |
@@ -1,20 +0,0 @@
|
|||||||
Output demo/local-time-footer.gif
|
|
||||||
|
|
||||||
# https://github.com/charmbracelet/vhs/blob/main/THEMES.md
|
|
||||||
Set Theme "AtomOneLight"
|
|
||||||
|
|
||||||
Set FontSize 14
|
|
||||||
Set Width 800
|
|
||||||
Set Height 400
|
|
||||||
Set Padding 0
|
|
||||||
Set Margin 1
|
|
||||||
|
|
||||||
# --- START ---
|
|
||||||
Set LoopOffset 4
|
|
||||||
Hide
|
|
||||||
Type "cargo run -- -m c"
|
|
||||||
Enter
|
|
||||||
Sleep 0.2
|
|
||||||
Show
|
|
||||||
# --- toggle local time ---
|
|
||||||
Type@1.5s ":::"
|
|
||||||
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 17 KiB |
@@ -1,7 +1,7 @@
|
|||||||
Output demo/local-time.gif
|
Output demo/local-time.gif
|
||||||
|
|
||||||
# https://github.com/charmbracelet/vhs/blob/main/THEMES.md
|
# https://github.com/charmbracelet/vhs/blob/main/THEMES.md
|
||||||
Set Theme "Atom"
|
Set Theme "AtomOneLight"
|
||||||
|
|
||||||
Set FontSize 14
|
Set FontSize 14
|
||||||
Set Width 800
|
Set Width 800
|
||||||
@@ -12,9 +12,11 @@ Set Margin 1
|
|||||||
# --- START ---
|
# --- START ---
|
||||||
Set LoopOffset 4
|
Set LoopOffset 4
|
||||||
Hide
|
Hide
|
||||||
Type "cargo run -- -m l"
|
Type "cargo run -- -m c"
|
||||||
Enter
|
Enter
|
||||||
Sleep 0.2
|
Sleep 0.2
|
||||||
Show
|
Show
|
||||||
|
Sleep 1
|
||||||
# --- toggle local time ---
|
# --- toggle local time ---
|
||||||
Type@1.5s ":::"
|
Type@1.5s ":::"
|
||||||
|
Sleep 1.5
|
||||||
|
|||||||
BIN
demo/menu.gif
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 106 KiB |
@@ -12,15 +12,19 @@ Set Margin 1
|
|||||||
# --- START ---
|
# --- START ---
|
||||||
Set LoopOffset 4
|
Set LoopOffset 4
|
||||||
Hide
|
Hide
|
||||||
Type "cargo run -- -r -m p --menu"
|
Type "cargo run -- -r -m p"
|
||||||
Enter
|
Enter
|
||||||
Type@200ms "m"
|
Sleep 0.2
|
||||||
Show
|
Show
|
||||||
# --- STYLES ---
|
# --- STYLES ---
|
||||||
Sleep 0.3s
|
Sleep 0.5
|
||||||
Type@0.3s "m"
|
Type "m"
|
||||||
Type@0.3s "t"
|
Sleep 0.5
|
||||||
Type@0.3s "c"
|
Type@0.5s "t"
|
||||||
Type@0.3s "p"
|
Type@0.5s "c"
|
||||||
Type@0.3s "e"
|
Type@0.5s "p"
|
||||||
Escape@0.3s
|
Type@0.5s "e"
|
||||||
|
Right@0.5s
|
||||||
|
Left@0.5s
|
||||||
|
Type@0.5s "e"
|
||||||
|
Sleep 0.5
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 166 KiB |
@@ -10,8 +10,9 @@ Set Padding 0
|
|||||||
Set Margin 1
|
Set Margin 1
|
||||||
|
|
||||||
# --- START ---
|
# --- START ---
|
||||||
|
Set LoopOffset 4
|
||||||
Hide
|
Hide
|
||||||
Type "cargo run -- -d -m p --blink on"
|
Type "cargo run -- -r -d -m p"
|
||||||
Enter
|
Enter
|
||||||
Sleep 0.2
|
Sleep 0.2
|
||||||
Show
|
Show
|
||||||
@@ -24,7 +25,7 @@ Sleep 0.2
|
|||||||
Down@30ms 80
|
Down@30ms 80
|
||||||
Sleep 100ms
|
Sleep 100ms
|
||||||
Type "e"
|
Type "e"
|
||||||
Sleep 4
|
Sleep 3
|
||||||
# --- POMODORO PAUSE ---
|
# --- POMODORO PAUSE ---
|
||||||
Right
|
Right
|
||||||
Sleep 0.5
|
Sleep 0.5
|
||||||
@@ -35,4 +36,4 @@ Sleep 0.2
|
|||||||
Down@30ms 60
|
Down@30ms 60
|
||||||
Sleep 100ms
|
Sleep 100ms
|
||||||
Type "e"
|
Type "e"
|
||||||
Sleep 4
|
Sleep 3
|
||||||
|
|||||||
24
flake.lock
generated
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"crane": {
|
"crane": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1754269165,
|
"lastModified": 1739936662,
|
||||||
"narHash": "sha256-0tcS8FHd4QjbCVoxN9jI+PjHgA4vc/IjkUSp+N3zy0U=",
|
"narHash": "sha256-x4syUjNUuRblR07nDPeLDP7DpphaBVbUaSoeZkFbGSk=",
|
||||||
"owner": "ipetkov",
|
"owner": "ipetkov",
|
||||||
"repo": "crane",
|
"repo": "crane",
|
||||||
"rev": "444e81206df3f7d92780680e45858e31d2f07a08",
|
"rev": "19de14aaeb869287647d9461cbd389187d8ecdb7",
|
||||||
"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": 1755240331,
|
"lastModified": 1740378829,
|
||||||
"narHash": "sha256-wEtw76+R/TOHEIjYOnxADC91G6s422HGruAngbjzsDw=",
|
"narHash": "sha256-cwmm7F73aQFJY6YN1roNibNKwxT6FlfXkG3MEbpSp7Q=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "fenix",
|
"repo": "fenix",
|
||||||
"rev": "3f076d4502001c64877099093318b2dbd8b062a1",
|
"rev": "92823f1b0c919d7e2d806956aaf98e90f3761ab7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -56,11 +56,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1755027561,
|
"lastModified": 1740367490,
|
||||||
"narHash": "sha256-IVft239Bc8p8Dtvf7UAACMG5P3ZV+3/aO28gXpGtMXI=",
|
"narHash": "sha256-WGaHVAjcrv+Cun7zPlI41SerRtfknGQap281+AakSAw=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "005433b926e16227259a1843015b5b2b7f7d1fc3",
|
"rev": "0196c0175e9191c474c26ab5548db27ef5d34b05",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -81,11 +81,11 @@
|
|||||||
"rust-analyzer-src": {
|
"rust-analyzer-src": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1755004716,
|
"lastModified": 1740329432,
|
||||||
"narHash": "sha256-TbhPR5Fqw5LjAeI3/FOPhNNFQCF3cieKCJWWupeZmiA=",
|
"narHash": "sha256-eKQ7aBkNvF5AhUpyJ1cW450jxomZ4gTIaYir5qsNl7Y=",
|
||||||
"owner": "rust-lang",
|
"owner": "rust-lang",
|
||||||
"repo": "rust-analyzer",
|
"repo": "rust-analyzer",
|
||||||
"rev": "b2a58b8c6eff3c3a2c8b5c70dbf69ead78284194",
|
"rev": "6d68c475c7aaf7534251182662456a4bf4216dfe",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
14
flake.nix
@@ -23,8 +23,8 @@
|
|||||||
fenix.packages.${system}.fromToolchainFile
|
fenix.packages.${system}.fromToolchainFile
|
||||||
{
|
{
|
||||||
file = ./rust-toolchain.toml;
|
file = ./rust-toolchain.toml;
|
||||||
#sha256 = nixpkgs.lib.fakeSha256;
|
# sha256 = nixpkgs.lib.fakeSha256;
|
||||||
sha256 = "sha256-+9FmLhAOezBZCOziO0Qct1NOrfpjNsXxc/8I0c7BdKE=";
|
sha256 = "sha256-AJ6LX/Q/Er9kS15bn9iflkUwcgYqRQxiOIL2ToVAXaU=";
|
||||||
};
|
};
|
||||||
|
|
||||||
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
|
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
|
||||||
@@ -88,12 +88,16 @@
|
|||||||
# 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-with-plugins.override {
|
pkgs.alsa-lib.dev
|
||||||
plugins = [pkgs.alsa-plugins pkgs.pipewire];
|
pkgs.pipewire
|
||||||
})
|
|
||||||
];
|
];
|
||||||
|
|
||||||
inherit (commonArgs) src;
|
inherit (commonArgs) src;
|
||||||
|
|
||||||
|
ALSA_PLUGIN_DIR =
|
||||||
|
if stdenv.isLinux
|
||||||
|
then "${pkgs.pipewire}/lib/alsa-lib/"
|
||||||
|
else "";
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
37
justfile
@@ -9,21 +9,18 @@ default:
|
|||||||
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
|
||||||
@@ -31,113 +28,79 @@ 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
|
# 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
|
# 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
|
# 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
|
# 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
|
# 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
|
# 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
|
# 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
|
# build demo: local time
|
||||||
[group('demo')]
|
|
||||||
demo-local-time:
|
demo-local-time:
|
||||||
vhs demo/local-time.tape
|
vhs demo/local-time.tape
|
||||||
|
|
||||||
alias dltf := demo-local-time-footer
|
|
||||||
|
|
||||||
# build demo: local time (footer)
|
|
||||||
[group('demo')]
|
|
||||||
demo-local-time-footer:
|
|
||||||
vhs demo/local-time-footer.tape
|
|
||||||
|
|
||||||
alias drc := demo-rocket-countdown
|
alias drc := demo-rocket-countdown
|
||||||
|
|
||||||
# build 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
|
# build demo: blink animation
|
||||||
[group('demo')]
|
|
||||||
demo-blink:
|
demo-blink:
|
||||||
vhs demo/blink.tape
|
vhs demo/blink.tape
|
||||||
|
|||||||
@@ -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.89.0"
|
channel = "1.85.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"
|
||||||
|
|||||||
99
src/app.rs
@@ -10,7 +10,6 @@ use crate::{
|
|||||||
countdown::{Countdown, CountdownState, CountdownStateArgs},
|
countdown::{Countdown, CountdownState, CountdownStateArgs},
|
||||||
footer::{Footer, FooterState},
|
footer::{Footer, FooterState},
|
||||||
header::Header,
|
header::Header,
|
||||||
local_time::{LocalTimeState, LocalTimeStateArgs, LocalTimeWidget},
|
|
||||||
pomodoro::{Mode as PomodoroMode, PomodoroState, PomodoroStateArgs, PomodoroWidget},
|
pomodoro::{Mode as PomodoroMode, PomodoroState, PomodoroStateArgs, PomodoroWidget},
|
||||||
timer::{Timer, TimerState},
|
timer::{Timer, TimerState},
|
||||||
},
|
},
|
||||||
@@ -45,11 +44,9 @@ pub struct App {
|
|||||||
#[allow(dead_code)] // w/ `--features sound` available only
|
#[allow(dead_code)] // w/ `--features sound` available only
|
||||||
sound_path: Option<PathBuf>,
|
sound_path: Option<PathBuf>,
|
||||||
app_time: AppTime,
|
app_time: AppTime,
|
||||||
app_time_format: AppTimeFormat,
|
|
||||||
countdown: CountdownState,
|
countdown: CountdownState,
|
||||||
timer: TimerState,
|
timer: TimerState,
|
||||||
pomodoro: PomodoroState,
|
pomodoro: PomodoroState,
|
||||||
local_time: LocalTimeState,
|
|
||||||
style: Style,
|
style: Style,
|
||||||
with_decis: bool,
|
with_decis: bool,
|
||||||
footer: FooterState,
|
footer: FooterState,
|
||||||
@@ -64,7 +61,6 @@ 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,
|
||||||
@@ -75,7 +71,6 @@ pub struct AppArgs {
|
|||||||
pub current_value_timer: Duration,
|
pub current_value_timer: Duration,
|
||||||
pub app_tx: events::AppEventTx,
|
pub app_tx: events::AppEventTx,
|
||||||
pub sound_path: Option<PathBuf>,
|
pub sound_path: Option<PathBuf>,
|
||||||
pub footer_toggle_app_time: Toggle,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FromAppArgs {
|
pub struct FromAppArgs {
|
||||||
@@ -96,25 +91,9 @@ impl From<FromAppArgs> for App {
|
|||||||
notification: args.notification.unwrap_or(stg.notification),
|
notification: args.notification.unwrap_or(stg.notification),
|
||||||
blink: args.blink.unwrap_or(stg.blink),
|
blink: args.blink.unwrap_or(stg.blink),
|
||||||
app_time_format: stg.app_time_format,
|
app_time_format: stg.app_time_format,
|
||||||
// Check args to set a possible mode to start with.
|
content: args.mode.unwrap_or(stg.content),
|
||||||
content: match args.mode {
|
|
||||||
Some(mode) => mode,
|
|
||||||
// check other args (especially durations)
|
|
||||||
None => {
|
|
||||||
if args.work.is_some() || args.pause.is_some() {
|
|
||||||
Content::Pomodoro
|
|
||||||
} else if args.countdown.is_some() {
|
|
||||||
Content::Countdown
|
|
||||||
}
|
|
||||||
// in other case just use latest stored state
|
|
||||||
else {
|
|
||||||
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),
|
||||||
@@ -124,18 +103,13 @@ 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: match args.countdown {
|
elapsed_value_countdown: stg.elapsed_value_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")]
|
||||||
sound_path: args.sound,
|
sound_path: args.sound,
|
||||||
#[cfg(not(feature = "sound"))]
|
#[cfg(not(feature = "sound"))]
|
||||||
sound_path: None,
|
sound_path: None,
|
||||||
footer_toggle_app_time: stg.footer_app_time,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,12 +138,10 @@ impl App {
|
|||||||
content,
|
content,
|
||||||
with_decis,
|
with_decis,
|
||||||
pomodoro_mode,
|
pomodoro_mode,
|
||||||
pomodoro_round,
|
|
||||||
notification,
|
notification,
|
||||||
blink,
|
blink,
|
||||||
sound_path,
|
sound_path,
|
||||||
app_tx,
|
app_tx,
|
||||||
footer_toggle_app_time,
|
|
||||||
} = args;
|
} = args;
|
||||||
let app_time = get_app_time();
|
let app_time = get_app_time();
|
||||||
|
|
||||||
@@ -180,7 +152,6 @@ impl App {
|
|||||||
sound_path,
|
sound_path,
|
||||||
content,
|
content,
|
||||||
app_time,
|
app_time,
|
||||||
app_time_format,
|
|
||||||
style,
|
style,
|
||||||
with_decis,
|
with_decis,
|
||||||
countdown: CountdownState::new(CountdownStateArgs {
|
countdown: CountdownState::new(CountdownStateArgs {
|
||||||
@@ -208,21 +179,9 @@ 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(),
|
||||||
}),
|
}),
|
||||||
local_time: LocalTimeState::new(LocalTimeStateArgs {
|
footer: FooterState::new(show_menu, app_time_format),
|
||||||
app_time,
|
|
||||||
app_time_format,
|
|
||||||
}),
|
|
||||||
footer: FooterState::new(
|
|
||||||
show_menu,
|
|
||||||
if footer_toggle_app_time == Toggle::On {
|
|
||||||
Some(app_time_format)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,43 +194,12 @@ 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') => app.mode = Mode::Quit,
|
KeyCode::Char('q') | KeyCode::Esc => 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,
|
||||||
KeyCode::Char('l') => app.content = Content::LocalTime,
|
|
||||||
// toogle app time format
|
// toogle app time format
|
||||||
KeyCode::Char(':') => {
|
KeyCode::Char(':') => app.footer.toggle_app_time_format(),
|
||||||
if app.content == Content::LocalTime {
|
|
||||||
// For LocalTime content: just cycle through formats
|
|
||||||
app.app_time_format = app.app_time_format.next();
|
|
||||||
app.local_time.set_app_time_format(app.app_time_format);
|
|
||||||
// Only update footer if it's currently showing time
|
|
||||||
if app.footer.app_time_format().is_some() {
|
|
||||||
app.footer.set_app_time_format(Some(app.app_time_format));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// For other content: allow footer to toggle between formats and None
|
|
||||||
let new_format = match app.footer.app_time_format() {
|
|
||||||
// footer is hidden -> show first format
|
|
||||||
None => Some(AppTimeFormat::first()),
|
|
||||||
Some(v) => {
|
|
||||||
if v != &AppTimeFormat::last() {
|
|
||||||
Some(v.next())
|
|
||||||
} else {
|
|
||||||
// reached last format -> hide footer time
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(format) = new_format {
|
|
||||||
app.app_time_format = format;
|
|
||||||
app.local_time.set_app_time_format(format);
|
|
||||||
}
|
|
||||||
app.footer.set_app_time_format(new_format);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// toogle menu
|
// toogle menu
|
||||||
KeyCode::Char('m') => app.footer.set_show_menu(!app.footer.get_show_menu()),
|
KeyCode::Char('m') => app.footer.set_show_menu(!app.footer.get_show_menu()),
|
||||||
KeyCode::Char(',') => {
|
KeyCode::Char(',') => {
|
||||||
@@ -294,7 +222,6 @@ impl App {
|
|||||||
if matches!(event, events::TuiEvent::Tick) {
|
if matches!(event, events::TuiEvent::Tick) {
|
||||||
app.app_time = get_app_time();
|
app.app_time = get_app_time();
|
||||||
app.countdown.set_app_time(app.app_time);
|
app.countdown.set_app_time(app.app_time);
|
||||||
app.local_time.set_app_time(app.app_time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pipe events into subviews and handle only 'unhandled' events afterwards
|
// Pipe events into subviews and handle only 'unhandled' events afterwards
|
||||||
@@ -302,7 +229,6 @@ impl App {
|
|||||||
Content::Countdown => app.countdown.update(event.clone()),
|
Content::Countdown => app.countdown.update(event.clone()),
|
||||||
Content::Timer => app.timer.update(event.clone()),
|
Content::Timer => app.timer.update(event.clone()),
|
||||||
Content::Pomodoro => app.pomodoro.update(event.clone()),
|
Content::Pomodoro => app.pomodoro.update(event.clone()),
|
||||||
Content::LocalTime => app.local_time.update(event.clone()),
|
|
||||||
} {
|
} {
|
||||||
match unhandled {
|
match unhandled {
|
||||||
events::TuiEvent::Render | events::TuiEvent::Resize => {
|
events::TuiEvent::Render | events::TuiEvent::Resize => {
|
||||||
@@ -327,7 +253,7 @@ impl App {
|
|||||||
ClockTypeId::Timer => {
|
ClockTypeId::Timer => {
|
||||||
format!("{name} stopped by reaching its maximum value.")
|
format!("{name} stopped by reaching its maximum value.")
|
||||||
}
|
}
|
||||||
_ => format!("{type_id:?} {name} done!"),
|
_ => format!("{:?} {name} done!", type_id),
|
||||||
};
|
};
|
||||||
// notification
|
// notification
|
||||||
let result = notify_rust::Notification::new()
|
let result = notify_rust::Notification::new()
|
||||||
@@ -393,7 +319,6 @@ impl App {
|
|||||||
AppEditMode::None
|
AppEditMode::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Content::LocalTime => AppEditMode::None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,8 +327,6 @@ impl App {
|
|||||||
Content::Countdown => self.countdown.is_running(),
|
Content::Countdown => self.countdown.is_running(),
|
||||||
Content::Timer => self.timer.get_clock().is_running(),
|
Content::Timer => self.timer.get_clock().is_running(),
|
||||||
Content::Pomodoro => self.pomodoro.get_clock().is_running(),
|
Content::Pomodoro => self.pomodoro.get_clock().is_running(),
|
||||||
// `LocalTime` does not use a `Clock`
|
|
||||||
Content::LocalTime => false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,7 +335,6 @@ impl App {
|
|||||||
Content::Countdown => Some(self.countdown.get_clock().get_percentage_done()),
|
Content::Countdown => Some(self.countdown.get_clock().get_percentage_done()),
|
||||||
Content::Timer => None,
|
Content::Timer => None,
|
||||||
Content::Pomodoro => Some(self.pomodoro.get_clock().get_percentage_done()),
|
Content::Pomodoro => Some(self.pomodoro.get_clock().get_percentage_done()),
|
||||||
Content::LocalTime => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,11 +351,10 @@ impl App {
|
|||||||
show_menu: self.footer.get_show_menu(),
|
show_menu: self.footer.get_show_menu(),
|
||||||
notification: self.notification,
|
notification: self.notification,
|
||||||
blink: self.blink,
|
blink: self.blink,
|
||||||
app_time_format: self.app_time_format,
|
app_time_format: *self.footer.app_time_format(),
|
||||||
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(
|
||||||
@@ -448,7 +369,6 @@ impl App {
|
|||||||
),
|
),
|
||||||
elapsed_value_countdown: Duration::from(*self.countdown.get_elapsed_value()),
|
elapsed_value_countdown: Duration::from(*self.countdown.get_elapsed_value()),
|
||||||
current_value_timer: Duration::from(*self.timer.get_clock().get_current_value()),
|
current_value_timer: Duration::from(*self.timer.get_clock().get_current_value()),
|
||||||
footer_app_time: self.footer.app_time_format().is_some().into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -475,9 +395,6 @@ impl AppWidget {
|
|||||||
blink: state.blink == Toggle::On,
|
blink: state.blink == Toggle::On,
|
||||||
}
|
}
|
||||||
.render(area, buf, &mut state.pomodoro),
|
.render(area, buf, &mut state.pomodoro),
|
||||||
Content::LocalTime => {
|
|
||||||
LocalTimeWidget { style: state.style }.render(area, buf, &mut state.local_time);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -488,7 +405,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() { 5 } else { 1 }),
|
Constraint::Length(if state.footer.get_show_menu() { 4 } else { 1 }),
|
||||||
])
|
])
|
||||||
.areas(area);
|
.areas(area);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use ratatui::symbols::shade;
|
use ratatui::symbols::shade;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::EnumString;
|
use time::OffsetDateTime;
|
||||||
use time::{OffsetDateTime, format_description};
|
use time::format_description;
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Default, Serialize, Deserialize,
|
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Default, Serialize, Deserialize,
|
||||||
@@ -15,8 +15,6 @@ pub enum Content {
|
|||||||
Timer,
|
Timer,
|
||||||
#[value(name = "pomodoro", alias = "p")]
|
#[value(name = "pomodoro", alias = "p")]
|
||||||
Pomodoro,
|
Pomodoro,
|
||||||
#[value(name = "localtime", alias = "l")]
|
|
||||||
LocalTime,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -73,7 +71,7 @@ impl Style {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default, PartialEq, EnumString, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
|
||||||
pub enum AppTimeFormat {
|
pub enum AppTimeFormat {
|
||||||
/// `hh:mm:ss`
|
/// `hh:mm:ss`
|
||||||
#[default]
|
#[default]
|
||||||
@@ -82,22 +80,17 @@ pub enum AppTimeFormat {
|
|||||||
HhMm,
|
HhMm,
|
||||||
/// `hh:mm AM` (or PM)
|
/// `hh:mm AM` (or PM)
|
||||||
Hh12Mm,
|
Hh12Mm,
|
||||||
|
/// `` (empty)
|
||||||
|
Hidden,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppTimeFormat {
|
impl AppTimeFormat {
|
||||||
pub const fn first() -> Self {
|
|
||||||
Self::HhMmSs
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn last() -> Self {
|
|
||||||
Self::Hh12Mm
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next(&self) -> Self {
|
pub fn next(&self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
AppTimeFormat::HhMmSs => AppTimeFormat::HhMm,
|
AppTimeFormat::HhMmSs => AppTimeFormat::HhMm,
|
||||||
AppTimeFormat::HhMm => AppTimeFormat::Hh12Mm,
|
AppTimeFormat::HhMm => AppTimeFormat::Hh12Mm,
|
||||||
AppTimeFormat::Hh12Mm => AppTimeFormat::HhMmSs,
|
AppTimeFormat::Hh12Mm => AppTimeFormat::Hidden,
|
||||||
|
AppTimeFormat::Hidden => AppTimeFormat::HhMmSs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,43 +113,24 @@ impl From<AppTime> for OffsetDateTime {
|
|||||||
impl AppTime {
|
impl AppTime {
|
||||||
pub fn format(&self, app_format: &AppTimeFormat) -> String {
|
pub fn format(&self, app_format: &AppTimeFormat) -> String {
|
||||||
let parse_str = match app_format {
|
let parse_str = match app_format {
|
||||||
AppTimeFormat::HhMmSs => "[hour]:[minute]:[second]",
|
AppTimeFormat::HhMmSs => Some("[hour]:[minute]:[second]"),
|
||||||
AppTimeFormat::HhMm => "[hour]:[minute]",
|
AppTimeFormat::HhMm => Some("[hour]:[minute]"),
|
||||||
AppTimeFormat::Hh12Mm => "[hour repr:12 padding:none]:[minute] [period]",
|
AppTimeFormat::Hh12Mm => Some("[hour repr:12 padding:none]:[minute] [period]"),
|
||||||
|
AppTimeFormat::Hidden => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
format_description::parse(parse_str)
|
if let Some(str) = parse_str {
|
||||||
.map_err(|_| "parse error")
|
format_description::parse(str)
|
||||||
.and_then(|fd| {
|
.map_err(|_| "parse error")
|
||||||
OffsetDateTime::from(*self)
|
.and_then(|fd| {
|
||||||
.format(&fd)
|
OffsetDateTime::from(*self)
|
||||||
.map_err(|_| "format error")
|
.format(&fd)
|
||||||
})
|
.map_err(|_| "format error")
|
||||||
.unwrap_or_else(|e| e.to_string())
|
})
|
||||||
}
|
.unwrap_or_else(|e| e.to_string())
|
||||||
|
} else {
|
||||||
pub fn get_period(&self) -> String {
|
"".to_owned()
|
||||||
format_description::parse("[period]")
|
}
|
||||||
.map_err(|_| "parse error")
|
|
||||||
.and_then(|fd| {
|
|
||||||
OffsetDateTime::from(*self)
|
|
||||||
.format(&fd)
|
|
||||||
.map_err(|_| "format error")
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|e| e.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts `AppTime` into a `Duration` representing elapsed time since midnight (today).
|
|
||||||
pub fn as_duration_of_today(&self) -> std::time::Duration {
|
|
||||||
let dt = OffsetDateTime::from(*self);
|
|
||||||
let time = dt.time();
|
|
||||||
|
|
||||||
let total_nanos = u64::from(time.hour()) * 3_600_000_000_000
|
|
||||||
+ u64::from(time.minute()) * 60_000_000_000
|
|
||||||
+ u64::from(time.second()) * 1_000_000_000
|
|
||||||
+ u64::from(time.nanosecond());
|
|
||||||
|
|
||||||
std::time::Duration::from_nanos(total_nanos)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,15 +150,6 @@ pub enum Toggle {
|
|||||||
Off,
|
Off,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<bool> for Toggle {
|
|
||||||
fn from(value: bool) -> Self {
|
|
||||||
match value {
|
|
||||||
true => Toggle::On,
|
|
||||||
false => Toggle::Off,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
@@ -231,5 +196,12 @@ mod tests {
|
|||||||
"6:06 PM",
|
"6:06 PM",
|
||||||
"local"
|
"local"
|
||||||
);
|
);
|
||||||
|
// hidden
|
||||||
|
assert_eq!(AppTime::Utc(dt).format(&AppTimeFormat::Hidden), "", "utc");
|
||||||
|
assert_eq!(
|
||||||
|
AppTime::Local(dt).format(&AppTimeFormat::Hidden),
|
||||||
|
"",
|
||||||
|
"local"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,19 +60,10 @@ impl DurationEx {
|
|||||||
self.seconds() / (SECS_PER_MINUTE * MINS_PER_HOUR)
|
self.seconds() / (SECS_PER_MINUTE * MINS_PER_HOUR)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hours as 24-hour clock
|
|
||||||
pub fn hours_mod(&self) -> u64 {
|
pub fn hours_mod(&self) -> u64 {
|
||||||
self.hours() % HOURS_PER_DAY
|
self.hours() % HOURS_PER_DAY
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hours as 12-hour clock
|
|
||||||
pub fn hours_mod_12(&self) -> u64 {
|
|
||||||
// 0 => 12,
|
|
||||||
// 1..=12 => hours,
|
|
||||||
// 13..=23 => hours - 12,
|
|
||||||
(self.hours_mod() + 11) % 12 + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn minutes(&self) -> u64 {
|
pub fn minutes(&self) -> u64 {
|
||||||
self.seconds() / MINS_PER_HOUR
|
self.seconds() / MINS_PER_HOUR
|
||||||
}
|
}
|
||||||
@@ -186,22 +177,22 @@ mod tests {
|
|||||||
fn test_fmt() {
|
fn test_fmt() {
|
||||||
// hh:mm:ss
|
// hh:mm:ss
|
||||||
let ex: DurationEx = Duration::from_secs(36001).into();
|
let ex: DurationEx = Duration::from_secs(36001).into();
|
||||||
assert_eq!(format!("{ex}"), "10:00:01");
|
assert_eq!(format!("{}", ex), "10:00:01");
|
||||||
// h:mm:ss
|
// h:mm:ss
|
||||||
let ex: DurationEx = Duration::from_secs(3601).into();
|
let ex: DurationEx = Duration::from_secs(3601).into();
|
||||||
assert_eq!(format!("{ex}"), "1:00:01");
|
assert_eq!(format!("{}", ex), "1:00:01");
|
||||||
// mm:ss
|
// mm:ss
|
||||||
let ex: DurationEx = Duration::from_secs(71).into();
|
let ex: DurationEx = Duration::from_secs(71).into();
|
||||||
assert_eq!(format!("{ex}"), "1:11");
|
assert_eq!(format!("{}", ex), "1:11");
|
||||||
// m:ss
|
// m:ss
|
||||||
let ex: DurationEx = Duration::from_secs(61).into();
|
let ex: DurationEx = Duration::from_secs(61).into();
|
||||||
assert_eq!(format!("{ex}"), "1:01");
|
assert_eq!(format!("{}", ex), "1:01");
|
||||||
// ss
|
// ss
|
||||||
let ex: DurationEx = Duration::from_secs(11).into();
|
let ex: DurationEx = Duration::from_secs(11).into();
|
||||||
assert_eq!(format!("{ex}"), "11");
|
assert_eq!(format!("{}", ex), "11");
|
||||||
// s
|
// s
|
||||||
let ex: DurationEx = Duration::from_secs(1).into();
|
let ex: DurationEx = Duration::from_secs(1).into();
|
||||||
assert_eq!(format!("{ex}"), "1");
|
assert_eq!(format!("{}", ex), "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -209,7 +200,7 @@ mod tests {
|
|||||||
let ex: DurationEx = Duration::from_secs(10).into();
|
let ex: DurationEx = Duration::from_secs(10).into();
|
||||||
let ex2: DurationEx = Duration::from_secs(1).into();
|
let ex2: DurationEx = Duration::from_secs(1).into();
|
||||||
let ex3 = ex.saturating_sub(ex2);
|
let ex3 = ex.saturating_sub(ex2);
|
||||||
assert_eq!(format!("{ex3}"), "9");
|
assert_eq!(format!("{}", ex3), "9");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -217,35 +208,7 @@ mod tests {
|
|||||||
let ex: DurationEx = Duration::from_secs(10).into();
|
let ex: DurationEx = Duration::from_secs(10).into();
|
||||||
let ex2: DurationEx = Duration::from_secs(1).into();
|
let ex2: DurationEx = Duration::from_secs(1).into();
|
||||||
let ex3 = ex.saturating_add(ex2);
|
let ex3 = ex.saturating_add(ex2);
|
||||||
assert_eq!(format!("{ex3}"), "11");
|
assert_eq!(format!("{}", ex3), "11");
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_hours_mod_12() {
|
|
||||||
// 24 -> 12
|
|
||||||
let ex: DurationEx = ONE_HOUR.saturating_mul(24).into();
|
|
||||||
let result = ex.hours_mod_12();
|
|
||||||
assert_eq!(result, 12);
|
|
||||||
|
|
||||||
// 12 -> 12
|
|
||||||
let ex: DurationEx = ONE_HOUR.saturating_mul(12).into();
|
|
||||||
let result = ex.hours_mod_12();
|
|
||||||
assert_eq!(result, 12);
|
|
||||||
|
|
||||||
// 0 -> 12
|
|
||||||
let ex: DurationEx = ONE_SECOND.into();
|
|
||||||
let result = ex.hours_mod_12();
|
|
||||||
assert_eq!(result, 12);
|
|
||||||
|
|
||||||
// 13 -> 1
|
|
||||||
let ex: DurationEx = ONE_HOUR.saturating_mul(13).into();
|
|
||||||
let result = ex.hours_mod_12();
|
|
||||||
assert_eq!(result, 1);
|
|
||||||
|
|
||||||
// 1 -> 1
|
|
||||||
let ex: DurationEx = ONE_HOUR.saturating_mul(1).into();
|
|
||||||
let result = ex.hours_mod_12();
|
|
||||||
assert_eq!(result, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -3,35 +3,21 @@ use crate::{
|
|||||||
widgets::pomodoro::Mode as PomodoroMode,
|
widgets::pomodoro::Mode as PomodoroMode,
|
||||||
};
|
};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
fn deserialize_app_time_format<'de, D>(deserializer: D) -> Result<AppTimeFormat, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let s = String::deserialize(deserializer)?;
|
|
||||||
match s.as_str() {
|
|
||||||
// Hidden is deprecated - use `default` value instead
|
|
||||||
"Hidden" => Ok(AppTimeFormat::default()),
|
|
||||||
_ => s.parse().map_err(serde::de::Error::custom),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct AppStorage {
|
pub struct AppStorage {
|
||||||
pub content: Content,
|
pub content: Content,
|
||||||
pub show_menu: bool,
|
pub show_menu: bool,
|
||||||
pub notification: Toggle,
|
pub notification: Toggle,
|
||||||
pub blink: Toggle,
|
pub blink: Toggle,
|
||||||
#[serde(deserialize_with = "deserialize_app_time_format")]
|
|
||||||
pub app_time_format: AppTimeFormat,
|
pub app_time_format: AppTimeFormat,
|
||||||
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,
|
||||||
@@ -44,8 +30,6 @@ pub struct AppStorage {
|
|||||||
pub elapsed_value_countdown: Duration,
|
pub elapsed_value_countdown: Duration,
|
||||||
// timer
|
// timer
|
||||||
pub current_value_timer: Duration,
|
pub current_value_timer: Duration,
|
||||||
// footer
|
|
||||||
pub footer_app_time: Toggle,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AppStorage {
|
impl Default for AppStorage {
|
||||||
@@ -62,7 +46,6 @@ 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,
|
||||||
@@ -75,8 +58,6 @@ impl Default for AppStorage {
|
|||||||
elapsed_value_countdown: Duration::ZERO,
|
elapsed_value_countdown: Duration::ZERO,
|
||||||
// timer
|
// timer
|
||||||
current_value_timer: Duration::ZERO,
|
current_value_timer: Duration::ZERO,
|
||||||
// footer
|
|
||||||
footer_app_time: Toggle::Off,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ pub mod countdown;
|
|||||||
pub mod edit_time;
|
pub mod edit_time;
|
||||||
pub mod footer;
|
pub mod footer;
|
||||||
pub mod header;
|
pub mod header;
|
||||||
pub mod local_time;
|
|
||||||
pub mod pomodoro;
|
pub mod pomodoro;
|
||||||
pub mod progressbar;
|
pub mod progressbar;
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ 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,
|
||||||
@@ -143,10 +142,6 @@ 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
|
||||||
}
|
}
|
||||||
@@ -156,18 +151,14 @@ 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;
|
||||||
// Update `Mode`
|
// special cases: Should `Mode` be updated?
|
||||||
// 1. `Done` -> `Pause`
|
// 1. `Done` -> `Initial` ?
|
||||||
if p == Mode::Done && self.current_value.gt(&Duration::ZERO.into()) {
|
if p == Mode::Done && self.current_value.gt(&Duration::ZERO.into()) {
|
||||||
Mode::Pause
|
Mode::Initial
|
||||||
}
|
}
|
||||||
// 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()) {
|
||||||
@@ -179,8 +170,6 @@ 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 {
|
||||||
@@ -413,7 +402,6 @@ 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
|
||||||
@@ -487,7 +475,6 @@ 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
|
||||||
|
|||||||
@@ -144,6 +144,8 @@ 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() {
|
||||||
@@ -162,96 +164,6 @@ 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
|
||||||
@@ -277,29 +189,85 @@ impl TuiEventHandler for CountdownState {
|
|||||||
self.edit_time_done(edit_time);
|
self.edit_time_done(edit_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Enter edit by local time mode
|
// STRG + e => toggle edit time
|
||||||
KeyCode::Char('e') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
KeyCode::Char('e') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||||
// set `edit_time`
|
// stop editing clock
|
||||||
self.edit_time = Some(EditTimeState::new(EditTimeStateArgs {
|
if self.clock.is_edit_mode() {
|
||||||
time: self.time_to_edit(),
|
// toggle edit mode
|
||||||
min: self.min_time_to_edit(),
|
self.clock.toggle_edit();
|
||||||
max: self.max_time_to_edit(),
|
}
|
||||||
}));
|
|
||||||
|
|
||||||
// pause `elapsed_clock`
|
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 {
|
||||||
|
time: self.time_to_edit(),
|
||||||
|
min: self.min_time_to_edit(),
|
||||||
|
max: self.max_time_to_edit(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop `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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Enter edit clock mode
|
// STRG + e => toggle edit clock
|
||||||
KeyCode::Char('e') => {
|
KeyCode::Char('e') => {
|
||||||
// toggle edit mode
|
// toggle edit mode
|
||||||
self.clock.toggle_edit();
|
self.clock.toggle_edit();
|
||||||
|
|
||||||
// pause `elapsed_clock`
|
// 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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),
|
||||||
},
|
},
|
||||||
@@ -319,7 +287,7 @@ fn human_days_diff(a: &OffsetDateTime, b: &OffsetDateTime) -> String {
|
|||||||
match days_diff {
|
match days_diff {
|
||||||
0 => "today".to_owned(),
|
0 => "today".to_owned(),
|
||||||
1 => "tomorrow".to_owned(),
|
1 => "tomorrow".to_owned(),
|
||||||
n => format!("+{n}days"),
|
n => format!("+{}days", n),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ use ratatui::{
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FooterState {
|
pub struct FooterState {
|
||||||
show_menu: bool,
|
show_menu: bool,
|
||||||
app_time_format: Option<AppTimeFormat>,
|
app_time_format: AppTimeFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FooterState {
|
impl FooterState {
|
||||||
pub const fn new(show_menu: bool, app_time_format: Option<AppTimeFormat>) -> Self {
|
pub const fn new(show_menu: bool, app_time_format: AppTimeFormat) -> Self {
|
||||||
Self {
|
Self {
|
||||||
show_menu,
|
show_menu,
|
||||||
app_time_format,
|
app_time_format,
|
||||||
@@ -32,12 +32,12 @@ impl FooterState {
|
|||||||
self.show_menu
|
self.show_menu
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn app_time_format(&self) -> &Option<AppTimeFormat> {
|
pub const fn app_time_format(&self) -> &AppTimeFormat {
|
||||||
&self.app_time_format
|
&self.app_time_format
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn set_app_time_format(&mut self, value: Option<AppTimeFormat>) {
|
pub fn toggle_app_time_format(&mut self) {
|
||||||
self.app_time_format = value;
|
self.app_time_format = self.app_time_format.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,6 @@ impl StatefulWidget for Footer {
|
|||||||
(Content::Countdown, "[c]ountdown"),
|
(Content::Countdown, "[c]ountdown"),
|
||||||
(Content::Timer, "[t]imer"),
|
(Content::Timer, "[t]imer"),
|
||||||
(Content::Pomodoro, "[p]omodoro"),
|
(Content::Pomodoro, "[p]omodoro"),
|
||||||
(Content::LocalTime, "[l]ocal time"),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let [_, area] =
|
let [_, area] =
|
||||||
@@ -72,12 +71,11 @@ impl StatefulWidget for Footer {
|
|||||||
)
|
)
|
||||||
.title(
|
.title(
|
||||||
Line::from(
|
Line::from(
|
||||||
match (state.app_time_format, self.selected_content) {
|
match state.app_time_format {
|
||||||
// Show time
|
// `Hidden` -> no (empty) title
|
||||||
(Some(v), content) if content != Content::LocalTime => format!(" {} " // add some space around
|
AppTimeFormat::Hidden => "".into(),
|
||||||
, self.app_time.format(&v)),
|
// others -> add some space around
|
||||||
// Hide time -> empty
|
_ => format!(" {} ", self.app_time.format(&state.app_time_format))
|
||||||
_ => "".into(),
|
|
||||||
}
|
}
|
||||||
).right_aligned())
|
).right_aligned())
|
||||||
.border_set(border::PLAIN)
|
.border_set(border::PLAIN)
|
||||||
@@ -91,7 +89,7 @@ impl StatefulWidget for Footer {
|
|||||||
let mut style = Style::default();
|
let mut style = Style::default();
|
||||||
// Add space for all except last
|
// Add space for all except last
|
||||||
let label = if index < content_labels.len() - 1 {
|
let label = if index < content_labels.len() - 1 {
|
||||||
format!("{label} ")
|
format!("{} ", label)
|
||||||
} else {
|
} else {
|
||||||
label.to_string()
|
label.to_string()
|
||||||
};
|
};
|
||||||
@@ -104,40 +102,37 @@ impl StatefulWidget for Footer {
|
|||||||
|
|
||||||
const SPACE: &str = " "; // 2 empty spaces
|
const SPACE: &str = " "; // 2 empty spaces
|
||||||
let widths = [Constraint::Length(12), Constraint::Percentage(100)];
|
let widths = [Constraint::Length(12), Constraint::Percentage(100)];
|
||||||
let mut table_rows = vec![
|
let table = Table::new(
|
||||||
// screens
|
[
|
||||||
Row::new(vec![
|
// content
|
||||||
Cell::from(Span::styled(
|
Row::new(vec![
|
||||||
"screens",
|
Cell::from(Span::styled(
|
||||||
Style::default().add_modifier(Modifier::BOLD),
|
"screens",
|
||||||
)),
|
Style::default().add_modifier(Modifier::BOLD),
|
||||||
Cell::from(Line::from(content_labels)),
|
|
||||||
]),
|
|
||||||
// appearance
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(Span::styled(
|
|
||||||
"appearance",
|
|
||||||
Style::default().add_modifier(Modifier::BOLD),
|
|
||||||
)),
|
|
||||||
Cell::from(Line::from(vec![
|
|
||||||
Span::from("[,]change style"),
|
|
||||||
Span::from(SPACE),
|
|
||||||
Span::from("[.]toggle deciseconds"),
|
|
||||||
Span::from(SPACE),
|
|
||||||
Span::from(format!(
|
|
||||||
"[:]toggle {} time",
|
|
||||||
match self.app_time {
|
|
||||||
AppTime::Local(_) => "local",
|
|
||||||
AppTime::Utc(_) => "utc",
|
|
||||||
}
|
|
||||||
)),
|
)),
|
||||||
])),
|
Cell::from(Line::from(content_labels)),
|
||||||
]),
|
]),
|
||||||
];
|
// format
|
||||||
|
Row::new(vec![
|
||||||
if self.selected_content != Content::LocalTime {
|
Cell::from(Span::styled(
|
||||||
table_rows.extend_from_slice(&[
|
"appearance",
|
||||||
// controls - 1. row
|
Style::default().add_modifier(Modifier::BOLD),
|
||||||
|
)),
|
||||||
|
Cell::from(Line::from(vec![
|
||||||
|
Span::from("[,]change style"),
|
||||||
|
Span::from(SPACE),
|
||||||
|
Span::from("[.]toggle deciseconds"),
|
||||||
|
Span::from(SPACE),
|
||||||
|
Span::from(format!(
|
||||||
|
"[:]toggle {} time",
|
||||||
|
match self.app_time {
|
||||||
|
AppTime::Local(_) => "local",
|
||||||
|
AppTime::Utc(_) => "utc",
|
||||||
|
}
|
||||||
|
)),
|
||||||
|
])),
|
||||||
|
]),
|
||||||
|
// edit
|
||||||
Row::new(vec![
|
Row::new(vec![
|
||||||
Cell::from(Span::styled(
|
Cell::from(Span::styled(
|
||||||
"controls",
|
"controls",
|
||||||
@@ -146,93 +141,55 @@ 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![Span::from(if self.running_clock {
|
let mut spans = vec![
|
||||||
"[s]top"
|
Span::from(if self.running_clock {
|
||||||
} else {
|
"[s]top"
|
||||||
"[s]tart"
|
} else {
|
||||||
})];
|
"[s]tart"
|
||||||
spans.extend_from_slice(&[
|
}),
|
||||||
|
Span::from(SPACE),
|
||||||
|
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 clock"),
|
|
||||||
]);
|
|
||||||
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("[^r]eset clocks+rounds"),
|
Span::from("[← →]switch work/pause"),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
spans
|
spans
|
||||||
}
|
}
|
||||||
_ => {
|
others => vec![
|
||||||
let mut spans = vec![Span::from("[s]ave changes")];
|
Span::from(match others {
|
||||||
if self.selected_content == Content::Countdown
|
AppEditMode::Clock => "[e]dit done",
|
||||||
|| self.selected_content == Content::Pomodoro
|
AppEditMode::Time => "[^e]dit done",
|
||||||
{
|
_ => "",
|
||||||
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!(
|
Span::from(format!("[{}]edit up", scrollbar::VERTICAL.begin)), // ↑
|
||||||
// ↑
|
|
||||||
"[{}]edit up",
|
|
||||||
scrollbar::VERTICAL.begin
|
|
||||||
)),
|
|
||||||
Span::from(SPACE),
|
Span::from(SPACE),
|
||||||
Span::from(format!(
|
Span::from(format!("[{}]edit up", scrollbar::VERTICAL.end)), // ↓,
|
||||||
// ↓
|
|
||||||
"[{}]edit up",
|
|
||||||
scrollbar::VERTICAL.end
|
|
||||||
)),
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
]),
|
]),
|
||||||
])
|
],
|
||||||
}
|
widths,
|
||||||
|
)
|
||||||
let table = Table::new(table_rows, widths).column_spacing(1);
|
.column_spacing(1);
|
||||||
|
|
||||||
Widget::render(table, menu_area, buf);
|
Widget::render(table, menu_area, buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,185 +0,0 @@
|
|||||||
use ratatui::{
|
|
||||||
buffer::Buffer,
|
|
||||||
layout::{Constraint, Layout, Rect},
|
|
||||||
style::{Modifier, Style},
|
|
||||||
text::{Line, Span},
|
|
||||||
widgets::{StatefulWidget, Widget},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
common::{AppTime, AppTimeFormat, Style as DigitStyle},
|
|
||||||
duration::DurationEx,
|
|
||||||
events::{TuiEvent, TuiEventHandler},
|
|
||||||
utils::center,
|
|
||||||
widgets::clock_elements::{
|
|
||||||
COLON_WIDTH, Colon, DIGIT_HEIGHT, DIGIT_SPACE_WIDTH, DIGIT_WIDTH, Digit,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use std::cmp::max;
|
|
||||||
|
|
||||||
/// State for `LocalTimeWidget`
|
|
||||||
pub struct LocalTimeState {
|
|
||||||
time: AppTime,
|
|
||||||
format: AppTimeFormat,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct LocalTimeStateArgs {
|
|
||||||
pub app_time: AppTime,
|
|
||||||
pub app_time_format: AppTimeFormat,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LocalTimeState {
|
|
||||||
pub fn new(args: LocalTimeStateArgs) -> Self {
|
|
||||||
let LocalTimeStateArgs {
|
|
||||||
app_time,
|
|
||||||
app_time_format,
|
|
||||||
} = args;
|
|
||||||
|
|
||||||
Self {
|
|
||||||
time: app_time,
|
|
||||||
format: app_time_format,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_app_time(&mut self, app_time: AppTime) {
|
|
||||||
self.time = app_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_app_time_format(&mut self, format: AppTimeFormat) {
|
|
||||||
self.format = format;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TuiEventHandler for LocalTimeState {
|
|
||||||
fn update(&mut self, event: TuiEvent) -> Option<TuiEvent> {
|
|
||||||
Some(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct LocalTimeWidget {
|
|
||||||
pub style: DigitStyle,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LocalTimeWidget {
|
|
||||||
fn get_horizontal_lengths(&self, format: &AppTimeFormat) -> Vec<u16> {
|
|
||||||
const PERIOD_WIDTH: u16 = 2; // PM or AM
|
|
||||||
|
|
||||||
match format {
|
|
||||||
AppTimeFormat::HhMmSs => vec![
|
|
||||||
DIGIT_WIDTH, // H
|
|
||||||
DIGIT_SPACE_WIDTH, // (space)
|
|
||||||
DIGIT_WIDTH, // h
|
|
||||||
COLON_WIDTH, // :
|
|
||||||
DIGIT_WIDTH, // M
|
|
||||||
DIGIT_SPACE_WIDTH, // (space)
|
|
||||||
DIGIT_WIDTH, // m
|
|
||||||
COLON_WIDTH, // :
|
|
||||||
DIGIT_WIDTH, // S
|
|
||||||
DIGIT_SPACE_WIDTH, // (space)
|
|
||||||
DIGIT_WIDTH, // s
|
|
||||||
],
|
|
||||||
AppTimeFormat::HhMm => vec![
|
|
||||||
DIGIT_WIDTH, // H
|
|
||||||
DIGIT_SPACE_WIDTH, // (space)
|
|
||||||
DIGIT_WIDTH, // h
|
|
||||||
COLON_WIDTH, // :
|
|
||||||
DIGIT_WIDTH, // M
|
|
||||||
DIGIT_SPACE_WIDTH, // (space)
|
|
||||||
DIGIT_WIDTH, // m
|
|
||||||
],
|
|
||||||
AppTimeFormat::Hh12Mm => vec![
|
|
||||||
DIGIT_SPACE_WIDTH + PERIOD_WIDTH, // (space) + (empty period) to center everything well horizontally
|
|
||||||
DIGIT_WIDTH, // H
|
|
||||||
DIGIT_SPACE_WIDTH, // (space)
|
|
||||||
DIGIT_WIDTH, // h
|
|
||||||
COLON_WIDTH, // :
|
|
||||||
DIGIT_WIDTH, // M
|
|
||||||
DIGIT_SPACE_WIDTH, // (space)
|
|
||||||
DIGIT_WIDTH, // m
|
|
||||||
DIGIT_SPACE_WIDTH, // (space)
|
|
||||||
PERIOD_WIDTH, // period
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StatefulWidget for LocalTimeWidget {
|
|
||||||
type State = LocalTimeState;
|
|
||||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
|
||||||
let current_value: DurationEx = state.time.as_duration_of_today().into();
|
|
||||||
let hours = current_value.hours_mod();
|
|
||||||
let hours12 = current_value.hours_mod_12();
|
|
||||||
let minutes = current_value.minutes_mod();
|
|
||||||
let seconds = current_value.seconds_mod();
|
|
||||||
let symbol = self.style.get_digit_symbol();
|
|
||||||
|
|
||||||
let label = Line::raw("Local Time".to_uppercase());
|
|
||||||
|
|
||||||
let format = state.format;
|
|
||||||
let widths = self.get_horizontal_lengths(&format);
|
|
||||||
let mut widths = widths;
|
|
||||||
// Special case for `Hh12Mm`
|
|
||||||
// It might be `h:Mm` OR `Hh:Mm` depending on `hours12`
|
|
||||||
if state.format == AppTimeFormat::Hh12Mm && hours12 < 10 {
|
|
||||||
// single digit means, no (zero) width's for `H` and `space`
|
|
||||||
widths[1] = 0; // `H`
|
|
||||||
widths[2] = 0; // `space`
|
|
||||||
}
|
|
||||||
|
|
||||||
let width = widths.iter().sum();
|
|
||||||
let area = center(
|
|
||||||
area,
|
|
||||||
Constraint::Length(max(width, label.width() as u16)),
|
|
||||||
Constraint::Length(DIGIT_HEIGHT + 1 /* height of label */),
|
|
||||||
);
|
|
||||||
|
|
||||||
let [v1, v2] = Layout::vertical(Constraint::from_lengths([DIGIT_HEIGHT, 1])).areas(area);
|
|
||||||
|
|
||||||
match state.format {
|
|
||||||
AppTimeFormat::HhMmSs => {
|
|
||||||
let [hh, _, h, c_hm, mm, _, m, c_ms, ss, _, s] =
|
|
||||||
Layout::horizontal(Constraint::from_lengths(widths)).areas(v1);
|
|
||||||
Digit::new(hours / 10, false, symbol).render(hh, buf);
|
|
||||||
Digit::new(hours % 10, false, symbol).render(h, buf);
|
|
||||||
Colon::new(symbol).render(c_hm, buf);
|
|
||||||
Digit::new(minutes / 10, false, symbol).render(mm, buf);
|
|
||||||
Digit::new(minutes % 10, false, symbol).render(m, buf);
|
|
||||||
Colon::new(symbol).render(c_ms, buf);
|
|
||||||
Digit::new(seconds / 10, false, symbol).render(ss, buf);
|
|
||||||
Digit::new(seconds % 10, false, symbol).render(s, buf);
|
|
||||||
}
|
|
||||||
AppTimeFormat::HhMm => {
|
|
||||||
let [hh, _, h, c_hm, mm, _, m] =
|
|
||||||
Layout::horizontal(Constraint::from_lengths(widths)).areas(v1);
|
|
||||||
Digit::new(hours / 10, false, symbol).render(hh, buf);
|
|
||||||
Digit::new(hours % 10, false, symbol).render(h, buf);
|
|
||||||
Colon::new(symbol).render(c_hm, buf);
|
|
||||||
Digit::new(minutes / 10, false, symbol).render(mm, buf);
|
|
||||||
Digit::new(minutes % 10, false, symbol).render(m, buf);
|
|
||||||
}
|
|
||||||
AppTimeFormat::Hh12Mm => {
|
|
||||||
let [_, hh, _, h, c_hm, mm, _, m, _, p] =
|
|
||||||
Layout::horizontal(Constraint::from_lengths(widths)).areas(v1);
|
|
||||||
// Hh
|
|
||||||
if hours12 >= 10 {
|
|
||||||
Digit::new(hours12 / 10, false, symbol).render(hh, buf);
|
|
||||||
Digit::new(hours12 % 10, false, symbol).render(h, buf);
|
|
||||||
}
|
|
||||||
// h
|
|
||||||
else {
|
|
||||||
Digit::new(hours12, false, symbol).render(h, buf);
|
|
||||||
}
|
|
||||||
Colon::new(symbol).render(c_hm, buf);
|
|
||||||
Digit::new(minutes / 10, false, symbol).render(mm, buf);
|
|
||||||
Digit::new(minutes % 10, false, symbol).render(m, buf);
|
|
||||||
Span::styled(
|
|
||||||
state.time.get_period().to_uppercase(),
|
|
||||||
Style::default().add_modifier(Modifier::BOLD),
|
|
||||||
)
|
|
||||||
.render(p, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
label.centered().render(v2, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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,7 +45,6 @@ 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 {
|
||||||
@@ -56,7 +55,6 @@ 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 {
|
||||||
@@ -69,7 +67,6 @@ impl PomodoroState {
|
|||||||
current_value_pause,
|
current_value_pause,
|
||||||
with_decis,
|
with_decis,
|
||||||
app_tx,
|
app_tx,
|
||||||
round,
|
|
||||||
} = args;
|
} = args;
|
||||||
Self {
|
Self {
|
||||||
mode,
|
mode,
|
||||||
@@ -91,7 +88,6 @@ impl PomodoroState {
|
|||||||
})
|
})
|
||||||
.with_name("Pause".to_owned()),
|
.with_name("Pause".to_owned()),
|
||||||
},
|
},
|
||||||
round,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,26 +103,14 @@ impl PomodoroState {
|
|||||||
&self.clock_map.work
|
&self.clock_map.work
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_clock_work_mut(&mut self) -> &mut ClockState<Countdown> {
|
|
||||||
self.clock_map.get_mut(&Mode::Work)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_clock_pause(&self) -> &ClockState<Countdown> {
|
pub fn get_clock_pause(&self) -> &ClockState<Countdown> {
|
||||||
&self.clock_map.pause
|
&self.clock_map.pause
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_clock_pause_mut(&mut self) -> &mut ClockState<Countdown> {
|
|
||||||
self.clock_map.get_mut(&Mode::Pause)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_mode(&self) -> &Mode {
|
pub fn get_mode(&self) -> &Mode {
|
||||||
&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;
|
||||||
@@ -148,76 +132,33 @@ 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();
|
||||||
}
|
}
|
||||||
// toggle WORK/PAUSE
|
KeyCode::Left if edit_mode => {
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
// toggle WORK/PAUSE
|
KeyCode::Right if edit_mode => {
|
||||||
|
self.get_clock_mut().edit_prev();
|
||||||
|
}
|
||||||
KeyCode::Right => {
|
KeyCode::Right => {
|
||||||
self.next();
|
self.next();
|
||||||
}
|
}
|
||||||
// reset rounds AND clocks
|
KeyCode::Up if edit_mode => {
|
||||||
KeyCode::Char('r') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
self.get_clock_mut().edit_up();
|
||||||
self.round = 1;
|
}
|
||||||
self.get_clock_work_mut().reset();
|
KeyCode::Down if edit_mode => {
|
||||||
self.get_clock_pause_mut().reset();
|
self.get_clock_mut().edit_down();
|
||||||
}
|
}
|
||||||
// reset current clock
|
|
||||||
KeyCode::Char('r') => {
|
KeyCode::Char('r') => {
|
||||||
// increase round 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),
|
||||||
@@ -245,7 +186,6 @@ 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,
|
||||||
@@ -256,25 +196,13 @@ impl StatefulWidget for PomodoroWidget {
|
|||||||
),
|
),
|
||||||
label.width() as u16,
|
label.width() as u16,
|
||||||
)),
|
)),
|
||||||
Constraint::Length(
|
Constraint::Length(clock_widget.get_height() + 1 /* height of mode_str */),
|
||||||
// empty label + height of `label` + `label_round`
|
|
||||||
clock_widget.get_height() + 3,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let [v1, v2, v3, v4] = Layout::vertical(Constraint::from_lengths([
|
let [v1, v2] =
|
||||||
1,
|
Layout::vertical(Constraint::from_lengths([clock_widget.get_height(), 1])).areas(area);
|
||||||
clock_widget.get_height(),
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
]))
|
|
||||||
.areas(area);
|
|
||||||
|
|
||||||
// empty line keep everything in center vertically comparing to other
|
clock_widget.render(v1, buf, state.get_clock_mut());
|
||||||
// views (which have one label below the clock only)
|
label.centered().render(v2, buf);
|
||||||
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,51 +39,28 @@ 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),
|
||||||
|
|||||||