mirror of
https://gitverse.ru/ot/DownOnSpot
synced 2025-12-18 09:24:17 +00:00
feat: Improve UI by printing errors in a separate queue, on exit and small touch-ups (#101)
This commit is contained in:
parent
4e2905f370
commit
f0a8720853
1 changed files with 70 additions and 26 deletions
96
src/main.rs
96
src/main.rs
|
|
@ -60,10 +60,10 @@ async fn start() {
|
||||||
match default_settings.save().await {
|
match default_settings.save().await {
|
||||||
Ok(path) => {
|
Ok(path) => {
|
||||||
println!(
|
println!(
|
||||||
"{}{}",
|
"{}{}",
|
||||||
"..but default settings have been created successfully. Edit them and run the program again.\nFind the settings file at: ".green(),
|
"..but default settings have been created successfully. Edit them and run the program again.\nFind the settings file at: ".green(),
|
||||||
path.to_string_lossy()
|
path.to_string_lossy()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!(
|
println!(
|
||||||
|
|
@ -155,6 +155,7 @@ async fn start() {
|
||||||
let mut download_states =
|
let mut download_states =
|
||||||
vec![DownloadState::None; downloader.get_downloads().await.len()];
|
vec![DownloadState::None; downloader.get_downloads().await.len()];
|
||||||
let mut messages = vec![];
|
let mut messages = vec![];
|
||||||
|
let mut errors = vec![];
|
||||||
|
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
print!("\x1b[2J\x1b[1;1H");
|
print!("\x1b[2J\x1b[1;1H");
|
||||||
|
|
@ -162,6 +163,7 @@ async fn start() {
|
||||||
|
|
||||||
let mut num_completed = 0;
|
let mut num_completed = 0;
|
||||||
let mut num_err = 0;
|
let mut num_err = 0;
|
||||||
|
let mut num_skipped = 0;
|
||||||
let mut num_downloading = 0;
|
let mut num_downloading = 0;
|
||||||
let mut num_waiting = 0;
|
let mut num_waiting = 0;
|
||||||
|
|
||||||
|
|
@ -180,19 +182,28 @@ async fn start() {
|
||||||
DownloadState::Downloading(_, _) => (),
|
DownloadState::Downloading(_, _) => (),
|
||||||
DownloadState::Post => (),
|
DownloadState::Post => (),
|
||||||
DownloadState::Done => messages.push(format!(
|
DownloadState::Done => messages.push(format!(
|
||||||
"{time_elapsed: >5} | {}: {}",
|
" {} | {}: {}",
|
||||||
|
secs_to_hrs_min_sec(time_elapsed as i32),
|
||||||
"Downloaded".green(),
|
"Downloaded".green(),
|
||||||
download.title
|
download.title
|
||||||
)),
|
)),
|
||||||
DownloadState::Error(e) => messages.push(format!(
|
DownloadState::Error(e) => {
|
||||||
"{time_elapsed: >5} | {}: {}",
|
let msg = format!(
|
||||||
|
" {} | {}: {}",
|
||||||
|
secs_to_hrs_min_sec(time_elapsed as i32),
|
||||||
|
if e == &SpotifyError::AlreadyDownloaded {
|
||||||
|
e.to_string().yellow()
|
||||||
|
} else {
|
||||||
|
e.to_string().red()
|
||||||
|
},
|
||||||
|
download.title
|
||||||
|
);
|
||||||
if e == &SpotifyError::AlreadyDownloaded {
|
if e == &SpotifyError::AlreadyDownloaded {
|
||||||
e.to_string().yellow()
|
messages.push(msg);
|
||||||
} else {
|
} else {
|
||||||
e.to_string().red()
|
errors.push(msg);
|
||||||
},
|
}
|
||||||
download.title
|
}
|
||||||
)),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,8 +228,13 @@ async fn start() {
|
||||||
num_waiting += 1;
|
num_waiting += 1;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
DownloadState::Error(_) => {
|
DownloadState::Error(e) => {
|
||||||
num_err += 1;
|
if e == &SpotifyError::AlreadyDownloaded {
|
||||||
|
num_skipped += 1;
|
||||||
|
} else {
|
||||||
|
num_err += 1;
|
||||||
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
DownloadState::Done => {
|
DownloadState::Done => {
|
||||||
|
|
@ -231,16 +247,19 @@ async fn start() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while messages.len() > 8 {
|
while messages.len() > 10 {
|
||||||
messages.remove(0);
|
messages.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(" {bold}\x1b[0;34m- DownOnSpot v{VERSION} -\x1b[0m{bold_off}\n");
|
println!(" {bold}\x1b[0;34m- DownOnSpot v{VERSION} -\x1b[0m{bold_off}\n");
|
||||||
|
|
||||||
println!("Time elapsed: {}", secs_to_min_sec(time_elapsed as i32));
|
println!(
|
||||||
|
"Time elapsed: {}",
|
||||||
|
secs_to_hrs_min_sec(time_elapsed as i32)
|
||||||
|
);
|
||||||
println!(
|
println!(
|
||||||
"Time remaining: {}\n",
|
"Time remaining: {}\n",
|
||||||
secs_to_min_sec(
|
secs_to_hrs_min_sec(
|
||||||
(time_elapsed as f32
|
(time_elapsed as f32
|
||||||
/ (progress_sum + num_completed as f32 + num_err as f32)
|
/ (progress_sum + num_completed as f32 + num_err as f32)
|
||||||
* (num_waiting as f32 + num_downloading as f32 - progress_sum))
|
* (num_waiting as f32 + num_downloading as f32 - progress_sum))
|
||||||
|
|
@ -249,25 +268,40 @@ async fn start() {
|
||||||
);
|
);
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
" {bold}{} {}{bold_off}",
|
" {bold} {} {}{bold_off}",
|
||||||
"Time".underline(),
|
"Time".underline(),
|
||||||
"Event".underline()
|
"Event".underline()
|
||||||
);
|
);
|
||||||
for message in &messages {
|
for message in messages.iter().rev() {
|
||||||
println!("{}", message);
|
println!("{}", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !errors.is_empty() {
|
||||||
|
println!(
|
||||||
|
"\n {bold} {} {}{bold_off}",
|
||||||
|
"Time".underline(),
|
||||||
|
"Error".underline()
|
||||||
|
);
|
||||||
|
for error in errors.iter().rev().take(5) {
|
||||||
|
println!("{}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("\n\n {}", "Current downloads:".underline().bold());
|
println!("\n\n {}", "Current downloads:".underline().bold());
|
||||||
println!("{}", current_download_view);
|
println!("{}", current_download_view);
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"\n {bold}Waiting | {} | {} | Total{bold_off}",
|
"\n{bold}{}|{}|{}|{}| Total{bold_off}",
|
||||||
"Err/Skip".red(),
|
" Waiting ",
|
||||||
"Done".green()
|
" Failed ".red(),
|
||||||
|
" Skipped ".yellow(),
|
||||||
|
" Done ".green()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
" {: <8}| {: <9}| {: <5}| {}",
|
" {: <8}| {: <8}| {: <8}| {: <8}| {}",
|
||||||
num_waiting,
|
num_waiting,
|
||||||
num_err,
|
num_err,
|
||||||
|
num_skipped,
|
||||||
num_completed,
|
num_completed,
|
||||||
download_states.len()
|
download_states.len()
|
||||||
);
|
);
|
||||||
|
|
@ -279,10 +313,18 @@ async fn start() {
|
||||||
|
|
||||||
task::sleep(refresh).await
|
task::sleep(refresh).await
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Finished download(s) in {}.",
|
"Finished download(s) in {}.",
|
||||||
secs_to_min_sec(time_elapsed as i32)
|
secs_to_hrs_min_sec(time_elapsed as i32)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if !errors.is_empty() {
|
||||||
|
println!("\n\n All Errors:");
|
||||||
|
for error in errors {
|
||||||
|
println!("{}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("{} {}", "Handling input failed:".red(), e)
|
error!("{} {}", "Handling input failed:".red(), e)
|
||||||
|
|
@ -290,6 +332,8 @@ async fn start() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn secs_to_min_sec(secs: i32) -> String {
|
fn secs_to_hrs_min_sec(secs: i32) -> String {
|
||||||
format!("{:0>2}m{:0>2}s", secs / 60, secs % 60)
|
format!("{:0>2}:{:0>2}:{:0>2}", secs / 360, secs / 60, secs % 60)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !cargo b --release
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue