mirror of
https://github.com/kristoferssolo/traxor.git
synced 2026-01-14 20:46:14 +00:00
feat: add status-based row colors for torrents
This commit is contained in:
parent
35e6e420ea
commit
ae6f4fd216
@ -10,4 +10,16 @@ pub struct ColorConfig {
|
||||
pub header_foreground: String,
|
||||
#[from_file(default = "blue")]
|
||||
pub info_foreground: String,
|
||||
|
||||
// Status colors
|
||||
#[from_file(default = "cyan")]
|
||||
pub status_downloading: String,
|
||||
#[from_file(default = "white")]
|
||||
pub status_seeding: String,
|
||||
#[from_file(default = "dark_gray")]
|
||||
pub status_stopped: String,
|
||||
#[from_file(default = "yellow")]
|
||||
pub status_verifying: String,
|
||||
#[from_file(default = "light_blue")]
|
||||
pub status_queued: String,
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ use ratatui::{
|
||||
widgets::{Block, BorderType, Borders, Row, Table},
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
use transmission_rpc::types::{Torrent, TorrentGetField};
|
||||
use transmission_rpc::types::{Torrent, TorrentGetField, TorrentStatus};
|
||||
|
||||
pub fn build_table<'a>(
|
||||
torrents: &'a [Torrent],
|
||||
@ -20,7 +20,7 @@ pub fn build_table<'a>(
|
||||
|
||||
let rows = torrents
|
||||
.iter()
|
||||
.map(|t| make_row(t, fields, selected, row_style))
|
||||
.map(|t| make_row(t, fields, selected, row_style, colors))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let widths = fields
|
||||
@ -65,14 +65,33 @@ fn make_row<'a>(
|
||||
fields: &[TorrentGetField],
|
||||
selected: &HashSet<i64>,
|
||||
highlight: Style,
|
||||
colors: &ColorConfig,
|
||||
) -> Row<'a> {
|
||||
let status_style = status_style(torrent.status, colors);
|
||||
|
||||
let cells = fields.iter().map(|&field| {
|
||||
if let Some(id) = torrent.id
|
||||
&& selected.contains(&id)
|
||||
{
|
||||
return field.value(torrent).set_style(highlight);
|
||||
}
|
||||
field.value(torrent).into()
|
||||
field.value(torrent).set_style(status_style)
|
||||
});
|
||||
Row::new(cells)
|
||||
}
|
||||
|
||||
fn status_style(status: Option<TorrentStatus>, colors: &ColorConfig) -> Style {
|
||||
let color = match status {
|
||||
Some(TorrentStatus::Downloading) => &colors.status_downloading,
|
||||
Some(TorrentStatus::Seeding) => &colors.status_seeding,
|
||||
Some(TorrentStatus::Stopped) => &colors.status_stopped,
|
||||
Some(TorrentStatus::Verifying) => &colors.status_verifying,
|
||||
Some(
|
||||
TorrentStatus::QueuedToDownload
|
||||
| TorrentStatus::QueuedToSeed
|
||||
| TorrentStatus::QueuedToVerify,
|
||||
) => &colors.status_queued,
|
||||
None => &colors.info_foreground,
|
||||
};
|
||||
Style::default().fg(to_color(color))
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user