more args: mode, style, decis (#20)
This commit is contained in:
parent
d705f20e2d
commit
2cf411e2ae
@ -30,6 +30,9 @@ Options:
|
|||||||
-c, --countdown <COUNTDOWN> Countdown time to start from. Format: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 10:00]
|
-c, --countdown <COUNTDOWN> Countdown time to start from. Format: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 10:00]
|
||||||
-w, --work <WORK> Work time to count down from. Format: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 25:00]
|
-w, --work <WORK> Work time to count down from. Format: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 25:00]
|
||||||
-p, --pause <PAUSE> Pause time to count down from. Format: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 5:00]
|
-p, --pause <PAUSE> Pause time to count down from. Format: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 5:00]
|
||||||
|
-d, --decis Wether to show deciseconds or not
|
||||||
|
-m, --mode <CONTENT> Mode to start with: [t]imer, [c]ountdown, [p]omodoro [default: timer] [possible values: countdown, timer, pomodoro]
|
||||||
|
-s, --style <STYLE> Style to display time with: [b]old, [t]hick, [c]ross, [e]mpty [default: bold] [possible values: bold, empty, thick, cross]
|
||||||
-h, --help Print help
|
-h, --help Print help
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
44
src/app.rs
44
src/app.rs
@ -1,10 +1,10 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
args::Args,
|
args::{Args, ClockStyle, Content},
|
||||||
constants::TICK_VALUE_MS,
|
constants::TICK_VALUE_MS,
|
||||||
events::{Event, EventHandler, Events},
|
events::{Event, EventHandler, Events},
|
||||||
terminal::Terminal,
|
terminal::Terminal,
|
||||||
widgets::{
|
widgets::{
|
||||||
clock::{self, Clock, ClockArgs, Style as ClockStyle},
|
clock::{self, Clock, ClockArgs},
|
||||||
countdown::{Countdown, CountdownWidget},
|
countdown::{Countdown, CountdownWidget},
|
||||||
footer::Footer,
|
footer::Footer,
|
||||||
header::Header,
|
header::Header,
|
||||||
@ -28,13 +28,6 @@ enum Mode {
|
|||||||
Quit,
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub enum Content {
|
|
||||||
Countdown,
|
|
||||||
Timer,
|
|
||||||
Pomodoro,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
content: Content,
|
content: Content,
|
||||||
@ -49,29 +42,38 @@ pub struct App {
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn new(args: Args) -> Self {
|
pub fn new(args: Args) -> Self {
|
||||||
|
let Args {
|
||||||
|
style,
|
||||||
|
work: work_initial_value,
|
||||||
|
pause: pause_initial_value,
|
||||||
|
mode: content,
|
||||||
|
countdown: countdown_initial_value,
|
||||||
|
decis: with_decis,
|
||||||
|
..
|
||||||
|
} = args;
|
||||||
Self {
|
Self {
|
||||||
mode: Mode::Running,
|
mode: Mode::Running,
|
||||||
content: Content::Countdown,
|
content,
|
||||||
show_menu: false,
|
show_menu: false,
|
||||||
clock_style: ClockStyle::Default,
|
clock_style: style,
|
||||||
with_decis: false,
|
with_decis,
|
||||||
countdown: Countdown::new(Clock::<clock::Countdown>::new(ClockArgs {
|
countdown: Countdown::new(Clock::<clock::Countdown>::new(ClockArgs {
|
||||||
initial_value: args.countdown,
|
initial_value: countdown_initial_value,
|
||||||
tick_value: Duration::from_millis(TICK_VALUE_MS),
|
tick_value: Duration::from_millis(TICK_VALUE_MS),
|
||||||
style: ClockStyle::Default,
|
style,
|
||||||
with_decis: false,
|
with_decis,
|
||||||
})),
|
})),
|
||||||
timer: Timer::new(Clock::<clock::Timer>::new(ClockArgs {
|
timer: Timer::new(Clock::<clock::Timer>::new(ClockArgs {
|
||||||
initial_value: Duration::ZERO,
|
initial_value: Duration::ZERO,
|
||||||
tick_value: Duration::from_millis(TICK_VALUE_MS),
|
tick_value: Duration::from_millis(TICK_VALUE_MS),
|
||||||
style: ClockStyle::Default,
|
style,
|
||||||
with_decis: false,
|
with_decis,
|
||||||
})),
|
})),
|
||||||
pomodoro: Pomodoro::new(PomodoroArgs {
|
pomodoro: Pomodoro::new(PomodoroArgs {
|
||||||
work: args.work,
|
work: work_initial_value,
|
||||||
pause: args.pause,
|
pause: pause_initial_value,
|
||||||
style: ClockStyle::Default,
|
style,
|
||||||
with_decis: false,
|
with_decis,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
60
src/args.rs
60
src/args.rs
@ -1,10 +1,43 @@
|
|||||||
use clap::Parser;
|
use clap::{Parser, ValueEnum};
|
||||||
use color_eyre::{
|
use color_eyre::{
|
||||||
eyre::{ensure, eyre},
|
eyre::{ensure, eyre},
|
||||||
Report,
|
Report,
|
||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
||||||
|
pub enum Content {
|
||||||
|
#[value(name = "countdown", alias = "c")]
|
||||||
|
Countdown,
|
||||||
|
#[value(name = "timer", alias = "t")]
|
||||||
|
Timer,
|
||||||
|
#[value(name = "pomodoro", alias = "p")]
|
||||||
|
Pomodoro,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, ValueEnum)]
|
||||||
|
pub enum ClockStyle {
|
||||||
|
#[value(name = "bold", alias = "b")]
|
||||||
|
Bold,
|
||||||
|
#[value(name = "empty", alias = "e")]
|
||||||
|
Empty,
|
||||||
|
#[value(name = "thick", alias = "t")]
|
||||||
|
Thick,
|
||||||
|
#[value(name = "cross", alias = "c")]
|
||||||
|
Cross,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ClockStyle {
|
||||||
|
pub fn next(&self) -> Self {
|
||||||
|
match self {
|
||||||
|
ClockStyle::Bold => ClockStyle::Empty,
|
||||||
|
ClockStyle::Empty => ClockStyle::Thick,
|
||||||
|
ClockStyle::Thick => ClockStyle::Cross,
|
||||||
|
ClockStyle::Cross => ClockStyle::Bold,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[arg(long, short, value_parser = parse_duration,
|
#[arg(long, short, value_parser = parse_duration,
|
||||||
@ -22,6 +55,31 @@ pub struct Args {
|
|||||||
help = "Pause time to count down from. Format: 'ss', 'mm:ss', or 'hh:mm:ss'"
|
help = "Pause time to count down from. Format: 'ss', 'mm:ss', or 'hh:mm:ss'"
|
||||||
)]
|
)]
|
||||||
pub pause: Duration,
|
pub pause: Duration,
|
||||||
|
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
short = 'd',
|
||||||
|
default_value = "false",
|
||||||
|
help = "Wether to show deciseconds or not"
|
||||||
|
)]
|
||||||
|
pub decis: bool,
|
||||||
|
|
||||||
|
#[arg(
|
||||||
|
short = 'm',
|
||||||
|
value_enum,
|
||||||
|
default_value = "timer",
|
||||||
|
help = "Mode to start with: [t]imer, [c]ountdown, [p]omodoro"
|
||||||
|
)]
|
||||||
|
pub mode: Content,
|
||||||
|
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
short = 's',
|
||||||
|
value_enum,
|
||||||
|
default_value = "bold",
|
||||||
|
help = "Style to display time with: [b]old, [t]hick, [c]ross, [e]mpty"
|
||||||
|
)]
|
||||||
|
pub style: ClockStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_duration(arg: &str) -> Result<Duration, Report> {
|
fn parse_duration(arg: &str) -> Result<Duration, Report> {
|
||||||
|
|||||||
@ -9,26 +9,7 @@ use ratatui::{
|
|||||||
widgets::StatefulWidget,
|
widgets::StatefulWidget,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::utils::center_horizontal;
|
use crate::{args::ClockStyle, utils::center_horizontal};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub enum Style {
|
|
||||||
Default,
|
|
||||||
Empty,
|
|
||||||
Thick,
|
|
||||||
Cross,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Style {
|
|
||||||
pub fn next(&self) -> Self {
|
|
||||||
match self {
|
|
||||||
Style::Default => Style::Empty,
|
|
||||||
Style::Empty => Style::Thick,
|
|
||||||
Style::Thick => Style::Cross,
|
|
||||||
Style::Cross => Style::Default,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Display, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, Display, PartialEq, Eq)]
|
||||||
pub enum Time {
|
pub enum Time {
|
||||||
@ -100,7 +81,7 @@ pub struct Clock<T> {
|
|||||||
current_value: Duration,
|
current_value: Duration,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
format: Format,
|
format: Format,
|
||||||
pub style: Style,
|
pub style: ClockStyle,
|
||||||
pub with_decis: bool,
|
pub with_decis: bool,
|
||||||
phantom: PhantomData<T>,
|
phantom: PhantomData<T>,
|
||||||
}
|
}
|
||||||
@ -108,7 +89,7 @@ pub struct Clock<T> {
|
|||||||
pub struct ClockArgs {
|
pub struct ClockArgs {
|
||||||
pub initial_value: Duration,
|
pub initial_value: Duration,
|
||||||
pub tick_value: Duration,
|
pub tick_value: Duration,
|
||||||
pub style: Style,
|
pub style: ClockStyle,
|
||||||
pub with_decis: bool,
|
pub with_decis: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,12 +552,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_digit_symbol(&self, style: &Style) -> &str {
|
fn get_digit_symbol(&self, style: &ClockStyle) -> &str {
|
||||||
match &style {
|
match &style {
|
||||||
Style::Default => "█",
|
ClockStyle::Bold => "█",
|
||||||
Style::Empty => "░",
|
ClockStyle::Empty => "░",
|
||||||
Style::Cross => "╬",
|
ClockStyle::Cross => "╬",
|
||||||
Style::Thick => "┃",
|
ClockStyle::Thick => "┃",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,13 +8,12 @@ use ratatui::{
|
|||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
args::ClockStyle,
|
||||||
events::{Event, EventHandler},
|
events::{Event, EventHandler},
|
||||||
utils::center,
|
utils::center,
|
||||||
widgets::clock::{self, Clock, ClockWidget},
|
widgets::clock::{self, Clock, ClockWidget},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::clock::Style;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Countdown {
|
pub struct Countdown {
|
||||||
clock: Clock<clock::Countdown>,
|
clock: Clock<clock::Countdown>,
|
||||||
@ -25,7 +24,7 @@ impl Countdown {
|
|||||||
Self { clock }
|
Self { clock }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_style(&mut self, style: Style) {
|
pub fn set_style(&mut self, style: ClockStyle) {
|
||||||
self.clock.style = style;
|
self.clock.style = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use crate::app::Content;
|
use crate::args::Content;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::{Constraint, Layout, Rect},
|
layout::{Constraint, Layout, Rect},
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
args::ClockStyle,
|
||||||
constants::TICK_VALUE_MS,
|
constants::TICK_VALUE_MS,
|
||||||
events::{Event, EventHandler},
|
events::{Event, EventHandler},
|
||||||
utils::center,
|
utils::center,
|
||||||
@ -15,7 +16,7 @@ use std::{cmp::max, time::Duration};
|
|||||||
|
|
||||||
use strum::Display;
|
use strum::Display;
|
||||||
|
|
||||||
use super::clock::{ClockArgs, Style};
|
use super::clock::ClockArgs;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Display, Hash, Eq, PartialEq)]
|
#[derive(Debug, Clone, Display, Hash, Eq, PartialEq)]
|
||||||
enum Mode {
|
enum Mode {
|
||||||
@ -47,7 +48,7 @@ pub struct Pomodoro {
|
|||||||
pub struct PomodoroArgs {
|
pub struct PomodoroArgs {
|
||||||
pub work: Duration,
|
pub work: Duration,
|
||||||
pub pause: Duration,
|
pub pause: Duration,
|
||||||
pub style: Style,
|
pub style: ClockStyle,
|
||||||
pub with_decis: bool,
|
pub with_decis: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ impl Pomodoro {
|
|||||||
self.clock_map.get(&self.mode)
|
self.clock_map.get(&self.mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_style(&mut self, style: Style) {
|
pub fn set_style(&mut self, style: crate::args::ClockStyle) {
|
||||||
self.clock_map.work.style = style;
|
self.clock_map.work.style = style;
|
||||||
self.clock_map.pause.style = style;
|
self.clock_map.pause.style = style;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
args::ClockStyle,
|
||||||
events::{Event, EventHandler},
|
events::{Event, EventHandler},
|
||||||
utils::center,
|
utils::center,
|
||||||
widgets::clock::{self, Clock, ClockWidget, Style},
|
widgets::clock::{self, Clock, ClockWidget},
|
||||||
};
|
};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
@ -22,7 +23,7 @@ impl Timer {
|
|||||||
Self { clock }
|
Self { clock }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_style(&mut self, style: Style) {
|
pub fn set_style(&mut self, style: ClockStyle) {
|
||||||
self.clock.style = style;
|
self.clock.style = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user