Skip to content

Commit

Permalink
auto hide empty columns
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski committed Apr 11, 2024
1 parent 0ab06e9 commit 6f2c119
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 288 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rm-main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ futures = "0.3"

# TUI
crossterm = { version = "0.27", features = ["event-stream"] }
ratatui = "0.26"
ratatui = "0.27.0-alpha.4"
ratatui-macros = "0.2"
tui-input = "0.8"
42 changes: 23 additions & 19 deletions rm-main/src/transmission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use transmission_rpc::types::TorrentAction as RPCAction;
use crate::{
action::{Action, TorrentAction},
app,
ui::{bytes_to_human_format, popup::ErrorPopup},
ui::{bytes_to_human_format, popup::ErrorPopup, tabs::torrents::torrents::TableManager},
};

pub async fn stats_fetch(ctx: app::Ctx, stats: Arc<std::sync::Mutex<Option<SessionStats>>>) {
Expand All @@ -36,7 +36,7 @@ pub async fn stats_fetch(ctx: app::Ctx, stats: Arc<std::sync::Mutex<Option<Sessi
pub async fn torrent_fetch(
ctx: app::Ctx,
torrents: Arc<std::sync::Mutex<Vec<Torrent>>>,
rows: Arc<std::sync::Mutex<Vec<RustmissionTorrent>>>,
table_manager: Arc<std::sync::Mutex<TableManager>>,
) {
loop {
let fields = vec![
Expand All @@ -61,10 +61,12 @@ pub async fn torrent_fetch(
.unwrap();

let new_torrents = rpc_response.arguments.torrents;
*rows.lock().unwrap() = new_torrents
.iter()
.map(|torrent| torrent_to_row(torrent))
.collect();
table_manager.lock().unwrap().set_new_rows(
new_torrents
.iter()
.map(|torrent| torrent_to_row(torrent))
.collect(),
);
*torrents.lock().unwrap() = new_torrents;
ctx.send_action(Action::Render);

Expand All @@ -73,22 +75,18 @@ pub async fn torrent_fetch(
}

pub struct RustmissionTorrent {
torrent_name: String,
size_when_done: String,
progress: String,
eta_secs: String,
download_speed: String,
upload_speed: String,
status: TorrentStatus,
pub torrent_name: String,
pub size_when_done: String,
pub progress: String,
pub eta_secs: String,
pub download_speed: String,
pub upload_speed: String,
pub status: TorrentStatus,
pub style: Style,
}

impl RustmissionTorrent {
pub fn to_row(&self) -> ratatui::widgets::Row {
let style = match self.status {
TorrentStatus::Stopped => Style::default().dark_gray().italic(),
_ => Style::default(),
};

Row::new([
self.torrent_name.as_str(),
self.size_when_done.as_str(),
Expand All @@ -97,7 +95,7 @@ impl RustmissionTorrent {
self.download_speed.as_str(),
self.upload_speed.as_str(),
])
.style(style)
.style(self.style)
}
}

Expand Down Expand Up @@ -129,6 +127,11 @@ fn torrent_to_row(t: &Torrent) -> RustmissionTorrent {

let status = t.status.expect("field requested");

let style = match status {
TorrentStatus::Stopped => Style::default().dark_gray().italic(),
_ => Style::default(),
};

RustmissionTorrent {
torrent_name,
size_when_done,
Expand All @@ -137,6 +140,7 @@ fn torrent_to_row(t: &Torrent) -> RustmissionTorrent {
download_speed,
upload_speed,
status,
style,
}
}

Expand Down
2 changes: 1 addition & 1 deletion rm-main/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod components;
pub mod popup;
pub mod tabs;

use tabs::torrents::TorrentsTab;
use crate::ui::tabs::torrents::torrents::TorrentsTab;

use crossterm::event::KeyCode;
use ratatui::prelude::*;
Expand Down
220 changes: 0 additions & 220 deletions rm-main/src/ui/tabs/torrents.rs

This file was deleted.

Loading

0 comments on commit 6f2c119

Please sign in to comment.