Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: torrent status icons #38

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions rm-main/src/ui/tabs/torrents/rustmission_torrent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ratatui::{
style::{Style, Stylize},
style::{Style, Styled, Stylize},
text::{Line, Span},
widgets::Row,
};
Expand All @@ -19,23 +19,24 @@ pub struct RustmissionTorrent {
pub upload_speed: String,
status: TorrentStatus,
pub style: Style,
pub icon_style: Style,
pub id: Id,
pub download_dir: String,
}

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(
Expand All @@ -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()),
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand All @@ -130,6 +153,7 @@ impl From<&Torrent> for RustmissionTorrent {
upload_speed,
status,
style,
icon_style,
id,
download_dir,
}
Expand Down
9 changes: 6 additions & 3 deletions rm-main/src/ui/tabs/torrents/table_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::rustmission_torrent::RustmissionTorrent;
pub struct TableManager {
ctx: app::Ctx,
pub table: GenericTable<RustmissionTorrent>,
pub widths: [Constraint; 8],
pub widths: [Constraint; 9],
pub filter: Arc<Mutex<Option<String>>>,
pub torrents_displaying_no: u16,
header: Vec<String>,
Expand All @@ -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(),
Expand Down Expand Up @@ -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), // <padding>
Constraint::Length(12), // Size
Expand All @@ -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();
}
Expand All @@ -141,6 +143,7 @@ impl TableManager {
}

[
Constraint::Length(1),
Constraint::Max(70), // Name
Constraint::Length(5), // <padding>
Constraint::Length(11), // Size
Expand Down