Skip to content

Commit

Permalink
refactor: use ratatui's color serde impl (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski authored Jun 21, 2024
1 parent e4f0a63 commit 580187b
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 262 deletions.
6 changes: 5 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions rm-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ toml = "0.8"
serde = { version = "1", features = ["derive"] }
anyhow = "1"
url = "2.5"
ratatui = "0.26"
ratatui = { version = "0.26", features = ["serde"] }

[dev-dependencies]
serde_json = "1"

239 changes: 0 additions & 239 deletions rm-config/src/color.rs

This file was deleted.

10 changes: 6 additions & 4 deletions rm-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod color;

use std::{
fs::File,
io::{Read, Write},
Expand All @@ -8,7 +6,7 @@ use std::{
};

use anyhow::{bail, Context, Result};
use color::Color;
use ratatui::style::Color;
use serde::{Deserialize, Serialize};
use toml::Table;
use xdg::BaseDirectories;
Expand All @@ -23,12 +21,16 @@ pub struct Config {
pub struct General {
#[serde(default)]
pub auto_hide: bool,
#[serde(default, with = "color")]
#[serde(default = "default_accent_color")]
pub accent_color: Color,
#[serde(default = "default_beginner_mode")]
pub beginner_mode: bool,
}

fn default_accent_color() -> Color {
Color::LightMagenta
}

fn default_beginner_mode() -> bool {
true
}
Expand Down
3 changes: 1 addition & 2 deletions rm-main/src/ui/components/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ impl Component for TabComponent {
.flex(Flex::Center)
.split(rect)[0];

let tabs_highlight_style =
Style::default().fg(self.ctx.config.general.accent_color.as_ratatui());
let tabs_highlight_style = Style::default().fg(self.ctx.config.general.accent_color);
let tabs = Tabs::new(self.tabs_list)
.style(Style::default().white())
.highlight_style(tabs_highlight_style)
Expand Down
4 changes: 2 additions & 2 deletions rm-main/src/ui/global_popups/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ impl Component for HelpPopup {
let popup_rect = centered_rect.inner(&Margin::new(1, 1));
let text_rect = popup_rect.inner(&Margin::new(3, 2));

let title_style = Style::new().fg(self.ctx.config.general.accent_color.as_ratatui());
let title_style = Style::new().fg(self.ctx.config.general.accent_color);
let block = Block::bordered()
.border_set(symbols::border::ROUNDED)
.title(
Title::from(
" [ CLOSE ] "
.fg(self.ctx.config.general.accent_color.as_ratatui())
.fg(self.ctx.config.general.accent_color)
.bold(),
)
.alignment(Alignment::Right)
Expand Down
5 changes: 2 additions & 3 deletions rm-main/src/ui/tabs/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl Component for SearchTab {
if self.search_focus == SearchFocus::Search {
Style::default()
.underlined()
.fg(self.ctx.config.general.accent_color.as_ratatui())
.fg(self.ctx.config.general.accent_color)
} else {
Style::default().underlined().gray()
}
Expand Down Expand Up @@ -264,8 +264,7 @@ impl Component for SearchTab {
.ctx
.config
.general
.accent_color
.as_ratatui());
.accent_color);
let table = Table::new(items, widths)
.header(header)
.highlight_style(table_higlight_style);
Expand Down
2 changes: 1 addition & 1 deletion rm-main/src/ui/tabs/torrents/input_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Component for InputManager {

spans.push(Span::styled(
self.prompt.as_str(),
Style::default().fg(self.ctx.config.general.accent_color.as_ratatui()),
Style::default().fg(self.ctx.config.general.accent_color),
));

spans.push(Span::raw(self.text()));
Expand Down
3 changes: 1 addition & 2 deletions rm-main/src/ui/tabs/torrents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ impl TorrentsTab {
.ctx
.config
.general
.accent_color
.as_ratatui());
.accent_color);

let table_widget = Table::new(torrent_rows, table_manager_lock.widths)
.header(Row::new(
Expand Down
3 changes: 1 addition & 2 deletions rm-main/src/ui/tabs/torrents/popups/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ impl Component for FilesPopup {

let info_text_rect = block_rect.inner(&Margin::new(3, 2));

let highlight_style =
Style::default().fg(self.ctx.config.general.accent_color.as_ratatui());
let highlight_style = Style::default().fg(self.ctx.config.general.accent_color);
let bold_highlight_style = highlight_style.on_black().bold();

let block = Block::bordered()
Expand Down
2 changes: 1 addition & 1 deletion rm-main/src/ui/tabs/torrents/popups/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Component for StatisticsPopup {
let block_rect = popup_rect.inner(&Margin::new(1, 1));
let text_rect = block_rect.inner(&Margin::new(3, 2));

let title_style = Style::default().fg(self.ctx.config.general.accent_color.as_ratatui());
let title_style = Style::default().fg(self.ctx.config.general.accent_color);
let block = Block::bordered()
.border_type(BorderType::Rounded)
.title(Title::from(" Statistics ".set_style(title_style)))
Expand Down
Loading

0 comments on commit 580187b

Please sign in to comment.