clean up console output a little

This commit is contained in:
Dominic 2024-05-25 14:17:07 +02:00
parent 01e0758b6a
commit 1e7f5f95cd
Signed by: msrd0
GPG key ID: AAF7C8430CA3345D
4 changed files with 67 additions and 25 deletions

View file

@ -10,6 +10,7 @@ license = "EPL-2.0"
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
camino = "1.1" camino = "1.1"
console = "0.15"
clap = { version = "4.4", features = ["derive"] } clap = { version = "4.4", features = ["derive"] }
fontconfig = "0.8" fontconfig = "0.8"
harfbuzz_rs = "2.0" harfbuzz_rs = "2.0"

View file

@ -15,6 +15,7 @@ use self::{
}; };
use camino::Utf8PathBuf as PathBuf; use camino::Utf8PathBuf as PathBuf;
use clap::Parser; use clap::Parser;
use console::style;
use rational::Rational; use rational::Rational;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr}; use serde_with::{serde_as, DisplayFromStr};
@ -208,29 +209,39 @@ fn ask(question: impl Display) -> String {
let mut stdout = io::stdout().lock(); let mut stdout = io::stdout().lock();
let mut stdin = io::stdin().lock(); let mut stdin = io::stdin().lock();
writeln!(stdout, "{question}").unwrap(); writeln!(stdout, "{} {question}", style("?").bold().yellow()).unwrap();
let mut line = String::new(); let mut line = String::new();
write!(stdout, "> ").unwrap(); write!(stdout, "{} ", style(">").cyan()).unwrap();
stdout.flush().unwrap(); stdout.flush().unwrap();
stdin.read_line(&mut line).unwrap(); stdin.read_line(&mut line).unwrap();
line.trim().to_owned() 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 stdout = io::stdout().lock();
let mut stdin = io::stdin().lock(); let mut stdin = io::stdin().lock();
writeln!(stdout, "{question}").unwrap();
let mut line = String::new(); let mut line = String::new();
loop { loop {
line.clear(); line.clear();
write!(stdout, "> ").unwrap(); write!(
stdout,
"{} {} ",
style(question).bold().magenta(),
style(">").cyan()
)
.unwrap();
stdout.flush().unwrap(); stdout.flush().unwrap();
stdin.read_line(&mut line).unwrap(); stdin.read_line(&mut line).unwrap();
let line = line.trim(); let line = line.trim();
match parse_time(line) { match parse_time(line) {
Ok(time) => return time, 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:"); print!("I found the following source files:");
for f in &files { for f in &files {
print!(" {f}"); print!(" {}", style(f).bold().yellow());
} }
println!(); println!();
files = ask("Which source files would you like to use? (specify multiple files separated by whitespace)") 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(); 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 // ask the user about start and end times
if !project.progress.asked_start_end { if !project.progress.asked_start_end {
project.source.start = Some(ask_time(format_args!( println!(
"Please take a look at the file {recording} and tell me the first second you want included" "{} What is the first/last second you want included?",
))); style("?").bold().yellow()
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" project.source.start = Some(ask_time("first"));
))); project.source.end = Some(ask_time("last "));
project.progress.asked_start_end = true; project.progress.asked_start_end = true;
fs::write(&project_path, toml::to_string(&project).unwrap().as_bytes()).unwrap(); 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 // ask the user about fast forward times
if !project.progress.asked_fast { if !project.progress.asked_fast {
println!(
"{} Which sections of the video do you want fast-forwarded? (0 to finish)",
style("?").bold().yellow()
);
loop { loop {
let start = ask_time(format_args!( let start = ask_time("from");
"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"
));
if start.seconds == 0 && start.micros == 0 { if start.seconds == 0 && start.micros == 0 {
break; break;
} }
let end = ask_time(format_args!( let end = ask_time("to ");
"Please tell me the last second you want fast-forwarded"
));
project.source.fast.push((start, end)); project.source.fast.push((start, end));
} }
project.progress.asked_fast = true; 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:"); println!(" Videos:");
for v in &videos { for v in &videos {
println!(" -> {v}"); println!(" {} {v}", style("->").bold().cyan());
} }
} }

View file

@ -29,7 +29,7 @@ impl Question {
let line_height = font_size * 6 / 5; let line_height = font_size * 6 / 5;
let padding = font_size / 2; let padding = font_size / 2;
let margin_x = 240; let margin_x = 240;
let margin_y = padding * 3 /2; let margin_y = padding * 3 / 2;
let question_offset = 64; let question_offset = 64;
let question_width = 240; let question_width = 240;

View file

@ -13,6 +13,7 @@ use crate::{
}; };
use anyhow::{bail, Context}; use anyhow::{bail, Context};
use camino::{Utf8Path as Path, Utf8PathBuf as PathBuf}; use camino::{Utf8Path as Path, Utf8PathBuf as PathBuf};
use console::style;
use std::{ use std::{
borrow::Cow, borrow::Cow,
collections::VecDeque, collections::VecDeque,
@ -227,7 +228,13 @@ impl<'a> Renderer<'a> {
} }
drop(file); 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 = let source_sample_rate =
ffprobe_audio("stream=sample_rate", &recording_txt)?.parse()?; ffprobe_audio("stream=sample_rate", &recording_txt)?.parse()?;
let recording_mkv = self.recording_mkv(); let recording_mkv = self.recording_mkv();
@ -261,7 +268,12 @@ impl<'a> Renderer<'a> {
}); });
let metadata = project.source.metadata.as_ref().unwrap(); 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 // render intro to svg then mp4
let intro_svg = self.target.join("intro.svg"); let intro_svg = self.target.join("intro.svg");
@ -508,7 +520,13 @@ impl<'a> Renderer<'a> {
) -> anyhow::Result<PathBuf> { ) -> anyhow::Result<PathBuf> {
let input = self.video_file_output(); let input = self.video_file_output();
let output = self.video_file_res(res); 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 { let mut ffmpeg = Ffmpeg::new(FfmpegOutput {
video_bitrate: Some(res.bitrate()), video_bitrate: Some(res.bitrate()),