Skip to content

Commit

Permalink
feat(term): add ferra, solarized_dark, helix themes
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed May 23, 2024
1 parent 9942398 commit d463de0
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 106 deletions.
19 changes: 16 additions & 3 deletions crates/synd_term/src/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use chrono::{DateTime, Utc};
use crossterm::event::{Event as CrosstermEvent, KeyEvent, KeyEventKind};
use futures_util::{FutureExt, Stream, StreamExt};
use ratatui::{style::palette::tailwind, widgets::Widget};
use ratatui::widgets::Widget;
use synd_auth::device_flow::{
self, DeviceAccessTokenResponse, DeviceAuthorizationResponse, DeviceFlow,
};
Expand All @@ -31,7 +31,7 @@ use crate::{
authentication::AuthenticateState, filter::FeedFilter, root::Root,
subscription::UnsubscribeSelection, tabs::Tab, Components,
},
theme::Theme,
theme::{Palette, Theme},
},
};

Expand Down Expand Up @@ -133,7 +133,7 @@ impl Application {
interactor: Interactor::new(),
authenticator: Authenticator::new(),
in_flight: InFlight::new().with_throbber_timer_interval(config.throbber_timer_interval),
theme: Theme::with_palette(&tailwind::BLUE),
theme: Theme::default(),
idle_timer: Box::pin(tokio::time::sleep(config.idle_timer_interval)),
screen: Screen::Login,
config,
Expand Down Expand Up @@ -560,6 +560,10 @@ impl Application {
self.apply_feed_filter(filter);
self.should_render();
}
Command::RotateTheme => {
self.rotate_theme();
self.should_render();
}
Command::HandleError {
message,
request_seq,
Expand Down Expand Up @@ -938,6 +942,15 @@ impl Application {
self.components.entries.update_filter(filter.clone());
self.components.subscription.update_filter(filter);
}

fn rotate_theme(&mut self) {
let p = match self.theme.name {
"ferra" => Palette::solarized_dark(),
"solarized_dark" => Palette::helix(),
_ => Palette::ferra(),
};
self.theme = Theme::with_palette(&p);
}
}

impl Application {
Expand Down
62 changes: 12 additions & 50 deletions crates/synd_term/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,27 @@
use std::{path::PathBuf, time::Duration};

use clap::{Parser, Subcommand};
use ratatui::style::palette::tailwind;
use url::Url;

use crate::config;
use crate::{config, ui::theme};

mod check;
mod clean;
mod export;

#[derive(Copy, Clone, PartialEq, Eq, Debug, clap::ValueEnum)]
pub enum Palette {
Slate,
Gray,
Zinc,
Neutral,
Stone,
Red,
Orange,
Amber,
Yellow,
Lime,
Green,
Emerald,
Teal,
Cyan,
Sky,
Blue,
Indigo,
Violet,
Purple,
Fuchsia,
Pink,
Ferra,
SolarizedDark,
Helix,
}

impl From<Palette> for tailwind::Palette {
fn from(t: Palette) -> Self {
#[allow(clippy::wildcard_imports)]
match t {
Palette::Slate => tailwind::SLATE,
Palette::Gray => tailwind::GRAY,
Palette::Zinc => tailwind::ZINC,
Palette::Neutral => tailwind::NEUTRAL,
Palette::Stone => tailwind::STONE,
Palette::Red => tailwind::RED,
Palette::Orange => tailwind::ORANGE,
Palette::Amber => tailwind::AMBER,
Palette::Yellow => tailwind::YELLOW,
Palette::Lime => tailwind::LIME,
Palette::Green => tailwind::GREEN,
Palette::Emerald => tailwind::EMERALD,
Palette::Teal => tailwind::TEAL,
Palette::Cyan => tailwind::CYAN,
Palette::Sky => tailwind::SKY,
Palette::Blue => tailwind::BLUE,
Palette::Indigo => tailwind::INDIGO,
Palette::Violet => tailwind::VIOLET,
Palette::Purple => tailwind::PURPLE,
Palette::Fuchsia => tailwind::FUCHSIA,
Palette::Pink => tailwind::PINK,
impl From<Palette> for theme::Palette {
fn from(p: Palette) -> Self {
match p {
Palette::Ferra => theme::Palette::ferra(),
Palette::SolarizedDark => theme::Palette::solarized_dark(),
Palette::Helix => theme::Palette::helix(),
}
}
}
Expand All @@ -70,8 +32,8 @@ pub struct Args {
/// Log file path
#[arg(long, default_value = config::log_path().into_os_string(), env = config::env::LOG_PATH)]
pub log: PathBuf,
/// Color palette
#[arg(value_enum, long = "theme", default_value_t = Palette::Slate, env = config::env::THEME)]
/// Color theme
#[arg(value_enum, long = "theme", default_value_t = Palette::Ferra, env = config::env::THEME, value_name = "THEME")]
pub palette: Palette,
#[command(subcommand)]
pub command: Option<Command>,
Expand Down
6 changes: 6 additions & 0 deletions crates/synd_term/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ pub(crate) enum Command {
ActivateAllFilterCategories,
DeactivateAllFilterCategories,

// Theme
RotateTheme,

HandleError {
message: String,
request_seq: Option<RequestSequence>,
Expand Down Expand Up @@ -212,4 +215,7 @@ impl Command {
pub fn deactivate_filtering() -> Self {
Command::DeactivateFiltering
}
pub fn rotate_theme() -> Self {
Command::RotateTheme
}
}
1 change: 1 addition & 0 deletions crates/synd_term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn default() -> KeymapsConfig {
});
let global = keymap!({
"q" | "C-c" => quit ,
"S-t" => rotate_theme,
});

KeymapsConfig {
Expand Down
1 change: 1 addition & 0 deletions crates/synd_term/src/keymap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ fn parse(s: &str) -> anyhow::Result<KeyEvent> {
for token in tokens {
let modifier = match token {
"C" => KeyModifiers::CONTROL,
"S" => KeyModifiers::SHIFT,
undefined => bail!("`{undefined}` modifier is not implemented yet"),
};
modifiers.insert(modifier);
Expand Down
10 changes: 3 additions & 7 deletions crates/synd_term/src/types/requirement_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ use synd_feed::types::Requirement;
use crate::ui::theme::RequirementLabelTheme;

pub trait RequirementExt {
fn label(&self, theme: &RequirementLabelTheme) -> [Span<'static>; 3];
fn label(&self, theme: &RequirementLabelTheme) -> Span<'static>;
}

impl RequirementExt for Requirement {
fn label(&self, theme: &RequirementLabelTheme) -> [Span<'static>; 3] {
fn label(&self, theme: &RequirementLabelTheme) -> Span<'static> {
let (label, color) = match self {
Requirement::Must => ("MST", theme.must),
Requirement::Should => ("SHD", theme.should),
Requirement::May => ("MAY", theme.may),
};
[
Span::styled(" ", Style::default().bg(color)),
Span::styled(label, Style::default().bg(color).fg(theme.fg)),
Span::styled(" ", Style::default().bg(color)),
]
Span::styled(label, Style::default().bg(color).fg(theme.fg))
}
}
15 changes: 9 additions & 6 deletions crates/synd_term/src/ui/components/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};
use ratatui::{
prelude::{Alignment, Buffer, Constraint, Layout, Margin, Rect},
style::{Modifier, Style, Stylize},
style::Stylize,
text::{Line, Span, Text},
widgets::{
block::{Position, Title},
Expand Down Expand Up @@ -136,7 +136,6 @@ impl Entries {
let entries = Table::new(rows, widths)
.header(header.style(cx.theme.entries.header))
.column_spacing(2)
.style(cx.theme.entries.background)
.highlight_symbol(ui::TABLE_HIGHLIGHT_SYMBOL)
.highlight_style(cx.theme.entries.selected_entry)
.highlight_spacing(ratatui::widgets::HighlightSpacing::WhenSelected);
Expand Down Expand Up @@ -209,7 +208,7 @@ impl Entries {
.unwrap_or_else(|| ui::default_icon());

let feed_title = entry.feed_title.as_deref().unwrap_or(ui::UNKNOWN_SYMBOL);
let requirement = entry.requirement().label(&cx.theme.requirement).to_vec();
let requirement = entry.requirement().label(&cx.theme.requirement);

Row::new([
Cell::from(Span::from(published)),
Expand All @@ -219,7 +218,11 @@ impl Entries {
Span::from(title),
])),
Cell::from(Span::from(feed_title)),
Cell::from(Line::from(requirement)),
Cell::from(Line::from(vec![
Span::from(" "),
requirement,
Span::from(" "),
])),
])
};

Expand All @@ -232,7 +235,7 @@ impl Entries {
)
}

fn render_summary(&self, area: Rect, buf: &mut Buffer, _cx: &Context<'_>) {
fn render_summary(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let block = Block::new()
.padding(Padding {
left: 3,
Expand Down Expand Up @@ -260,7 +263,7 @@ impl Entries {
// should to Lines?
let paragraph = Paragraph::new(Text::from(summary))
.wrap(Wrap { trim: false })
.style(Style::default().add_modifier(Modifier::DIM))
.style(cx.theme.entries.summary)
.alignment(Alignment::Center);

Widget::render(paragraph, inner, buf);
Expand Down
12 changes: 10 additions & 2 deletions crates/synd_term/src/ui/components/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,19 @@ impl Filter {
Span::from(concat!(icon!(requirement), " Requirement")).dim(),
Span::from(" "),
];
spans.extend(self.requirement.label(&cx.theme.requirement));
spans.push(self.requirement.label(&cx.theme.requirement).bold());

spans.extend([
Span::from(" "),
Span::from(concat!(icon!(category), " Categories")).dim(),
{
let s = Span::from(concat!(icon!(category), " Categories"));

if self.state == State::CategoryFiltering {
s
} else {
s.dim()
}
},
Span::from(" "),
]);

Expand Down
4 changes: 1 addition & 3 deletions crates/synd_term/src/ui/components/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ impl<'a> Root<'a> {
impl<'a> Widget for Root<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
// Background
Block::new()
.style(self.cx.theme.background)
.render(area, buf);
Block::new().style(self.cx.theme.base).render(area, buf);

if self.components.auth.should_render() {
let [auth_area, prompt_area] =
Expand Down
13 changes: 7 additions & 6 deletions crates/synd_term/src/ui/components/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,7 @@ impl Subscription {
.as_deref()
.unwrap_or(ui::UNKNOWN_SYMBOL);
let desc = feed_meta.description.as_deref().unwrap_or("");
let requirement = feed_meta
.requirement()
.label(&cx.theme.requirement)
.to_vec();
let requirement = feed_meta.requirement().label(&cx.theme.requirement);
let category = feed_meta.category();
let icon = cx
.categories
Expand All @@ -299,7 +296,11 @@ impl Subscription {
.trim_end_matches('/'),
)),
Cell::from(Span::from(desc)),
Cell::from(Line::from(requirement)),
Cell::from(Line::from(vec![
Span::from(" "),
requirement,
Span::from(" "),
])),
])
};

Expand Down Expand Up @@ -467,7 +468,7 @@ impl Subscription {
bottom: 1,
})
.borders(Borders::ALL)
.style(cx.theme.background);
.style(cx.theme.base);

let inner_area = block.inner(area);
let vertical = Layout::vertical([Constraint::Length(6), Constraint::Fill(1)]);
Expand Down
2 changes: 1 addition & 1 deletion crates/synd_term/src/ui/components/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Tabs {
width: area.width.saturating_sub(5),
..area
};
// left padding * 2 + len("Entries" + "Feeds") = 20

let horizontal = Layout::horizontal([Constraint::Min(0), Constraint::Length(24)]);
let [title, tabs] = horizontal.areas(area);

Expand Down
Loading

0 comments on commit d463de0

Please # to comment.