diff --git a/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs b/rm-main/src/ui/tabs/torrents/rustmission_torrent.rs index d5b5e6a..cf307e9 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, }; @@ -19,6 +19,7 @@ pub struct RustmissionTorrent { pub upload_speed: String, status: TorrentStatus, pub style: Style, + pub icon_style: Style, pub id: Id, pub download_dir: String, } @@ -26,16 +27,16 @@ pub struct RustmissionTorrent { impl RustmissionTorrent { pub fn to_row(&self) -> ratatui::widgets::Row { Row::new([ - Line::from(self.torrent_name.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(""), - 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)), - Line::from(self.download_dir.as_str()), + 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(download_speed_format(&self.download_speed)).set_style(self.style), + Line::from(upload_speed_format(&self.upload_speed)).set_style(self.style), + Line::from(self.download_dir.as_str()).set_style(self.style), ]) - .style(self.style) } pub fn to_row_with_higlighted_indices( @@ -53,8 +54,11 @@ impl RustmissionTorrent { } } + let icon_line = Line::from(self.status_icon()).set_style(self.icon_style); + Row::new([ - Line::from(torrent_name_line), + icon_line, + torrent_name_line, Line::from(""), Line::from(self.size_when_done.as_str()), Line::from(self.progress.as_str()), @@ -78,6 +82,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 { @@ -116,6 +133,12 @@ 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(), + }; let download_dir = t .download_dir .clone() @@ -130,6 +153,7 @@ impl From<&Torrent> for RustmissionTorrent { upload_speed, status, style, + icon_style, id, download_dir, } diff --git a/rm-main/src/ui/tabs/torrents/table_manager.rs b/rm-main/src/ui/tabs/torrents/table_manager.rs index f340efa..bb7b79f 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; 8], + pub widths: [Constraint; 9], 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(), "".to_owned(), "Size".to_owned(), @@ -101,8 +102,9 @@ impl TableManager { rows } - const fn default_widths() -> [Constraint; 8] { + const fn default_widths() -> [Constraint; 9] { [ + Constraint::Length(1), // State Constraint::Max(70), // Name Constraint::Length(5), // Constraint::Length(12), // Size @@ -114,7 +116,7 @@ impl TableManager { ] } - fn header_widths(&self, rows: &[RustmissionTorrent]) -> [Constraint; 8] { + fn header_widths(&self, rows: &[RustmissionTorrent]) -> [Constraint; 9] { if !self.ctx.config.general.auto_hide { return Self::default_widths(); } @@ -141,6 +143,7 @@ impl TableManager { } [ + Constraint::Length(1), Constraint::Max(70), // Name Constraint::Length(5), // Constraint::Length(11), // Size