Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configurable icons #89

Merged
merged 11 commits into from
Aug 17, 2024
Merged
26 changes: 26 additions & 0 deletions rm-config/defaults/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,29 @@ headers = ["Name", "SizeWhenDone", "Progress", "Eta", "DownloadRate", "UploadRat
# If you uncomment this, providers won't be automatically added in future
# versions of Rustmission.
# providers = ["Knaben", "Nyaa"]

[icons]
# Ascii alternatives # Defaults
# upload = "↑" # ""
# download = "↓" # ""
# arrow_left = "←" # ""
# arrow_right = "→" # ""
# arrow_up = "↑" # ""
# arrow_down = "↓" # ""
# triangle_right = "▶" # "▶"
# triangle_down = "▼" # "▼"
# file = "∷" # ""
# disk = "[D]" # "󰋊"
# help = "[?]" # "󰘥"
# success = "✔" # ""
# failure = "✖" # ""
# searching = "⟳" # ""
# verifying = "⟳" # "󰑓"
# loading = "⌛" # "󱥸"
# pause = "‖" # "󰏤"
# idle = "○" # "󱗼"
# magnifying_glass = "[o]" # ""
# provider_disabled = "⛔" # "󰪎"
# provider_category_general = "[G]" # ""
# provider_category_anime = "[A]" # "󰎁"

21 changes: 12 additions & 9 deletions rm-config/src/keymap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use serde::{
Deserialize, Serialize,
};

use crate::utils::{self, ConfigFetchingError};
use crate::{
utils::{self, ConfigFetchingError},
CONFIG,
};
use rm_shared::action::Action;

use self::actions::{general::GeneralAction, torrents_tab::TorrentsAction};
Expand All @@ -36,7 +39,7 @@ pub struct KeybindsHolder<T: Into<Action>> {
}

#[derive(Serialize, Clone)]
pub struct Keybinding<T: Into<Action>> {
pub struct Keybinding<T> {
pub on: KeyCode,
#[serde(default)]
pub modifier: KeyModifier,
Expand All @@ -49,10 +52,10 @@ impl<T: Into<Action>> Keybinding<T> {
let key = match self.on {
KeyCode::Backspace => "Backspace".into(),
KeyCode::Enter => "Enter".into(),
KeyCode::Left => "".into(),
KeyCode::Right => "".into(),
KeyCode::Up => "".into(),
KeyCode::Down => "".into(),
KeyCode::Left => CONFIG.icons.arrow_left.clone(),
KeyCode::Right => CONFIG.icons.arrow_right.clone(),
KeyCode::Up => CONFIG.icons.arrow_up.clone(),
KeyCode::Down => CONFIG.icons.arrow_down.clone(),
KeyCode::Home => "Home".into(),
KeyCode::End => "End".into(),
KeyCode::PageUp => "PageUp".into(),
Expand Down Expand Up @@ -90,7 +93,7 @@ impl<T: Into<Action>> Keybinding<T> {
}
}

impl<T: Into<Action>> Keybinding<T> {
impl<T> Keybinding<T> {
fn new(on: KeyCode, action: T, modifier: Option<KeyModifier>, show_in_help: bool) -> Self {
Self {
on,
Expand All @@ -101,7 +104,7 @@ impl<T: Into<Action>> Keybinding<T> {
}
}

impl<'de, T: Into<Action> + Deserialize<'de>> Deserialize<'de> for Keybinding<T> {
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Keybinding<T> {
fn deserialize<D>(deserializer: D) -> std::prelude::v1::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
Expand All @@ -119,7 +122,7 @@ impl<'de, T: Into<Action> + Deserialize<'de>> Deserialize<'de> for Keybinding<T>
phantom: PhantomData<T>,
}

impl<'de, T: Into<Action> + Deserialize<'de>> Visitor<'de> for KeybindingVisitor<T> {
impl<'de, T: Deserialize<'de>> Visitor<'de> for KeybindingVisitor<T> {
type Value = Keybinding<T>;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
2 changes: 2 additions & 0 deletions rm-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Config {
pub connection: main_config::Connection,
pub torrents_tab: main_config::TorrentsTab,
pub search_tab: main_config::SearchTab,
pub icons: main_config::Icons,
pub keybindings: KeymapConfig,
pub directories: Directories,
}
Expand All @@ -44,6 +45,7 @@ impl Config {
connection: main_config.connection,
torrents_tab: main_config.torrents_tab,
search_tab: main_config.search_tab,
icons: main_config.icons,
keybindings: keybindings.clone(),
directories,
})
Expand Down
129 changes: 0 additions & 129 deletions rm-config/src/main_config.rs

This file was deleted.

19 changes: 19 additions & 0 deletions rm-config/src/main_config/connection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use serde::Deserialize;
use url::Url;

#[derive(Deserialize)]
pub struct Connection {
pub username: Option<String>,
pub password: Option<String>,
pub url: Url,
#[serde(default = "default_refresh")]
pub torrents_refresh: u64,
#[serde(default = "default_refresh")]
pub stats_refresh: u64,
#[serde(default = "default_refresh")]
pub free_space_refresh: u64,
}

fn default_refresh() -> u64 {
5
}
33 changes: 33 additions & 0 deletions rm-config/src/main_config/general.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use ratatui::style::Color;
use serde::Deserialize;

#[derive(Deserialize)]
pub struct General {
#[serde(default)]
pub auto_hide: bool,
#[serde(default = "default_accent_color")]
pub accent_color: Color,
#[serde(default = "default_beginner_mode")]
pub beginner_mode: bool,
#[serde(default)]
pub headers_hide: bool,
}

impl Default for General {
fn default() -> Self {
Self {
auto_hide: false,
accent_color: default_accent_color(),
beginner_mode: default_beginner_mode(),
headers_hide: false,
}
}
}

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

fn default_beginner_mode() -> bool {
true
}
Loading
Loading