Skip to content

Commit

Permalink
feat: better cli output
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Apr 9, 2024
1 parent e0be24b commit d0f88be
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions three-style-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use clap::{
builder::styling::{AnsiColor, Color, Style},
Parser, Subcommand,
};
use std::str::FromStr;
use std::{
str::FromStr,
time::{Duration, Instant},
};
use three_style_lib::{
commutator::{
finder::{find_corner_commutators, find_edge_commutators},
Expand Down Expand Up @@ -30,13 +33,15 @@ impl Cli {
depth,
}) = self.command
{
let start = Instant::now();
let commutators = match (corners, edges) {
(Some(corners), None) => search_corner_commutators(corners, gen, depth)?,
(None, Some(edges)) => search_edge_commutators(edges, gen, depth)?,
_ => unreachable!(),
};
let end = Instant::now();

print_commutators(commutators);
print_commutators(commutators, end - start);
}

Ok(())
Expand Down Expand Up @@ -104,24 +109,35 @@ fn search_edge_commutators(
Ok(results)
}

fn print_commutators(commutators: Vec<Commutator>) {
fn print_commutators(commutators: Vec<Commutator>, duration: Duration) {
let duration = duration.as_secs_f32();
let count = commutators.len();
let bold = Style::new().bold();
let cyan = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)));
let green = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Green)));

for comm in commutators {
let style = Style::new().bold();
println!(
"{style}{}{style:#}: {} ({})",
"{bold}{}{bold:#}: {} {cyan}({}){cyan:#}",
comm,
comm.expand(),
comm.expand().len()
);
}

if count > 0 {
println!("\nFound {green}{count}{green:#} results in {duration:.2}s.");
} else {
println!("No result found.");
}
}

fn print_error(error: String) {
let style = Style::new()
.bold()
.fg_color(Some(Color::Ansi(AnsiColor::Red)));

println!("{style}error{style:#}: {}", error);
eprintln!("{style}error{style:#}: {}", error);
}

fn main() {
Expand Down

0 comments on commit d0f88be

Please sign in to comment.