From 1e7f5f95cd26bb5fc766d732629ec06175394995 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 25 May 2024 14:17:07 +0200 Subject: [PATCH] clean up console output a little --- Cargo.toml | 1 + src/main.rs | 65 ++++++++++++++++++++++++++++++++--------------- src/question.rs | 2 +- src/render/mod.rs | 24 ++++++++++++++--- 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0faaa6c..d73faad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ license = "EPL-2.0" [dependencies] anyhow = "1.0" camino = "1.1" +console = "0.15" clap = { version = "4.4", features = ["derive"] } fontconfig = "0.8" harfbuzz_rs = "2.0" diff --git a/src/main.rs b/src/main.rs index af93579..4a82515 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ use self::{ }; use camino::Utf8PathBuf as PathBuf; use clap::Parser; +use console::style; use rational::Rational; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; @@ -208,29 +209,39 @@ fn ask(question: impl Display) -> String { let mut stdout = io::stdout().lock(); let mut stdin = io::stdin().lock(); - writeln!(stdout, "{question}").unwrap(); + writeln!(stdout, "{} {question}", style("?").bold().yellow()).unwrap(); let mut line = String::new(); - write!(stdout, "> ").unwrap(); + write!(stdout, "{} ", style(">").cyan()).unwrap(); stdout.flush().unwrap(); stdin.read_line(&mut line).unwrap(); line.trim().to_owned() } -fn ask_time(question: impl Display) -> Time { +fn ask_time(question: impl Display + Copy) -> Time { let mut stdout = io::stdout().lock(); let mut stdin = io::stdin().lock(); - writeln!(stdout, "{question}").unwrap(); let mut line = String::new(); loop { line.clear(); - write!(stdout, "> ").unwrap(); + write!( + stdout, + "{} {} ", + style(question).bold().magenta(), + style(">").cyan() + ) + .unwrap(); stdout.flush().unwrap(); stdin.read_line(&mut line).unwrap(); let line = line.trim(); match parse_time(line) { Ok(time) => return time, - Err(err) => writeln!(stdout, "Invalid Input {line:?}: {err}").unwrap() + Err(err) => writeln!( + stdout, + "{} {line:?}: {err}", + style("Invalid Input").bold().red() + ) + .unwrap() } } } @@ -274,7 +285,7 @@ fn main() { print!("I found the following source files:"); for f in &files { - print!(" {f}"); + print!(" {}", style(f).bold().yellow()); } println!(); files = ask("Which source files would you like to use? (specify multiple files separated by whitespace)") @@ -316,14 +327,21 @@ fn main() { fs::write(&project_path, toml::to_string(&project).unwrap().as_bytes()).unwrap(); } + println!(); + println!( + " {} Preprocessed video: {}", + style("==>").bold().cyan(), + style(recording).bold().yellow() + ); + // ask the user about start and end times if !project.progress.asked_start_end { - project.source.start = Some(ask_time(format_args!( - "Please take a look at the file {recording} and tell me the first second you want included" - ))); - project.source.end = Some(ask_time(format_args!( - "Please take a look at the file {recording} and tell me the last second you want included" - ))); + println!( + "{} What is the first/last second you want included?", + style("?").bold().yellow() + ); + project.source.start = Some(ask_time("first")); + project.source.end = Some(ask_time("last ")); project.progress.asked_start_end = true; fs::write(&project_path, toml::to_string(&project).unwrap().as_bytes()).unwrap(); @@ -331,16 +349,16 @@ fn main() { // ask the user about fast forward times if !project.progress.asked_fast { + println!( + "{} Which sections of the video do you want fast-forwarded? (0 to finish)", + style("?").bold().yellow() + ); loop { - let start = ask_time(format_args!( - "Please take a look at the file {recording} and tell me the first second you want fast-forwarded. You may reply with `0` if there are no more fast-forward sections" - )); + let start = ask_time("from"); if start.seconds == 0 && start.micros == 0 { break; } - let end = ask_time(format_args!( - "Please tell me the last second you want fast-forwarded" - )); + let end = ask_time("to "); project.source.fast.push((start, end)); } project.progress.asked_fast = true; @@ -380,9 +398,14 @@ fn main() { } } - println!("\x1B[1m ==> DONE :)\x1B[0m"); + println!(); + println!( + " {} {}", + style("==>").bold().cyan(), + style("DONE :)").bold() + ); println!(" Videos:"); for v in &videos { - println!(" -> {v}"); + println!(" {} {v}", style("->").bold().cyan()); } } diff --git a/src/question.rs b/src/question.rs index f38a8b5..daf25bb 100644 --- a/src/question.rs +++ b/src/question.rs @@ -29,7 +29,7 @@ impl Question { let line_height = font_size * 6 / 5; let padding = font_size / 2; let margin_x = 240; - let margin_y = padding * 3 /2; + let margin_y = padding * 3 / 2; let question_offset = 64; let question_width = 240; diff --git a/src/render/mod.rs b/src/render/mod.rs index 012ff2c..bd22aff 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -13,6 +13,7 @@ use crate::{ }; use anyhow::{bail, Context}; use camino::{Utf8Path as Path, Utf8PathBuf as PathBuf}; +use console::style; use std::{ borrow::Cow, collections::VecDeque, @@ -227,7 +228,13 @@ impl<'a> Renderer<'a> { } drop(file); - println!("\x1B[1m ==> Concatenating Video and Normalising Audio ...\x1B[0m"); + println!(); + println!( + " {} {}", + style("==>").bold().cyan(), + style("Concatenating Video and Normalising Audio ...").bold() + ); + let source_sample_rate = ffprobe_audio("stream=sample_rate", &recording_txt)?.parse()?; let recording_mkv = self.recording_mkv(); @@ -261,7 +268,12 @@ impl<'a> Renderer<'a> { }); let metadata = project.source.metadata.as_ref().unwrap(); - println!("\x1B[1m ==> Preparing assets ...\x1B[0m"); + println!(); + println!( + " {} {}", + style("==>").bold().cyan(), + style("Preparing assets ...").bold() + ); // render intro to svg then mp4 let intro_svg = self.target.join("intro.svg"); @@ -508,7 +520,13 @@ impl<'a> Renderer<'a> { ) -> anyhow::Result { let input = self.video_file_output(); let output = self.video_file_res(res); - println!("\x1B[1m ==> Rescaling to {}p\x1B[0m", res.height()); + + println!(); + println!( + " {} {}", + style("==>").bold().cyan(), + style(format!("Rescaling to {}p", res.height())).bold() + ); let mut ffmpeg = Ffmpeg::new(FfmpegOutput { video_bitrate: Some(res.bitrate()),