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] Usage: timr [OPTIONS]
Options: 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. Formats: '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. Formats: '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. Formats: 'ss', 'mm:ss', or 'hh:mm:ss' [default: 5:00]
-d, --decis Wether to show deciseconds or not -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] -m, --mode <MODE> Mode to start with. [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] -s, --style <STYLE> Style to display time with. [possible values: full, light, medium, dark, thick, cross, braille]
-r, --reset Reset stored values to default -r, --reset Reset stored values to default.
-h, --help Print help -h, --help Print help
``` ```

View File

@ -11,40 +11,31 @@ use crate::{app::Content, widgets::clock::Style};
pub struct Args { pub struct Args {
#[arg(long, short, value_parser = parse_duration, #[arg(long, short, value_parser = parse_duration,
default_value="10:00" /* 10min */, 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, pub countdown: Duration,
#[arg(long, short, value_parser = parse_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>, pub work: Option<Duration>,
#[arg(long, short, value_parser = parse_duration, #[arg(long, short, value_parser = parse_duration,
default_value="5:00" /* 5min */, 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, 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, pub decis: bool,
#[arg( #[arg(long, short = 'm', value_enum, help = "Mode to start with.")]
short = 'm',
value_enum,
help = "Mode to start with: [t]imer, [c]ountdown, [p]omodoro"
)]
pub mode: Option<Content>, pub mode: Option<Content>,
#[arg( #[arg(long, short = 's', value_enum, help = "Style to display time with.")]
long,
short = 's',
value_enum,
help = "Style to display time with: [b]old, [t]hick, [c]ross, [e]mpty"
)]
pub style: Option<Style>, 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, pub reset: bool,
} }

View File

@ -8,6 +8,7 @@ use strum::Display;
use ratatui::{ use ratatui::{
buffer::Buffer, buffer::Buffer,
layout::{Constraint, Layout, Position, Rect}, layout::{Constraint, Layout, Position, Rect},
symbols::shade,
widgets::StatefulWidget, widgets::StatefulWidget,
}; };
@ -79,23 +80,35 @@ pub enum Format {
#[derive(Debug, Copy, Clone, ValueEnum, Default, Serialize, Deserialize)] #[derive(Debug, Copy, Clone, ValueEnum, Default, Serialize, Deserialize)]
pub enum Style { pub enum Style {
#[default] #[default]
#[value(name = "bold", alias = "b")] #[value(name = "full", alias = "f")]
Bold, Full,
#[value(name = "empty", alias = "e")] #[value(name = "light", alias = "l")]
Empty, Light,
#[value(name = "medium", alias = "m")]
Medium,
#[value(name = "dark", alias = "d")]
Dark,
#[value(name = "thick", alias = "t")] #[value(name = "thick", alias = "t")]
Thick, Thick,
#[value(name = "cross", alias = "c")] #[value(name = "cross", alias = "c")]
Cross, 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 { impl Style {
pub fn next(&self) -> Self { pub fn next(&self) -> Self {
match self { match self {
Style::Bold => Style::Empty, Style::Full => Style::Dark,
Style::Empty => Style::Thick, Style::Dark => Style::Medium,
Style::Medium => Style::Light,
Style::Light => Style::Braille,
Style::Braille => Style::Thick,
Style::Thick => Style::Cross, 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 { fn get_digit_symbol(&self, style: &Style) -> &str {
match &style { match &style {
Style::Bold => "", Style::Full => shade::FULL,
Style::Empty => "", Style::Light => shade::LIGHT,
Style::Medium => shade::MEDIUM,
Style::Dark => shade::DARK,
Style::Cross => "", Style::Cross => "",
Style::Thick => "", Style::Thick => "",
Style::Braille => "",
} }
} }

View File

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