From e136fbe8ab80d505e5340cd2131bd2ffdb93eeae Mon Sep 17 00:00:00 2001 From: Ryan Aidan Date: Sun, 23 Jun 2024 16:39:15 +0800 Subject: [PATCH 1/2] feat: color directory header in file popup (#31) --- rm-main/src/ui/tabs/torrents/popups/files.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rm-main/src/ui/tabs/torrents/popups/files.rs b/rm-main/src/ui/tabs/torrents/popups/files.rs index 5a9a2ef..0bfce3d 100644 --- a/rm-main/src/ui/tabs/torrents/popups/files.rs +++ b/rm-main/src/ui/tabs/torrents/popups/files.rs @@ -241,7 +241,10 @@ impl Component for FilesPopup { } }; let block = block - .title(Title::from(format!(" {} ", download_dir)).alignment(Alignment::Right)) + .title( + Title::from(format!(" {} ", download_dir).set_style(highlight_style)) + .alignment(Alignment::Right), + ) .title( Title::from(" [ CLOSE ] ".set_style(close_button_style)) .alignment(Alignment::Right) From a3eceda6ce34dd32e16718df5c5262443959cb1a Mon Sep 17 00:00:00 2001 From: Ryan Aidan Date: Tue, 25 Jun 2024 01:55:10 +0800 Subject: [PATCH 2/2] feat: add up/down icon in up/down stat + allow hiding header row (#30) * feat: add upload/download icons + allow hiding header row * feat: hide search tab headers --- rm-config/defaults/config.toml | 3 ++ rm-config/src/lib.rs | 2 ++ rm-main/src/ui/tabs/search.rs | 12 ++++++-- rm-main/src/ui/tabs/torrents/mod.rs | 16 ++++++---- .../ui/tabs/torrents/rustmission_torrent.rs | 24 ++++++++------- rm-main/src/ui/tabs/torrents/table_manager.rs | 29 ++++++++++--------- rm-main/src/utils.rs | 14 +++++++++ 7 files changed, 69 insertions(+), 31 deletions(-) diff --git a/rm-config/defaults/config.toml b/rm-config/defaults/config.toml index 2b3a228..d0f6256 100644 --- a/rm-config/defaults/config.toml +++ b/rm-config/defaults/config.toml @@ -11,6 +11,9 @@ accent_color = "LightMagenta" # a little bit cluttered interface. beginner_mode = true +# If enabled, hides header row of torrents tab +headers_hide = false + [connection] url = "http://CHANGE_ME:9091/transmission/rpc" # REQUIRED! diff --git a/rm-config/src/lib.rs b/rm-config/src/lib.rs index b510760..d6f0f11 100644 --- a/rm-config/src/lib.rs +++ b/rm-config/src/lib.rs @@ -25,6 +25,8 @@ pub struct General { pub accent_color: Color, #[serde(default = "default_beginner_mode")] pub beginner_mode: bool, + #[serde(default)] + pub headers_hide: bool, } fn default_accent_color() -> Color { diff --git a/rm-main/src/ui/tabs/search.rs b/rm-main/src/ui/tabs/search.rs index 927207a..b5a6f2b 100644 --- a/rm-main/src/ui/tabs/search.rs +++ b/rm-main/src/ui/tabs/search.rs @@ -265,9 +265,15 @@ impl Component for SearchTab { .config .general .accent_color); - let table = Table::new(items, widths) - .header(header) - .highlight_style(table_higlight_style); + + let table = { + let table = Table::new(items, widths).highlight_style(table_higlight_style); + if !self.ctx.config.general.headers_hide { + table.header(header) + } else { + table + } + }; f.render_stateful_widget(table, rest, &mut *table_lock.state.borrow_mut()); diff --git a/rm-main/src/ui/tabs/torrents/mod.rs b/rm-main/src/ui/tabs/torrents/mod.rs index 9e83925..b498ffe 100644 --- a/rm-main/src/ui/tabs/torrents/mod.rs +++ b/rm-main/src/ui/tabs/torrents/mod.rs @@ -120,11 +120,17 @@ impl TorrentsTab { .general .accent_color); - let table_widget = Table::new(torrent_rows, table_manager_lock.widths) - .header(Row::new( - table_manager_lock.header().iter().map(|s| s.as_str()), - )) - .highlight_style(highlight_table_style); + let table_widget = { + let table = Table::new(torrent_rows, table_manager_lock.widths) + .highlight_style(highlight_table_style); + if !self.ctx.config.general.headers_hide { + table.header(Row::new( + table_manager_lock.header().iter().map(|s| s.as_str()), + )) + } else { + table + } + }; f.render_stateful_widget( table_widget, diff --git a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs index 19c8cf3..50532c0 100644 --- a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs +++ b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs @@ -5,7 +5,9 @@ use ratatui::{ }; use transmission_rpc::types::{Id, Torrent, TorrentStatus}; -use crate::utils::{bytes_to_human_format, seconds_to_human_format}; +use crate::utils::{ + bytes_to_human_format, download_speed_format, seconds_to_human_format, upload_speed_format, +}; #[derive(Clone)] pub struct RustmissionTorrent { @@ -23,12 +25,13 @@ pub struct RustmissionTorrent { impl RustmissionTorrent { pub fn to_row(&self) -> ratatui::widgets::Row { Row::new([ - self.torrent_name.as_str(), - self.size_when_done.as_str(), - self.progress.as_str(), - self.eta_secs.as_str(), - self.download_speed.as_str(), - self.upload_speed.as_str(), + Line::from(self.torrent_name.as_str()), + Line::from(""), + Line::from(self.size_when_done.as_str()), + Line::from(self.progress.as_str()), + Line::from(self.eta_secs.as_str()), + Line::from(download_speed_format(&self.download_speed)), + Line::from(upload_speed_format(&self.upload_speed)), ]) .style(self.style) } @@ -49,12 +52,13 @@ impl RustmissionTorrent { } Row::new([ - torrent_name_line, + Line::from(torrent_name_line), + Line::from(""), Line::from(self.size_when_done.as_str()), Line::from(self.progress.as_str()), Line::from(self.eta_secs.as_str()), - Line::from(self.download_speed.as_str()), - Line::from(self.upload_speed.as_str()), + Line::from(download_speed_format(&self.download_speed)), + Line::from(upload_speed_format(&self.upload_speed)), ]) } diff --git a/rm-main/src/ui/tabs/torrents/table_manager.rs b/rm-main/src/ui/tabs/torrents/table_manager.rs index 7fc2aad..2d4563f 100644 --- a/rm-main/src/ui/tabs/torrents/table_manager.rs +++ b/rm-main/src/ui/tabs/torrents/table_manager.rs @@ -9,7 +9,7 @@ use super::rustmission_torrent::RustmissionTorrent; pub struct TableManager { ctx: app::Ctx, pub table: GenericTable, - pub widths: [Constraint; 6], + pub widths: [Constraint; 7], pub filter: Arc>>, pub torrents_displaying_no: u16, header: Vec, @@ -26,6 +26,7 @@ impl TableManager { torrents_displaying_no: 0, header: vec![ "Name".to_owned(), + "".to_owned(), "Size".to_owned(), "Progress".to_owned(), "ETA".to_owned(), @@ -99,18 +100,19 @@ impl TableManager { rows } - const fn default_widths() -> [Constraint; 6] { + const fn default_widths() -> [Constraint; 7] { [ Constraint::Max(70), // Name - Constraint::Length(10), // Size - Constraint::Length(10), // Progress - Constraint::Length(10), // ETA - Constraint::Length(10), // Download - Constraint::Length(10), // Upload + Constraint::Length(5), // + Constraint::Length(12), // Size + Constraint::Length(12), // Progress + Constraint::Length(12), // ETA + Constraint::Length(12), // Download + Constraint::Length(12), // Upload ] } - fn header_widths(&self, rows: &[RustmissionTorrent]) -> [Constraint; 6] { + fn header_widths(&self, rows: &[RustmissionTorrent]) -> [Constraint; 7] { if !self.ctx.config.general.auto_hide { return Self::default_widths(); } @@ -122,23 +124,24 @@ impl TableManager { for row in rows { if !row.download_speed.is_empty() { - download_width = 9; + download_width = 11; } if !row.upload_speed.is_empty() { - upload_width = 9; + upload_width = 11; } if !row.progress.is_empty() { - progress_width = 9; + progress_width = 11; } if !row.eta_secs.is_empty() { - eta_width = 9; + eta_width = 11; } } [ Constraint::Max(70), // Name - Constraint::Length(9), // Size + Constraint::Length(5), // + Constraint::Length(11), // Size Constraint::Length(progress_width), // Progress Constraint::Length(eta_width), // ETA Constraint::Length(download_width), // Download diff --git a/rm-main/src/utils.rs b/rm-main/src/utils.rs index 6ef3177..992c984 100644 --- a/rm-main/src/utils.rs +++ b/rm-main/src/utils.rs @@ -61,3 +61,17 @@ pub fn seconds_to_human_format(seconds: i64) -> String { curr_string = format!("{curr_string}{rest}s"); curr_string } + +pub fn download_speed_format(download_speed: &str) -> String { + if download_speed.len() > 0 { + return format!("▼ {}", download_speed); + } + download_speed.to_string() +} + +pub fn upload_speed_format(upload_speed: &str) -> String { + if upload_speed.len() > 0 { + return format!("▲ {}", upload_speed); + } + upload_speed.to_string() +}