style: move transfer stats to right side of status bar

This commit is contained in:
Kristofers Solo 2026-01-01 04:30:49 +02:00
parent ae6f4fd216
commit e4fcc70c30
Signed by: kristoferssolo
GPG Key ID: 8687F2D3EEE6F0ED

View File

@ -1,4 +1,7 @@
use crate::app::{App, InputMode}; use crate::app::{
App, InputMode,
utils::{filesize::FileSize, netspeed::NetSpeed},
};
use ratatui::{ use ratatui::{
prelude::*, prelude::*,
text::Span, text::Span,
@ -6,13 +9,26 @@ use ratatui::{
}; };
pub fn render(frame: &mut Frame, app: &App, area: Rect) { pub fn render(frame: &mut Frame, app: &App, area: Rect) {
let torrents = &app.torrents.torrents;
// Aggregate stats
let total_down_speed: i64 = torrents.iter().filter_map(|t| t.rate_download).sum();
let total_up_speed: i64 = torrents.iter().filter_map(|t| t.rate_upload).sum();
let total_downloaded: u64 = torrents.iter().filter_map(|t| t.downloaded_ever).sum();
let total_uploaded: i64 = torrents.iter().filter_map(|t| t.uploaded_ever).sum();
let down_speed = NetSpeed::new(total_down_speed.unsigned_abs());
let up_speed = NetSpeed::new(total_up_speed.unsigned_abs());
let downloaded = FileSize::new(total_downloaded);
let uploaded = FileSize::new(total_uploaded.unsigned_abs());
let total = app.torrents.len(); let total = app.torrents.len();
let selected_count = app.torrents.selected.len(); let selected_count = app.torrents.selected.len();
let left = if selected_count > 0 { let count_info = if selected_count > 0 {
format!(" {selected_count}/{total} selected") format!("{selected_count}/{total}")
} else { } else {
format!(" {total} torrents") format!("{total}")
}; };
let mode_text = match app.input_mode { let mode_text = match app.input_mode {
@ -23,12 +39,14 @@ pub fn render(frame: &mut Frame, app: &App, area: Rect) {
}; };
let keybinds = match app.input_mode { let keybinds = match app.input_mode {
InputMode::None => "q Quit │ ? Help │ ↑↓ Navigate │ Space Select │ Enter Toggle", InputMode::None => "? Help",
InputMode::Move | InputMode::Rename => "Enter Submit │ Esc Cancel │ Tab Complete", InputMode::Move | InputMode::Rename => "Enter Submit │ Esc Cancel",
InputMode::ConfirmDelete(_) => "y Confirm │ n Cancel", InputMode::ConfirmDelete(_) => "y Confirm │ n Cancel",
}; };
let right = format!("{keybinds} "); let left = format!(" {keybinds}");
let right =
format!("{count_info} │ ↓ {down_speed}{up_speed} │ D: {downloaded} U: {uploaded} ");
let available_width = area.width.saturating_sub(2) as usize; let available_width = area.width.saturating_sub(2) as usize;
let left_len = left.chars().count(); let left_len = left.chars().count();
@ -37,6 +55,8 @@ pub fn render(frame: &mut Frame, app: &App, area: Rect) {
let content = if left_len + right_len < available_width { let content = if left_len + right_len < available_width {
let padding = available_width.saturating_sub(left_len + right_len); let padding = available_width.saturating_sub(left_len + right_len);
format!("{left}{}{right}", " ".repeat(padding)) format!("{left}{}{right}", " ".repeat(padding))
} else if left_len < available_width {
left
} else { } else {
right right
}; };