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]
|
||||
-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]
|
||||
-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
|
||||
```
|
||||
|
||||
|
||||
44
src/app.rs
44
src/app.rs
@ -1,10 +1,10 @@
|
||||
use crate::{
|
||||
args::Args,
|
||||
args::{Args, ClockStyle, Content},
|
||||
constants::TICK_VALUE_MS,
|
||||
events::{Event, EventHandler, Events},
|
||||
terminal::Terminal,
|
||||
widgets::{
|
||||
clock::{self, Clock, ClockArgs, Style as ClockStyle},
|
||||
clock::{self, Clock, ClockArgs},
|
||||
countdown::{Countdown, CountdownWidget},
|
||||
footer::Footer,
|
||||
header::Header,
|
||||
@ -28,13 +28,6 @@ enum Mode {
|
||||
Quit,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum Content {
|
||||
Countdown,
|
||||
Timer,
|
||||
Pomodoro,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct App {
|
||||
content: Content,
|
||||
@ -49,29 +42,38 @@ pub struct App {
|
||||
|
||||
impl App {
|
||||
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 {
|
||||
mode: Mode::Running,
|
||||
content: Content::Countdown,
|
||||
content,
|
||||
show_menu: false,
|
||||
clock_style: ClockStyle::Default,
|
||||
with_decis: false,
|
||||
clock_style: style,
|
||||
with_decis,
|
||||
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),
|
||||
style: ClockStyle::Default,
|
||||
with_decis: false,
|
||||
style,
|
||||
with_decis,
|
||||
})),
|
||||
timer: Timer::new(Clock::<clock::Timer>::new(ClockArgs {
|
||||
initial_value: Duration::ZERO,
|
||||
tick_value: Duration::from_millis(TICK_VALUE_MS),
|
||||
style: ClockStyle::Default,
|
||||
with_decis: false,
|
||||
style,
|
||||
with_decis,
|
||||
})),
|
||||
pomodoro: Pomodoro::new(PomodoroArgs {
|
||||
work: args.work,
|
||||
pause: args.pause,
|
||||
style: ClockStyle::Default,
|
||||
with_decis: false,
|
||||
work: work_initial_value,
|
||||
pause: pause_initial_value,
|
||||
style,
|
||||
with_decis,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
60
src/args.rs
60
src/args.rs
@ -1,10 +1,43 @@
|
||||
use clap::Parser;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use color_eyre::{
|
||||
eyre::{ensure, eyre},
|
||||
Report,
|
||||
};
|
||||
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)]
|
||||
pub struct Args {
|
||||
#[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'"
|
||||
)]
|
||||
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> {
|
||||
|
||||
@ -9,26 +9,7 @@ use ratatui::{
|
||||
widgets::StatefulWidget,
|
||||
};
|
||||
|
||||
use crate::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,
|
||||
}
|
||||
}
|
||||
}
|
||||
use crate::{args::ClockStyle, utils::center_horizontal};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Display, PartialEq, Eq)]
|
||||
pub enum Time {
|
||||
@ -100,7 +81,7 @@ pub struct Clock<T> {
|
||||
current_value: Duration,
|
||||
mode: Mode,
|
||||
format: Format,
|
||||
pub style: Style,
|
||||
pub style: ClockStyle,
|
||||
pub with_decis: bool,
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
@ -108,7 +89,7 @@ pub struct Clock<T> {
|
||||
pub struct ClockArgs {
|
||||
pub initial_value: Duration,
|
||||
pub tick_value: Duration,
|
||||
pub style: Style,
|
||||
pub style: ClockStyle,
|
||||
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 {
|
||||
Style::Default => "█",
|
||||
Style::Empty => "░",
|
||||
Style::Cross => "╬",
|
||||
Style::Thick => "┃",
|
||||
ClockStyle::Bold => "█",
|
||||
ClockStyle::Empty => "░",
|
||||
ClockStyle::Cross => "╬",
|
||||
ClockStyle::Thick => "┃",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,13 +8,12 @@ use ratatui::{
|
||||
use std::cmp::max;
|
||||
|
||||
use crate::{
|
||||
args::ClockStyle,
|
||||
events::{Event, EventHandler},
|
||||
utils::center,
|
||||
widgets::clock::{self, Clock, ClockWidget},
|
||||
};
|
||||
|
||||
use super::clock::Style;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Countdown {
|
||||
clock: Clock<clock::Countdown>,
|
||||
@ -25,7 +24,7 @@ impl Countdown {
|
||||
Self { clock }
|
||||
}
|
||||
|
||||
pub fn set_style(&mut self, style: Style) {
|
||||
pub fn set_style(&mut self, style: ClockStyle) {
|
||||
self.clock.style = style;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::app::Content;
|
||||
use crate::args::Content;
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Layout, Rect},
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use crate::{
|
||||
args::ClockStyle,
|
||||
constants::TICK_VALUE_MS,
|
||||
events::{Event, EventHandler},
|
||||
utils::center,
|
||||
@ -15,7 +16,7 @@ use std::{cmp::max, time::Duration};
|
||||
|
||||
use strum::Display;
|
||||
|
||||
use super::clock::{ClockArgs, Style};
|
||||
use super::clock::ClockArgs;
|
||||
|
||||
#[derive(Debug, Clone, Display, Hash, Eq, PartialEq)]
|
||||
enum Mode {
|
||||
@ -47,7 +48,7 @@ pub struct Pomodoro {
|
||||
pub struct PomodoroArgs {
|
||||
pub work: Duration,
|
||||
pub pause: Duration,
|
||||
pub style: Style,
|
||||
pub style: ClockStyle,
|
||||
pub with_decis: bool,
|
||||
}
|
||||
|
||||
@ -82,7 +83,7 @@ impl Pomodoro {
|
||||
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.pause.style = style;
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
use crate::{
|
||||
args::ClockStyle,
|
||||
events::{Event, EventHandler},
|
||||
utils::center,
|
||||
widgets::clock::{self, Clock, ClockWidget, Style},
|
||||
widgets::clock::{self, Clock, ClockWidget},
|
||||
};
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
@ -22,7 +23,7 @@ impl Timer {
|
||||
Self { clock }
|
||||
}
|
||||
|
||||
pub fn set_style(&mut self, style: Style) {
|
||||
pub fn set_style(&mut self, style: ClockStyle) {
|
||||
self.clock.style = style;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user