Skip to content

Commit

Permalink
feat(term): stylize requirement lavel
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Apr 13, 2024
1 parent 1f41872 commit 324d599
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
23 changes: 16 additions & 7 deletions crates/synd_term/src/types/requirement_ext.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
use ratatui::{
style::{Color, Style},
text::Span,
};
use synd_feed::types::Requirement;

pub trait RequirementExt {
fn display(&self) -> &'static str;
fn label(&self, color: Color) -> [Span<'static>; 3];
}

impl RequirementExt for Requirement {
fn display(&self) -> &'static str {
match self {
Requirement::Must => "MUST",
Requirement::Should => "SHOULD",
Requirement::May => "MAY",
}
fn label(&self, fg: Color) -> [Span<'static>; 3] {
let (label, color) = match self {
Requirement::Must => ("MST", Color::Rgb(154, 4, 4)),
Requirement::Should => ("SHD", Color::Rgb(243, 201, 105)),
Requirement::May => ("MAY", Color::Rgb(35, 57, 91)),
};
[
Span::styled("", Style::default().fg(color)),
Span::styled(label, Style::default().bg(color).fg(fg)),
Span::styled("", Style::default().fg(color)),
]
}
}
9 changes: 5 additions & 4 deletions crates/synd_term/src/ui/components/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ impl Entries {
Cell::from(" Published"),
Cell::from("󰯂 Entry"),
Cell::from("󰑫 Feed"),
Cell::from(" ReqLv"),
Cell::from(" Req"),
]);

let constraints = [
Constraint::Length(11),
Constraint::Fill(2),
Constraint::Fill(1),
Constraint::Length(7),
Constraint::Length(5),
];

let row = |entry: &'a types::Entry| {
Expand All @@ -159,7 +159,8 @@ impl Entries {
let requirement = entry
.requirement
.unwrap_or(ui::DEFAULT_REQUIREMNET)
.display();
.label(cx.theme.requiment_fg)
.to_vec();

Row::new([
Cell::from(Span::from(published)),
Expand All @@ -169,7 +170,7 @@ impl Entries {
Span::from(title),
])),
Cell::from(Span::from(feed_title)),
Cell::from(Span::from(requirement).dim()),
Cell::from(Line::from(requirement)),
])
};

Expand Down
9 changes: 5 additions & 4 deletions crates/synd_term/src/ui/components/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ impl Subscription {
Cell::from(" Updated"),
Cell::from(" URL"),
Cell::from("󰎞 Description"),
Cell::from(" ReqLv"),
Cell::from(" Req"),
]);

let constraints = [
Constraint::Fill(1),
Constraint::Length(10),
Constraint::Fill(1),
Constraint::Fill(2),
Constraint::Length(7),
Constraint::Length(5),
];

let row = |feed_meta: &'a Feed| {
Expand All @@ -181,7 +181,8 @@ impl Subscription {
let requirement = feed_meta
.requirement
.unwrap_or(ui::DEFAULT_REQUIREMNET)
.display();
.label(cx.theme.requiment_fg)
.to_vec();
let category = feed_meta
.category
.as_ref()
Expand All @@ -199,7 +200,7 @@ impl Subscription {
Cell::from(Span::from(updated)),
Cell::from(Span::from(website_url)),
Cell::from(Span::from(desc)),
Cell::from(Span::from(requirement).dim()),
Cell::from(Line::from(requirement)),
])
};

Expand Down
2 changes: 2 additions & 0 deletions crates/synd_term/src/ui/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Theme {
pub entries: EntriesTheme,
pub error: ErrorTheme,
pub default_icon_fg: Color,
pub requiment_fg: Color,
}

#[derive(Clone)]
Expand Down Expand Up @@ -86,6 +87,7 @@ impl Theme {
message: Style::new().fg(err).bg(bg),
},
default_icon_fg: fg,
requiment_fg: bg,
}
}
pub fn new() -> Self {
Expand Down

0 comments on commit 324d599

Please sign in to comment.