Skip to content

Commit

Permalink
add serde defaults, add missing icons
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski committed Aug 15, 2024
1 parent 808c6c7 commit 11094e0
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 43 deletions.
1 change: 1 addition & 0 deletions rm-config/defaults/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ verifying = "󰑓"
loading = "󱥸"
pause = "󰏤"
idle = "󱗼"
magnifying_glass = ""
provider_disabled = "󰪎"
provider_category_general = ""
provider_category_anime = "󰎁"
155 changes: 134 additions & 21 deletions rm-config/src/main_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl Default for TorrentsTab {

#[derive(Deserialize)]
pub struct SearchTab {
#[serde(default)]
pub providers: Vec<WhichProvider>,
}

Expand All @@ -102,53 +103,165 @@ impl Default for SearchTab {

#[derive(Deserialize)]
pub struct Icons {
#[serde(default = "default_upload")]
pub upload: String,
#[serde(default = "default_download")]
pub download: String,
#[serde(default = "default_arrow_left")]
pub arrow_left: String,
#[serde(default = "default_arrow_right")]
pub arrow_right: String,
#[serde(default = "default_arrow_up")]
pub arrow_up: String,
#[serde(default = "default_arrow_down")]
pub arrow_down: String,
#[serde(default = "default_triangle_right")]
pub triangle_right: String,
#[serde(default = "default_triangle_down")]
pub triangle_down: String,
#[serde(default = "default_file")]
pub file: String,
#[serde(default = "default_disk")]
pub disk: String,
#[serde(default = "default_help")]
pub help: String,
#[serde(default = "default_success")]
pub success: String,
#[serde(default = "default_failure")]
pub failure: String,
#[serde(default = "default_searching")]
pub searching: String,
#[serde(default = "default_verifying")]
pub verifying: String,
#[serde(default = "default_loading")]
pub loading: String,
#[serde(default = "default_pause")]
pub pause: String,
#[serde(default = "default_idle")]
pub idle: String,
#[serde(default = "default_magnifying_glass")]
pub magnifying_glass: String,
#[serde(default = "default_provider_disabled")]
pub provider_disabled: String,
#[serde(default = "default_provider_category_general")]
pub provider_category_general: String,
#[serde(default = "default_provider_category_anime")]
pub provider_category_anime: String,
}

fn default_upload() -> String {
"".into()
}

fn default_download() -> String {
"".into()
}

fn default_arrow_left() -> String {
"".into()
}

fn default_arrow_right() -> String {
"".into()
}

fn default_arrow_up() -> String {
"".into()
}

fn default_arrow_down() -> String {
"".into()
}

fn default_triangle_right() -> String {
"▶".into()
}

fn default_triangle_down() -> String {
"▼".into()
}

fn default_file() -> String {
"".into()
}

fn default_disk() -> String {
"󰋊".into()
}

fn default_help() -> String {
"".into()
}

fn default_success() -> String {
"".into()
}

fn default_failure() -> String {
"".into()
}

fn default_searching() -> String {
"".into()
}

fn default_verifying() -> String {
"󰑓".into()
}

fn default_loading() -> String {
"󱥸".into()
}

fn default_pause() -> String {
"󰏤".into()
}

fn default_idle() -> String {
"󱗼".into()
}

fn default_magnifying_glass() -> String {
"".into()
}

fn default_provider_disabled() -> String {
"󰪎".into()
}

fn default_provider_category_general() -> String {
"".into()
}

fn default_provider_category_anime() -> String {
"󰎁".into()
}

impl Default for Icons {
fn default() -> Self {
Self {
upload: "".into(),
download: "".into(),
arrow_left: "".into(),
arrow_right: "".into(),
arrow_up: "".into(),
arrow_down: "".into(),
triangle_right: "▶".into(),
triangle_down: "▼".into(),
file: "".into(),
disk: "󰋊".into(),
help: "󰘥".into(),
success: "".into(),
failure: "".into(),
searching: "".into(),
verifying: "󰑓".into(),
loading: "󱥸".into(),
pause: "󰏤".into(),
idle: "󱗼".into(),
provider_disabled: "󰪎".into(),
provider_category_general: "".into(),
provider_category_anime: "󰎁".into(),
upload: default_upload(),
download: default_download(),
arrow_left: default_arrow_left(),
arrow_right: default_arrow_right(),
arrow_up: default_arrow_up(),
arrow_down: default_arrow_down(),
triangle_right: default_triangle_right(),
triangle_down: default_triangle_down(),
file: default_file(),
disk: default_disk(),
help: default_help(),
success: default_success(),
failure: default_failure(),
searching: default_searching(),
verifying: default_verifying(),
loading: default_loading(),
pause: default_pause(),
idle: default_idle(),
magnifying_glass: default_magnifying_glass(),
provider_disabled: default_provider_disabled(),
provider_category_general: default_provider_category_general(),
provider_category_anime: default_provider_category_anime(),
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions rm-main/src/tui/tabs/torrents/rustmission_torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use ratatui::{
use rm_config::CONFIG;
use rm_shared::{
header::Header,
utils::{
bytes_to_human_format, download_speed_format, seconds_to_human_format, upload_speed_format,
},
utils::{bytes_to_human_format, seconds_to_human_format},
};
use transmission_rpc::types::{ErrorType, Id, Torrent, TorrentStatus};

Expand Down Expand Up @@ -295,3 +293,17 @@ fn time_to_line<'a>(time: NaiveDateTime) -> Line<'a> {
Line::from(time.format("%y|%m|%d %H:%M").to_string())
}
}

fn download_speed_format(download_speed: &str) -> String {
if !download_speed.is_empty() {
return format!("{} {}", CONFIG.icons.download, download_speed);
}
download_speed.to_string()
}

fn upload_speed_format(upload_speed: &str) -> String {
if !upload_speed.is_empty() {
return format!("{} {}", CONFIG.icons.upload, upload_speed);
}
upload_speed.to_string()
}
8 changes: 3 additions & 5 deletions rm-main/src/tui/tabs/torrents/tasks/default.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ratatui::prelude::*;
use rm_config::CONFIG;
use rm_shared::action::Action;

use crate::tui::components::Component;

Expand All @@ -14,11 +15,8 @@ impl DefaultBar {
impl Component for DefaultBar {
fn render(&mut self, f: &mut ratatui::Frame<'_>, rect: Rect) {
if CONFIG.general.beginner_mode {
if let Some(keys) = CONFIG
.keybindings
.get_keys_for_action(rm_shared::action::Action::ShowHelp)
{
f.render_widget(format!("󰘥 {keys} - help"), rect)
if let Some(keys) = CONFIG.keybindings.get_keys_for_action(Action::ShowHelp) {
f.render_widget(format!("{} {keys} - help", CONFIG.icons.help), rect)
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions rm-shared/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,6 @@ pub fn seconds_to_human_format(seconds: i64) -> String {
curr_string
}

pub fn download_speed_format(download_speed: &str) -> String {
if !download_speed.is_empty() {
return format!(" {}", download_speed);
}
download_speed.to_string()
}

pub fn upload_speed_format(upload_speed: &str) -> String {
if !upload_speed.is_empty() {
return format!(" {}", upload_speed);
}
upload_speed.to_string()
}

pub fn truncated_str(str: &str, max: usize) -> String {
if str.chars().count() < max {
str.to_string()
Expand Down

0 comments on commit 11094e0

Please sign in to comment.