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() +}