Add styles: Light, Medium, Dark, Braille (#24)

* add `Style::Braille`, use ratatui's shades/arrows

* update args

* update README
This commit is contained in:
Jens K. 2024-12-23 15:13:06 +01:00 committed by GitHub
parent d86f8905f2
commit acb627b1d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 52 additions and 39 deletions

View File

@ -24,13 +24,13 @@ _soon_
Usage: timr [OPTIONS]
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]
-r, --reset Reset stored values to default
-c, --countdown <COUNTDOWN> Countdown time to start from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 10:00]
-w, --work <WORK> Work time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 25:00]
-p, --pause <PAUSE> Pause time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 5:00]
-d, --decis Wether to show deciseconds or not.
-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]
-r, --reset Reset stored values to default.
-h, --help Print help
```

View File

@ -11,40 +11,31 @@ use crate::{app::Content, widgets::clock::Style};
pub struct Args {
#[arg(long, short, value_parser = parse_duration,
default_value="10:00" /* 10min */,
help = "Countdown time to start from. Format: 'ss', 'mm:ss', or 'hh:mm:ss'"
help = "Countdown time to start from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'"
)]
pub countdown: Duration,
#[arg(long, short, value_parser = parse_duration,
help = "Work time to count down from. Format: 'ss', 'mm:ss', or 'hh:mm:ss'"
help = "Work time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'"
)]
pub work: Option<Duration>,
#[arg(long, short, value_parser = parse_duration,
default_value="5:00" /* 5min */,
help = "Pause time to count down from. Format: 'ss', 'mm:ss', or 'hh:mm:ss'"
help = "Pause time to count down from. Formats: 'ss', 'mm:ss', or 'hh:mm:ss'"
)]
pub pause: Duration,
#[arg(long, short = 'd', help = "Whether to show deciseconds or not")]
#[arg(long, short = 'd', help = "Whether to show deciseconds or not.")]
pub decis: bool,
#[arg(
short = 'm',
value_enum,
help = "Mode to start with: [t]imer, [c]ountdown, [p]omodoro"
)]
#[arg(long, short = 'm', value_enum, help = "Mode to start with.")]
pub mode: Option<Content>,
#[arg(
long,
short = 's',
value_enum,
help = "Style to display time with: [b]old, [t]hick, [c]ross, [e]mpty"
)]
#[arg(long, short = 's', value_enum, help = "Style to display time with.")]
pub style: Option<Style>,
#[arg(long, short = 'r', help = "Reset stored values to default")]
#[arg(long, short = 'r', help = "Reset stored values to default.")]
pub reset: bool,
}

View File

@ -8,6 +8,7 @@ use strum::Display;
use ratatui::{
buffer::Buffer,
layout::{Constraint, Layout, Position, Rect},
symbols::shade,
widgets::StatefulWidget,
};
@ -79,23 +80,35 @@ pub enum Format {
#[derive(Debug, Copy, Clone, ValueEnum, Default, Serialize, Deserialize)]
pub enum Style {
#[default]
#[value(name = "bold", alias = "b")]
Bold,
#[value(name = "empty", alias = "e")]
Empty,
#[value(name = "full", alias = "f")]
Full,
#[value(name = "light", alias = "l")]
Light,
#[value(name = "medium", alias = "m")]
Medium,
#[value(name = "dark", alias = "d")]
Dark,
#[value(name = "thick", alias = "t")]
Thick,
#[value(name = "cross", alias = "c")]
Cross,
/// https://en.wikipedia.org/wiki/Braille_Patterns
/// Note: Might not be supported in all terminals
/// see https://docs.rs/ratatui/latest/src/ratatui/symbols.rs.html#150
#[value(name = "braille", alias = "b")]
Braille,
}
impl Style {
pub fn next(&self) -> Self {
match self {
Style::Bold => Style::Empty,
Style::Empty => Style::Thick,
Style::Full => Style::Dark,
Style::Dark => Style::Medium,
Style::Medium => Style::Light,
Style::Light => Style::Braille,
Style::Braille => Style::Thick,
Style::Thick => Style::Cross,
Style::Cross => Style::Bold,
Style::Cross => Style::Full,
}
}
}
@ -599,10 +612,13 @@ where
fn get_digit_symbol(&self, style: &Style) -> &str {
match &style {
Style::Bold => "",
Style::Empty => "",
Style::Full => shade::FULL,
Style::Light => shade::LIGHT,
Style::Medium => shade::MEDIUM,
Style::Dark => shade::DARK,
Style::Cross => "",
Style::Thick => "",
Style::Braille => "",
}
}

View File

@ -5,7 +5,7 @@ use ratatui::{
buffer::Buffer,
layout::{Constraint, Layout, Rect},
style::{Modifier, Style},
symbols,
symbols::{border, scrollbar},
text::{Line, Span},
widgets::{Block, Borders, Cell, Row, Table, Widget},
};
@ -33,8 +33,10 @@ impl Widget for Footer {
Layout::vertical([Constraint::Length(1), Constraint::Percentage(100)]).areas(area);
Block::new()
.borders(Borders::TOP)
.title(format! {"[m]enu {:} ", if self.show_menu {""} else {""}})
.border_set(symbols::border::DOUBLE)
.title(
format! {"[m]enu {:} ", if self.show_menu {scrollbar::VERTICAL.end} else {scrollbar::VERTICAL.begin}},
)
.border_set(border::DOUBLE)
.render(border_area, buf);
// show menu
if self.show_menu {
@ -56,7 +58,7 @@ impl Widget for Footer {
})
.collect();
const SPACE: &str = " ";
const SPACE: &str = " "; // 2 empty spaces
let widths = [Constraint::Length(12), Constraint::Percentage(100)];
Table::new(
[
@ -91,11 +93,15 @@ impl Widget for Footer {
vec![
Span::from("[e]dit done"),
Span::from(SPACE),
Span::from("[← →]edit selection"),
Span::from(format!(
"[{} {}]edit selection",
scrollbar::HORIZONTAL.begin,
scrollbar::HORIZONTAL.end
)), // ← →,
Span::from(SPACE),
Span::from("[↑]edit up"),
Span::from(format!("[{}]edit up", scrollbar::VERTICAL.begin)), // ↑
Span::from(SPACE),
Span::from("[↓]edit down"),
Span::from(format!("[{}]edit up", scrollbar::VERTICAL.end)), // ↓,
]
} else {
let mut spans = vec![