Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a20587947 | ||
|
|
e25eb6ef89 | ||
|
|
60392b40ed | ||
|
|
901cf69472 | ||
|
|
c494f0e829 | ||
|
|
637c1da21b | ||
|
|
3439e4aa8d | ||
|
|
5bc37f005f | ||
|
|
bfa40fd8f1 | ||
|
|
93a3cde396 | ||
|
|
d27587a44a | ||
|
|
5f4c5bb8ed | ||
|
|
44af71c01c |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -4,8 +4,6 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- "release/**"
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
get-version:
|
||||
|
||||
27
CHANGELOG.md
27
CHANGELOG.md
@@ -1,8 +1,33 @@
|
||||
# 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
|
||||
|
||||
### Features
|
||||
###
|
||||
|
||||
- (pomodoro) Count WORK rounds [#75](https://github.com/sectore/timr-tui/pull/75), [6b068bb](https://github.com/sectore/timr-tui/commit/6b068bbd094d9ec1a36b47598fadfc71296d9590)
|
||||
- (pomodoro/countdown) Change initial value [#79](https://github.com/sectore/timr-tui/pull/79), [aae5c38](https://github.com/sectore/timr-tui/commit/aae5c38cd6a666d5ba418b12fb67879a2146b9a2)
|
||||
|
||||
477
Cargo.lock
generated
477
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
20
Cargo.toml
20
Cargo.toml
@@ -1,10 +1,10 @@
|
||||
[package]
|
||||
name = "timr-tui"
|
||||
version = "1.3.0"
|
||||
version = "1.4.0"
|
||||
description = "TUI to organize your time: Pomodoro, Countdown, Timer."
|
||||
edition = "2024"
|
||||
# Reminder: Always keep `channel` in `rust-toolchain.toml` in sync with `rust-version`.
|
||||
rust-version = "1.86.0"
|
||||
rust-version = "1.89.0"
|
||||
homepage = "https://github.com/sectore/timr-tui"
|
||||
repository = "https://github.com/sectore/timr-tui"
|
||||
readme = "README.md"
|
||||
@@ -16,25 +16,25 @@ exclude = [".github/*", "demo/*.tape", "result/*", "*.mp3"]
|
||||
[dependencies]
|
||||
ratatui = "0.29.0"
|
||||
crossterm = { version = "0.28.1", features = ["event-stream", "serde"] }
|
||||
color-eyre = "0.6.2"
|
||||
color-eyre = "0.6.5"
|
||||
futures = "0.3"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
strum = { version = "0.26.3", features = ["derive"] }
|
||||
tokio = { version = "1.41.1", features = ["full"] }
|
||||
tokio-stream = "0.1.16"
|
||||
tokio-util = "0.7.12"
|
||||
tokio = { version = "1.45.1", features = ["full"] }
|
||||
tokio-stream = "0.1.17"
|
||||
tokio-util = "0.7.15"
|
||||
tracing = "0.1.41"
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
|
||||
directories = "5.0.1"
|
||||
clap = { version = "4.5.23", features = ["derive"] }
|
||||
time = { version = "0.3.37", features = ["formatting", "local-offset"] }
|
||||
notify-rust = "4.11.4"
|
||||
clap = { version = "4.5.40", features = ["derive"] }
|
||||
time = { version = "0.3.41", features = ["formatting", "local-offset"] }
|
||||
notify-rust = "4.11.7"
|
||||
rodio = { version = "0.20.1", features = [
|
||||
"symphonia-mp3",
|
||||
"symphonia-wav",
|
||||
], default-features = false, optional = true }
|
||||
thiserror = { version = "2.0.11", optional = true }
|
||||
thiserror = { version = "2.0.12", optional = true }
|
||||
|
||||
|
||||
[features]
|
||||
|
||||
45
README.md
45
README.md
@@ -41,10 +41,23 @@ _(theme depends on your terminal preferences)_
|
||||
<img alt="countdown" src="demo/countdown.gif" />
|
||||
</a>
|
||||
|
||||
## Change style
|
||||
## Countdown: Mission Elapsed Time ([MET](https://en.wikipedia.org/wiki/Mission_Elapsed_Time))
|
||||
|
||||
<a href="demo/style.gif">
|
||||
<img alt="style" src="demo/style.gif" />
|
||||
<a href="demo/countdown-met.gif">
|
||||
<img alt="menu" src="demo/countdown-met.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>
|
||||
|
||||
## Toggle deciseconds
|
||||
@@ -53,24 +66,18 @@ _(theme depends on your terminal preferences)_
|
||||
<img alt="deciseconds" src="demo/decis.gif" />
|
||||
</a>
|
||||
|
||||
## Change style
|
||||
|
||||
<a href="demo/style.gif">
|
||||
<img alt="style" src="demo/style.gif" />
|
||||
</a>
|
||||
|
||||
## Menu
|
||||
|
||||
<a href="demo/menu.gif">
|
||||
<img alt="menu" src="demo/menu.gif" />
|
||||
</a>
|
||||
|
||||
## Local time (footer)
|
||||
|
||||
<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
|
||||
|
||||
```sh
|
||||
@@ -83,7 +90,7 @@ Options:
|
||||
-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'
|
||||
-d, --decis Show deciseconds.
|
||||
-m, --mode <MODE> Mode to start with. [possible values: countdown, timer, pomodoro]
|
||||
-m, --mode <MODE> Mode to start with. [possible values: countdown, timer, pomodoro, localtime]
|
||||
-s, --style <STYLE> Style to display time with. [possible values: full, light, medium, dark, thick, cross, braille]
|
||||
--menu Open the menu.
|
||||
-r, --reset Reset stored values to default values.
|
||||
@@ -115,6 +122,7 @@ Extra option (if `--features sound` is enabled by local build only):
|
||||
| <kbd>p</kbd> | Pomodoro |
|
||||
| <kbd>c</kbd> | Countdown |
|
||||
| <kbd>t</kbd> | Timer |
|
||||
| <kbd>l</kbd> | Local Time |
|
||||
|
||||
## Controls
|
||||
|
||||
@@ -135,7 +143,7 @@ Extra option (if `--features sound` is enabled by local build only):
|
||||
| <kbd>↑</kbd> | edit to go up |
|
||||
| <kbd>↓</kbd> | edit to go down |
|
||||
|
||||
**In `Pomodoro` screen only**
|
||||
**In `Pomodoro` screen only:**
|
||||
|
||||
| Key | Description |
|
||||
| --- | --- |
|
||||
@@ -156,7 +164,7 @@ Extra option (if `--features sound` is enabled by local build only):
|
||||
| --- | --- |
|
||||
| <kbd>,</kbd> | toggle styles |
|
||||
| <kbd>.</kbd> | toggle deciseconds |
|
||||
| <kbd>:</kbd> | toggle local time in footer |
|
||||
| <kbd>:</kbd> | toggle local time |
|
||||
|
||||
# Installation
|
||||
|
||||
@@ -220,6 +228,7 @@ Available recipes:
|
||||
demo-countdown-met # build demo: countdown + met [alias: dcm]
|
||||
demo-decis # build demo: deciseconds [alias: dd]
|
||||
demo-local-time # build demo: local time [alias: dlt]
|
||||
demo-local-time-footer # build demo: local time (footer) [alias: dltf]
|
||||
demo-menu # build demo: menu [alias: dm]
|
||||
demo-pomodoro # build demo: pomodoro [alias: dp]
|
||||
demo-rocket-countdown # build demo: rocket countdown [alias: drc]
|
||||
|
||||
BIN
demo/local-time-footer.gif
Normal file
BIN
demo/local-time-footer.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
20
demo/local-time-footer.tape
Normal file
20
demo/local-time-footer.tape
Normal file
@@ -0,0 +1,20 @@
|
||||
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 ":::"
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 28 KiB |
@@ -1,7 +1,7 @@
|
||||
Output demo/local-time.gif
|
||||
|
||||
# https://github.com/charmbracelet/vhs/blob/main/THEMES.md
|
||||
Set Theme "AtomOneLight"
|
||||
Set Theme "Atom"
|
||||
|
||||
Set FontSize 14
|
||||
Set Width 800
|
||||
@@ -12,11 +12,9 @@ Set Margin 1
|
||||
# --- START ---
|
||||
Set LoopOffset 4
|
||||
Hide
|
||||
Type "cargo run -- -m c"
|
||||
Type "cargo run -- -m l"
|
||||
Enter
|
||||
Sleep 0.2
|
||||
Show
|
||||
Sleep 1
|
||||
# --- toggle local time ---
|
||||
Type@1.5s ":::"
|
||||
Sleep 1.5
|
||||
|
||||
24
flake.lock
generated
24
flake.lock
generated
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"locked": {
|
||||
"lastModified": 1745454774,
|
||||
"narHash": "sha256-oLvmxOnsEKGtwczxp/CwhrfmQUG2ym24OMWowcoRhH8=",
|
||||
"lastModified": 1754269165,
|
||||
"narHash": "sha256-0tcS8FHd4QjbCVoxN9jI+PjHgA4vc/IjkUSp+N3zy0U=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "efd36682371678e2b6da3f108fdb5c613b3ec598",
|
||||
"rev": "444e81206df3f7d92780680e45858e31d2f07a08",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -23,11 +23,11 @@
|
||||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1745995211,
|
||||
"narHash": "sha256-hf6Xu3KS06WyE/3dqV96iLGx3jIYQq9e68iCEFHrt04=",
|
||||
"lastModified": 1755240331,
|
||||
"narHash": "sha256-wEtw76+R/TOHEIjYOnxADC91G6s422HGruAngbjzsDw=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "0db04339c4e4c0fd42dbbaebe3590a67cbd12aa3",
|
||||
"rev": "3f076d4502001c64877099093318b2dbd8b062a1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -56,11 +56,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1745930157,
|
||||
"narHash": "sha256-y3h3NLnzRSiUkYpnfvnS669zWZLoqqI6NprtLQ+5dck=",
|
||||
"lastModified": 1755027561,
|
||||
"narHash": "sha256-IVft239Bc8p8Dtvf7UAACMG5P3ZV+3/aO28gXpGtMXI=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "46e634be05ce9dc6d4db8e664515ba10b78151ae",
|
||||
"rev": "005433b926e16227259a1843015b5b2b7f7d1fc3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -81,11 +81,11 @@
|
||||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1745949276,
|
||||
"narHash": "sha256-9ZK31t2HUiGdLLnDafrRnSrrO12JwqcAFbrJ9nRwh0Y=",
|
||||
"lastModified": 1755004716,
|
||||
"narHash": "sha256-TbhPR5Fqw5LjAeI3/FOPhNNFQCF3cieKCJWWupeZmiA=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "78a488dd5e7e4f17162001519665795e6e68b6f8",
|
||||
"rev": "b2a58b8c6eff3c3a2c8b5c70dbf69ead78284194",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
{
|
||||
file = ./rust-toolchain.toml;
|
||||
#sha256 = nixpkgs.lib.fakeSha256;
|
||||
sha256 = "sha256-X/4ZBHO3iW0fOenQ3foEvscgAPJYl2abspaBThDOukI=";
|
||||
sha256 = "sha256-+9FmLhAOezBZCOziO0Qct1NOrfpjNsXxc/8I0c7BdKE=";
|
||||
};
|
||||
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
|
||||
|
||||
7
justfile
7
justfile
@@ -121,6 +121,13 @@ alias dlt := demo-local-time
|
||||
demo-local-time:
|
||||
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
|
||||
|
||||
# build demo: rocket countdown
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[toolchain]
|
||||
# Reminder: Always keep `rust-version` in `Cargo.toml` in sync with `channel`.
|
||||
channel = "1.86.0"
|
||||
channel = "1.89.0"
|
||||
components = ["clippy", "rustfmt", "rust-src", "rust-analyzer"]
|
||||
targets = ["x86_64-pc-windows-gnu", "x86_64-unknown-linux-musl"]
|
||||
profile = "minimal"
|
||||
|
||||
84
src/app.rs
84
src/app.rs
@@ -10,6 +10,7 @@ use crate::{
|
||||
countdown::{Countdown, CountdownState, CountdownStateArgs},
|
||||
footer::{Footer, FooterState},
|
||||
header::Header,
|
||||
local_time::{LocalTimeState, LocalTimeStateArgs, LocalTimeWidget},
|
||||
pomodoro::{Mode as PomodoroMode, PomodoroState, PomodoroStateArgs, PomodoroWidget},
|
||||
timer::{Timer, TimerState},
|
||||
},
|
||||
@@ -44,9 +45,11 @@ pub struct App {
|
||||
#[allow(dead_code)] // w/ `--features sound` available only
|
||||
sound_path: Option<PathBuf>,
|
||||
app_time: AppTime,
|
||||
app_time_format: AppTimeFormat,
|
||||
countdown: CountdownState,
|
||||
timer: TimerState,
|
||||
pomodoro: PomodoroState,
|
||||
local_time: LocalTimeState,
|
||||
style: Style,
|
||||
with_decis: bool,
|
||||
footer: FooterState,
|
||||
@@ -72,6 +75,7 @@ pub struct AppArgs {
|
||||
pub current_value_timer: Duration,
|
||||
pub app_tx: events::AppEventTx,
|
||||
pub sound_path: Option<PathBuf>,
|
||||
pub footer_toggle_app_time: Toggle,
|
||||
}
|
||||
|
||||
pub struct FromAppArgs {
|
||||
@@ -92,7 +96,22 @@ impl From<FromAppArgs> for App {
|
||||
notification: args.notification.unwrap_or(stg.notification),
|
||||
blink: args.blink.unwrap_or(stg.blink),
|
||||
app_time_format: stg.app_time_format,
|
||||
content: args.mode.unwrap_or(stg.content),
|
||||
// Check args to set a possible mode to start with.
|
||||
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),
|
||||
pomodoro_mode: stg.pomodoro_mode,
|
||||
pomodoro_round: stg.pomodoro_count,
|
||||
@@ -116,6 +135,7 @@ impl From<FromAppArgs> for App {
|
||||
sound_path: args.sound,
|
||||
#[cfg(not(feature = "sound"))]
|
||||
sound_path: None,
|
||||
footer_toggle_app_time: stg.footer_app_time,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -149,6 +169,7 @@ impl App {
|
||||
blink,
|
||||
sound_path,
|
||||
app_tx,
|
||||
footer_toggle_app_time,
|
||||
} = args;
|
||||
let app_time = get_app_time();
|
||||
|
||||
@@ -159,6 +180,7 @@ impl App {
|
||||
sound_path,
|
||||
content,
|
||||
app_time,
|
||||
app_time_format,
|
||||
style,
|
||||
with_decis,
|
||||
countdown: CountdownState::new(CountdownStateArgs {
|
||||
@@ -189,7 +211,18 @@ impl App {
|
||||
round: pomodoro_round,
|
||||
app_tx: app_tx.clone(),
|
||||
}),
|
||||
footer: FooterState::new(show_menu, app_time_format),
|
||||
local_time: LocalTimeState::new(LocalTimeStateArgs {
|
||||
app_time,
|
||||
app_time_format,
|
||||
}),
|
||||
footer: FooterState::new(
|
||||
show_menu,
|
||||
if footer_toggle_app_time == Toggle::On {
|
||||
Some(app_time_format)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,8 +239,39 @@ impl App {
|
||||
KeyCode::Char('c') => app.content = Content::Countdown,
|
||||
KeyCode::Char('t') => app.content = Content::Timer,
|
||||
KeyCode::Char('p') => app.content = Content::Pomodoro,
|
||||
KeyCode::Char('l') => app.content = Content::LocalTime,
|
||||
// toogle app time format
|
||||
KeyCode::Char(':') => app.footer.toggle_app_time_format(),
|
||||
KeyCode::Char(':') => {
|
||||
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
|
||||
KeyCode::Char('m') => app.footer.set_show_menu(!app.footer.get_show_menu()),
|
||||
KeyCode::Char(',') => {
|
||||
@@ -230,6 +294,7 @@ impl App {
|
||||
if matches!(event, events::TuiEvent::Tick) {
|
||||
app.app_time = get_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
|
||||
@@ -237,6 +302,7 @@ impl App {
|
||||
Content::Countdown => app.countdown.update(event.clone()),
|
||||
Content::Timer => app.timer.update(event.clone()),
|
||||
Content::Pomodoro => app.pomodoro.update(event.clone()),
|
||||
Content::LocalTime => app.local_time.update(event.clone()),
|
||||
} {
|
||||
match unhandled {
|
||||
events::TuiEvent::Render | events::TuiEvent::Resize => {
|
||||
@@ -261,7 +327,7 @@ impl App {
|
||||
ClockTypeId::Timer => {
|
||||
format!("{name} stopped by reaching its maximum value.")
|
||||
}
|
||||
_ => format!("{:?} {name} done!", type_id),
|
||||
_ => format!("{type_id:?} {name} done!"),
|
||||
};
|
||||
// notification
|
||||
let result = notify_rust::Notification::new()
|
||||
@@ -327,6 +393,7 @@ impl App {
|
||||
AppEditMode::None
|
||||
}
|
||||
}
|
||||
Content::LocalTime => AppEditMode::None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,6 +402,8 @@ impl App {
|
||||
Content::Countdown => self.countdown.is_running(),
|
||||
Content::Timer => self.timer.get_clock().is_running(),
|
||||
Content::Pomodoro => self.pomodoro.get_clock().is_running(),
|
||||
// `LocalTime` does not use a `Clock`
|
||||
Content::LocalTime => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,6 +412,7 @@ impl App {
|
||||
Content::Countdown => Some(self.countdown.get_clock().get_percentage_done()),
|
||||
Content::Timer => None,
|
||||
Content::Pomodoro => Some(self.pomodoro.get_clock().get_percentage_done()),
|
||||
Content::LocalTime => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,7 +429,7 @@ impl App {
|
||||
show_menu: self.footer.get_show_menu(),
|
||||
notification: self.notification,
|
||||
blink: self.blink,
|
||||
app_time_format: *self.footer.app_time_format(),
|
||||
app_time_format: self.app_time_format,
|
||||
style: self.style,
|
||||
with_decis: self.with_decis,
|
||||
pomodoro_mode: self.pomodoro.get_mode().clone(),
|
||||
@@ -378,6 +448,7 @@ impl App {
|
||||
),
|
||||
elapsed_value_countdown: Duration::from(*self.countdown.get_elapsed_value()),
|
||||
current_value_timer: Duration::from(*self.timer.get_clock().get_current_value()),
|
||||
footer_app_time: self.footer.app_time_format().is_some().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -404,6 +475,9 @@ impl AppWidget {
|
||||
blink: state.blink == Toggle::On,
|
||||
}
|
||||
.render(area, buf, &mut state.pomodoro),
|
||||
Content::LocalTime => {
|
||||
LocalTimeWidget { style: state.style }.render(area, buf, &mut state.local_time);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use clap::ValueEnum;
|
||||
use ratatui::symbols::shade;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use time::OffsetDateTime;
|
||||
use time::format_description;
|
||||
use strum::EnumString;
|
||||
use time::{OffsetDateTime, format_description};
|
||||
|
||||
#[derive(
|
||||
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Default, Serialize, Deserialize,
|
||||
@@ -15,6 +15,8 @@ pub enum Content {
|
||||
Timer,
|
||||
#[value(name = "pomodoro", alias = "p")]
|
||||
Pomodoro,
|
||||
#[value(name = "localtime", alias = "l")]
|
||||
LocalTime,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -71,7 +73,7 @@ impl Style {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, EnumString, Serialize, Deserialize)]
|
||||
pub enum AppTimeFormat {
|
||||
/// `hh:mm:ss`
|
||||
#[default]
|
||||
@@ -80,17 +82,22 @@ pub enum AppTimeFormat {
|
||||
HhMm,
|
||||
/// `hh:mm AM` (or PM)
|
||||
Hh12Mm,
|
||||
/// `` (empty)
|
||||
Hidden,
|
||||
}
|
||||
|
||||
impl AppTimeFormat {
|
||||
pub const fn first() -> Self {
|
||||
Self::HhMmSs
|
||||
}
|
||||
|
||||
pub const fn last() -> Self {
|
||||
Self::Hh12Mm
|
||||
}
|
||||
|
||||
pub fn next(&self) -> Self {
|
||||
match self {
|
||||
AppTimeFormat::HhMmSs => AppTimeFormat::HhMm,
|
||||
AppTimeFormat::HhMm => AppTimeFormat::Hh12Mm,
|
||||
AppTimeFormat::Hh12Mm => AppTimeFormat::Hidden,
|
||||
AppTimeFormat::Hidden => AppTimeFormat::HhMmSs,
|
||||
AppTimeFormat::Hh12Mm => AppTimeFormat::HhMmSs,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,14 +120,12 @@ impl From<AppTime> for OffsetDateTime {
|
||||
impl AppTime {
|
||||
pub fn format(&self, app_format: &AppTimeFormat) -> String {
|
||||
let parse_str = match app_format {
|
||||
AppTimeFormat::HhMmSs => Some("[hour]:[minute]:[second]"),
|
||||
AppTimeFormat::HhMm => Some("[hour]:[minute]"),
|
||||
AppTimeFormat::Hh12Mm => Some("[hour repr:12 padding:none]:[minute] [period]"),
|
||||
AppTimeFormat::Hidden => None,
|
||||
AppTimeFormat::HhMmSs => "[hour]:[minute]:[second]",
|
||||
AppTimeFormat::HhMm => "[hour]:[minute]",
|
||||
AppTimeFormat::Hh12Mm => "[hour repr:12 padding:none]:[minute] [period]",
|
||||
};
|
||||
|
||||
if let Some(str) = parse_str {
|
||||
format_description::parse(str)
|
||||
format_description::parse(parse_str)
|
||||
.map_err(|_| "parse error")
|
||||
.and_then(|fd| {
|
||||
OffsetDateTime::from(*self)
|
||||
@@ -128,9 +133,30 @@ impl AppTime {
|
||||
.map_err(|_| "format error")
|
||||
})
|
||||
.unwrap_or_else(|e| e.to_string())
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
|
||||
pub fn get_period(&self) -> String {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +176,15 @@ pub enum Toggle {
|
||||
Off,
|
||||
}
|
||||
|
||||
impl From<bool> for Toggle {
|
||||
fn from(value: bool) -> Self {
|
||||
match value {
|
||||
true => Toggle::On,
|
||||
false => Toggle::Off,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
@@ -196,12 +231,5 @@ mod tests {
|
||||
"6:06 PM",
|
||||
"local"
|
||||
);
|
||||
// hidden
|
||||
assert_eq!(AppTime::Utc(dt).format(&AppTimeFormat::Hidden), "", "utc");
|
||||
assert_eq!(
|
||||
AppTime::Local(dt).format(&AppTimeFormat::Hidden),
|
||||
"",
|
||||
"local"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +60,19 @@ impl DurationEx {
|
||||
self.seconds() / (SECS_PER_MINUTE * MINS_PER_HOUR)
|
||||
}
|
||||
|
||||
/// Hours as 24-hour clock
|
||||
pub fn hours_mod(&self) -> u64 {
|
||||
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 {
|
||||
self.seconds() / MINS_PER_HOUR
|
||||
}
|
||||
@@ -177,22 +186,22 @@ mod tests {
|
||||
fn test_fmt() {
|
||||
// hh:mm:ss
|
||||
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
|
||||
let ex: DurationEx = Duration::from_secs(3601).into();
|
||||
assert_eq!(format!("{}", ex), "1:00:01");
|
||||
assert_eq!(format!("{ex}"), "1:00:01");
|
||||
// mm:ss
|
||||
let ex: DurationEx = Duration::from_secs(71).into();
|
||||
assert_eq!(format!("{}", ex), "1:11");
|
||||
assert_eq!(format!("{ex}"), "1:11");
|
||||
// m:ss
|
||||
let ex: DurationEx = Duration::from_secs(61).into();
|
||||
assert_eq!(format!("{}", ex), "1:01");
|
||||
assert_eq!(format!("{ex}"), "1:01");
|
||||
// ss
|
||||
let ex: DurationEx = Duration::from_secs(11).into();
|
||||
assert_eq!(format!("{}", ex), "11");
|
||||
assert_eq!(format!("{ex}"), "11");
|
||||
// s
|
||||
let ex: DurationEx = Duration::from_secs(1).into();
|
||||
assert_eq!(format!("{}", ex), "1");
|
||||
assert_eq!(format!("{ex}"), "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -200,7 +209,7 @@ mod tests {
|
||||
let ex: DurationEx = Duration::from_secs(10).into();
|
||||
let ex2: DurationEx = Duration::from_secs(1).into();
|
||||
let ex3 = ex.saturating_sub(ex2);
|
||||
assert_eq!(format!("{}", ex3), "9");
|
||||
assert_eq!(format!("{ex3}"), "9");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -208,7 +217,35 @@ mod tests {
|
||||
let ex: DurationEx = Duration::from_secs(10).into();
|
||||
let ex2: DurationEx = Duration::from_secs(1).into();
|
||||
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]
|
||||
|
||||
@@ -3,17 +3,30 @@ use crate::{
|
||||
widgets::pomodoro::Mode as PomodoroMode,
|
||||
};
|
||||
use color_eyre::eyre::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
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)]
|
||||
pub struct AppStorage {
|
||||
pub content: Content,
|
||||
pub show_menu: bool,
|
||||
pub notification: Toggle,
|
||||
pub blink: Toggle,
|
||||
#[serde(deserialize_with = "deserialize_app_time_format")]
|
||||
pub app_time_format: AppTimeFormat,
|
||||
pub style: Style,
|
||||
pub with_decis: bool,
|
||||
@@ -31,6 +44,8 @@ pub struct AppStorage {
|
||||
pub elapsed_value_countdown: Duration,
|
||||
// timer
|
||||
pub current_value_timer: Duration,
|
||||
// footer
|
||||
pub footer_app_time: Toggle,
|
||||
}
|
||||
|
||||
impl Default for AppStorage {
|
||||
@@ -60,6 +75,8 @@ impl Default for AppStorage {
|
||||
elapsed_value_countdown: Duration::ZERO,
|
||||
// timer
|
||||
current_value_timer: Duration::ZERO,
|
||||
// footer
|
||||
footer_app_time: Toggle::Off,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ pub mod countdown;
|
||||
pub mod edit_time;
|
||||
pub mod footer;
|
||||
pub mod header;
|
||||
pub mod local_time;
|
||||
pub mod pomodoro;
|
||||
pub mod progressbar;
|
||||
pub mod timer;
|
||||
|
||||
@@ -319,7 +319,7 @@ fn human_days_diff(a: &OffsetDateTime, b: &OffsetDateTime) -> String {
|
||||
match days_diff {
|
||||
0 => "today".to_owned(),
|
||||
1 => "tomorrow".to_owned(),
|
||||
n => format!("+{}days", n),
|
||||
n => format!("+{n}days"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@ use ratatui::{
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FooterState {
|
||||
show_menu: bool,
|
||||
app_time_format: AppTimeFormat,
|
||||
app_time_format: Option<AppTimeFormat>,
|
||||
}
|
||||
|
||||
impl FooterState {
|
||||
pub const fn new(show_menu: bool, app_time_format: AppTimeFormat) -> Self {
|
||||
pub const fn new(show_menu: bool, app_time_format: Option<AppTimeFormat>) -> Self {
|
||||
Self {
|
||||
show_menu,
|
||||
app_time_format,
|
||||
@@ -32,12 +32,12 @@ impl FooterState {
|
||||
self.show_menu
|
||||
}
|
||||
|
||||
pub const fn app_time_format(&self) -> &AppTimeFormat {
|
||||
pub const fn app_time_format(&self) -> &Option<AppTimeFormat> {
|
||||
&self.app_time_format
|
||||
}
|
||||
|
||||
pub fn toggle_app_time_format(&mut self) {
|
||||
self.app_time_format = self.app_time_format.next();
|
||||
pub const fn set_app_time_format(&mut self, value: Option<AppTimeFormat>) {
|
||||
self.app_time_format = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ impl StatefulWidget for Footer {
|
||||
(Content::Countdown, "[c]ountdown"),
|
||||
(Content::Timer, "[t]imer"),
|
||||
(Content::Pomodoro, "[p]omodoro"),
|
||||
(Content::LocalTime, "[l]ocal time"),
|
||||
]);
|
||||
|
||||
let [_, area] =
|
||||
@@ -71,11 +72,12 @@ impl StatefulWidget for Footer {
|
||||
)
|
||||
.title(
|
||||
Line::from(
|
||||
match state.app_time_format {
|
||||
// `Hidden` -> no (empty) title
|
||||
AppTimeFormat::Hidden => "".into(),
|
||||
// others -> add some space around
|
||||
_ => format!(" {} ", self.app_time.format(&state.app_time_format))
|
||||
match (state.app_time_format, self.selected_content) {
|
||||
// Show time
|
||||
(Some(v), content) if content != Content::LocalTime => format!(" {} " // add some space around
|
||||
, self.app_time.format(&v)),
|
||||
// Hide time -> empty
|
||||
_ => "".into(),
|
||||
}
|
||||
).right_aligned())
|
||||
.border_set(border::PLAIN)
|
||||
@@ -89,7 +91,7 @@ impl StatefulWidget for Footer {
|
||||
let mut style = Style::default();
|
||||
// Add space for all except last
|
||||
let label = if index < content_labels.len() - 1 {
|
||||
format!("{} ", label)
|
||||
format!("{label} ")
|
||||
} else {
|
||||
label.to_string()
|
||||
};
|
||||
@@ -102,8 +104,7 @@ impl StatefulWidget for Footer {
|
||||
|
||||
const SPACE: &str = " "; // 2 empty spaces
|
||||
let widths = [Constraint::Length(12), Constraint::Percentage(100)];
|
||||
let table = Table::new(
|
||||
[
|
||||
let mut table_rows = vec![
|
||||
// screens
|
||||
Row::new(vec![
|
||||
Cell::from(Span::styled(
|
||||
@@ -132,6 +133,10 @@ impl StatefulWidget for Footer {
|
||||
)),
|
||||
])),
|
||||
]),
|
||||
];
|
||||
|
||||
if self.selected_content != Content::LocalTime {
|
||||
table_rows.extend_from_slice(&[
|
||||
// controls - 1. row
|
||||
Row::new(vec![
|
||||
Cell::from(Span::styled(
|
||||
@@ -158,12 +163,12 @@ impl StatefulWidget for Footer {
|
||||
}
|
||||
spans.extend_from_slice(&[
|
||||
Span::from(SPACE),
|
||||
Span::from("[r]eset"),
|
||||
Span::from("[r]eset clock"),
|
||||
]);
|
||||
if self.selected_content == Content::Pomodoro {
|
||||
spans.extend_from_slice(&[
|
||||
Span::from(SPACE),
|
||||
Span::from("[^r]eset round"),
|
||||
Span::from("[^r]eset clocks+rounds"),
|
||||
]);
|
||||
}
|
||||
spans
|
||||
@@ -224,10 +229,10 @@ impl StatefulWidget for Footer {
|
||||
}
|
||||
})),
|
||||
]),
|
||||
],
|
||||
widths,
|
||||
)
|
||||
.column_spacing(1);
|
||||
])
|
||||
}
|
||||
|
||||
let table = Table::new(table_rows, widths).column_spacing(1);
|
||||
|
||||
Widget::render(table, menu_area, buf);
|
||||
}
|
||||
|
||||
185
src/widgets/local_time.rs
Normal file
185
src/widgets/local_time.rs
Normal file
@@ -0,0 +1,185 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -107,10 +107,18 @@ impl PomodoroState {
|
||||
&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> {
|
||||
&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 {
|
||||
&self.mode
|
||||
}
|
||||
@@ -198,19 +206,19 @@ impl TuiEventHandler for PomodoroState {
|
||||
KeyCode::Right => {
|
||||
self.next();
|
||||
}
|
||||
// reset round
|
||||
// reset rounds AND clocks
|
||||
KeyCode::Char('r') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
self.round = 1;
|
||||
self.get_clock_work_mut().reset();
|
||||
self.get_clock_pause_mut().reset();
|
||||
}
|
||||
// reset values
|
||||
// reset current clock
|
||||
KeyCode::Char('r') => {
|
||||
// count number of finished rounds of WORK before resetting the clock
|
||||
// increase round before (!!) resetting the clock
|
||||
if self.get_mode() == &Mode::Work && self.get_clock().is_done() {
|
||||
self.round += 1;
|
||||
}
|
||||
// reset both clocks
|
||||
self.clock_map.pause.reset();
|
||||
self.clock_map.work.reset();
|
||||
self.get_clock_mut().reset();
|
||||
}
|
||||
_ => return Some(event),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user