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
4 changed files with 52 additions and 39 deletions

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![