chore: UI tweaks

This commit is contained in:
Michel de Graaf
2025-11-12 14:52:31 +01:00
parent 406def31d9
commit 69a044b1fa
6 changed files with 502 additions and 168 deletions
+25 -2
View File
@@ -1,12 +1,27 @@
use ratatui::{
style::Style,
text::{Line, Span},
};
use crate::ui::COLOR_PRIMARY;
pub fn format_bytes(bytes: u64) -> String {
let mb = bytes as f64 / 1_048_576.0;
format!("{:.1} MB", mb)
}
pub fn format_bytes_progress(downloaded: u64, total: u64) -> String {
pub fn format_bytes_progress(downloaded: u64, total: u64) -> Line<'static> {
let downloaded_mb = downloaded as f64 / 1_048_576.0;
let total_mb = total as f64 / 1_048_576.0;
format!("{:.1}/{:.1} MB", downloaded_mb, total_mb)
let mut spans = vec![];
spans.push(Span::styled(
format!("{:.1}/{:.1}", downloaded_mb, total_mb),
Style::default().fg(COLOR_PRIMARY),
));
spans.push(Span::raw(" MB"));
Line::from(spans)
}
pub fn format_speed(speed_bytes_per_sec: f64) -> String {
@@ -19,3 +34,11 @@ pub fn get_bitrate(
) -> Option<u32> {
attribs.get(&0).copied()
}
// Spinner animation chars
const SPINNER_CHARS: [&str; 10] =
["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
pub fn get_spinner_char(state: usize) -> &'static str {
SPINNER_CHARS[state % SPINNER_CHARS.len()]
}