chore: refactor CLI app with new modules for seperation of concerns, reusable components and consistent styling

This commit is contained in:
Michel de Graaf
2025-11-12 02:02:35 +01:00
parent 5a28452c02
commit 5816d9b632
11 changed files with 1075 additions and 1034 deletions
+52
View File
@@ -0,0 +1,52 @@
use soulseek_rs::DownloadStatus;
#[derive(Debug, Clone)]
pub struct FileDownloadState {
pub filename: String,
pub username: String,
pub total_bytes: u64,
pub bytes_downloaded: u64,
pub speed_bytes_per_sec: f64,
pub status: DownloadStatus,
}
impl FileDownloadState {
pub fn new(filename: String, username: String, total_bytes: u64) -> Self {
Self {
filename,
username,
total_bytes,
bytes_downloaded: 0,
speed_bytes_per_sec: 0.0,
status: DownloadStatus::Queued,
}
}
pub fn update_status(&mut self, status: DownloadStatus) {
match &status {
DownloadStatus::InProgress {
bytes_downloaded,
total_bytes,
speed_bytes_per_sec,
} => {
self.bytes_downloaded = *bytes_downloaded;
self.total_bytes = *total_bytes;
self.speed_bytes_per_sec = *speed_bytes_per_sec;
}
DownloadStatus::Completed => {
self.bytes_downloaded = self.total_bytes;
}
_ => {}
}
self.status = status;
}
pub fn is_finished(&self) -> bool {
matches!(
self.status,
DownloadStatus::Completed
| DownloadStatus::Failed
| DownloadStatus::TimedOut
)
}
}
@@ -0,0 +1,9 @@
#[derive(Clone)]
pub struct FileDisplayData {
pub filename: String,
pub size: u64,
pub username: String,
pub speed: u32,
pub slots: u8,
pub bitrate: Option<u32>,
}
+5
View File
@@ -0,0 +1,5 @@
mod download_state;
mod file_display_data;
pub use download_state::FileDownloadState;
pub use file_display_data::FileDisplayData;