From 7166c44220a5652d76cac6432621e70684398da7 Mon Sep 17 00:00:00 2001 From: aidanaden Date: Mon, 24 Jun 2024 09:05:43 +0800 Subject: [PATCH 1/5] feat: tick icon for completed torrnets --- rm-main/src/ui/tabs/torrents/rustmission_torrent.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs index 19c8cf3..e74dd23 100644 --- a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs +++ b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs @@ -82,7 +82,7 @@ impl From<&Torrent> for RustmissionTorrent { let size_when_done = bytes_to_human_format(t.size_when_done.expect("field requested")); let progress = match t.percent_done.expect("field requested") { - done if done == 1f32 => String::default(), + done if done == 1f32 => "✓".to_string(), percent => format!("{:.2}%", percent * 100f32), }; From 487ef0716ff5674d9a63fb7b68482c9e9fb3002f Mon Sep 17 00:00:00 2001 From: aidanaden Date: Tue, 25 Jun 2024 01:03:45 +0800 Subject: [PATCH 2/5] feat: add status icons --- .../src/ui/tabs/torrents/rustmission_torrent.rs | 17 ++++++++++++++++- rm-main/src/ui/tabs/torrents/table_manager.rs | 9 ++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs index e74dd23..f464ff1 100644 --- a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs +++ b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs @@ -23,6 +23,7 @@ pub struct RustmissionTorrent { impl RustmissionTorrent { pub fn to_row(&self) -> ratatui::widgets::Row { Row::new([ + self.status_icon(), self.torrent_name.as_str(), self.size_when_done.as_str(), self.progress.as_str(), @@ -49,6 +50,7 @@ impl RustmissionTorrent { } Row::new([ + Line::from(self.status_icon()), torrent_name_line, Line::from(self.size_when_done.as_str()), Line::from(self.progress.as_str()), @@ -71,6 +73,19 @@ impl RustmissionTorrent { self.status = new_status; } + + fn status_icon(&self) -> &str { + // ▼ + match self.status() { + TorrentStatus::Stopped => "⏸", + TorrentStatus::Verifying => "↺", + TorrentStatus::Seeding => "▲", + TorrentStatus::Downloading => "▼", + TorrentStatus::QueuedToSeed => "", + TorrentStatus::QueuedToVerify => "", + TorrentStatus::QueuedToDownload => "", + } + } } impl From<&Torrent> for RustmissionTorrent { @@ -82,7 +97,7 @@ impl From<&Torrent> for RustmissionTorrent { let size_when_done = bytes_to_human_format(t.size_when_done.expect("field requested")); let progress = match t.percent_done.expect("field requested") { - done if done == 1f32 => "✓".to_string(), + done if done == 1f32 => String::default(), percent => format!("{:.2}%", percent * 100f32), }; diff --git a/rm-main/src/ui/tabs/torrents/table_manager.rs b/rm-main/src/ui/tabs/torrents/table_manager.rs index 7fc2aad..078879a 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, @@ -25,6 +25,7 @@ impl TableManager { filter: Arc::new(Mutex::new(None)), torrents_displaying_no: 0, header: vec![ + " ".to_owned(), "Name".to_owned(), "Size".to_owned(), "Progress".to_owned(), @@ -99,8 +100,9 @@ impl TableManager { rows } - const fn default_widths() -> [Constraint; 6] { + const fn default_widths() -> [Constraint; 7] { [ + Constraint::Length(1), // State Constraint::Max(70), // Name Constraint::Length(10), // Size Constraint::Length(10), // Progress @@ -110,7 +112,7 @@ impl TableManager { ] } - 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(); } @@ -137,6 +139,7 @@ impl TableManager { } [ + Constraint::Length(1), Constraint::Max(70), // Name Constraint::Length(9), // Size Constraint::Length(progress_width), // Progress From e6c124f2b7f7f63429cfe3ababbc7d567f470713 Mon Sep 17 00:00:00 2001 From: aidanaden Date: Tue, 25 Jun 2024 01:04:45 +0800 Subject: [PATCH 3/5] chore: comment --- rm-main/src/ui/tabs/torrents/rustmission_torrent.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs index f464ff1..4fdb32d 100644 --- a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs +++ b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs @@ -75,7 +75,6 @@ impl RustmissionTorrent { } fn status_icon(&self) -> &str { - // ▼ match self.status() { TorrentStatus::Stopped => "⏸", TorrentStatus::Verifying => "↺", From 0536fd000616d938921f689555e7adeae50d5cb2 Mon Sep 17 00:00:00 2001 From: aidanaden Date: Tue, 25 Jun 2024 02:55:27 +0800 Subject: [PATCH 4/5] feat: colored state icons --- .../ui/tabs/torrents/rustmission_torrent.rs | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs index 4fdb32d..4340559 100644 --- a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs +++ b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs @@ -1,5 +1,5 @@ use ratatui::{ - style::{Style, Stylize}, + style::{Style, Styled, Stylize}, text::{Line, Span}, widgets::Row, }; @@ -17,21 +17,21 @@ pub struct RustmissionTorrent { pub upload_speed: String, status: TorrentStatus, pub style: Style, + pub icon_style: Style, pub id: Id, } impl RustmissionTorrent { pub fn to_row(&self) -> ratatui::widgets::Row { Row::new([ - self.status_icon(), - 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.status_icon()).set_style(self.icon_style), + Line::from(self.torrent_name.as_str()).set_style(self.style), + Line::from(self.size_when_done.as_str()).set_style(self.style), + Line::from(self.progress.as_str()).set_style(self.style), + Line::from(self.eta_secs.as_str()).set_style(self.style), + Line::from(self.download_speed.as_str()).set_style(self.style), + Line::from(self.upload_speed.as_str()).set_style(self.style), ]) - .style(self.style) } pub fn to_row_with_higlighted_indices( @@ -49,8 +49,10 @@ impl RustmissionTorrent { } } + let icon_line = Line::from(self.status_icon()).set_style(self.icon_style); + Row::new([ - Line::from(self.status_icon()), + icon_line, torrent_name_line, Line::from(self.size_when_done.as_str()), Line::from(self.progress.as_str()), @@ -75,6 +77,7 @@ impl RustmissionTorrent { } fn status_icon(&self) -> &str { + // ▼ match self.status() { TorrentStatus::Stopped => "⏸", TorrentStatus::Verifying => "↺", @@ -123,6 +126,13 @@ impl From<&Torrent> for RustmissionTorrent { _ => Style::default(), }; + let icon_style = match status { + TorrentStatus::Stopped => Style::default().dark_gray(), + TorrentStatus::Seeding => Style::default().blue(), + TorrentStatus::Downloading => Style::default().green(), + _ => Style::default(), + }; + Self { torrent_name, size_when_done, @@ -132,6 +142,7 @@ impl From<&Torrent> for RustmissionTorrent { upload_speed, status, style, + icon_style, id, } } From a37b2283540d38cc8b6299203c5b194e6dcd0b88 Mon Sep 17 00:00:00 2001 From: aidanaden Date: Tue, 25 Jun 2024 03:02:16 +0800 Subject: [PATCH 5/5] fix: type errors --- rm-main/src/ui/tabs/torrents/table_manager.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rm-main/src/ui/tabs/torrents/table_manager.rs b/rm-main/src/ui/tabs/torrents/table_manager.rs index 3d9078b..f324002 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; 7], + pub widths: [Constraint; 8], pub filter: Arc>>, pub torrents_displaying_no: u16, header: Vec, @@ -101,7 +101,7 @@ impl TableManager { rows } - const fn default_widths() -> [Constraint; 7] { + const fn default_widths() -> [Constraint; 8] { [ Constraint::Length(1), // State Constraint::Max(70), // Name @@ -114,7 +114,7 @@ impl TableManager { ] } - fn header_widths(&self, rows: &[RustmissionTorrent]) -> [Constraint; 7] { + fn header_widths(&self, rows: &[RustmissionTorrent]) -> [Constraint; 8] { if !self.ctx.config.general.auto_hide { return Self::default_widths(); }