removed duplicate code

This commit is contained in:
Anton-4 2024-02-16 15:13:40 +01:00
parent 719e32e0f0
commit 00d1ac0aef
No known key found for this signature in database
GPG key ID: 0971D718C0A9B937
3 changed files with 42 additions and 30 deletions

View file

@ -210,33 +210,7 @@ fn main() -> io::Result<()> {
threading,
) {
Ok((problems, total_time)) => {
println!(
"\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms.",
if problems.errors == 0 {
32 // green
} else {
33 // yellow
},
problems.errors,
if problems.errors == 1 {
"error"
} else {
"errors"
},
if problems.warnings == 0 {
32 // green
} else {
33 // yellow
},
problems.warnings,
if problems.warnings == 1 {
"warning"
} else {
"warnings"
},
total_time.as_millis(),
);
problems.print_to_stdout(total_time);
Ok(problems.exit_code())
}

View file

@ -86,7 +86,10 @@ mod cli_run {
&[],
);
let err = compile_out.stdout.trim();
dbg!(&err);
dbg!("- - - - - - -");
let err = strip_colors(err);
dbg!(&err);
// e.g. "1 error and 0 warnings found in 123 ms."
let (before_first_digit, _) = err.split_at(err.rfind("found in ").unwrap());

View file

@ -6,6 +6,8 @@ use roc_problem::can::Problem;
use roc_region::all::LineInfo;
use roc_solve_problem::TypeError;
use crate::report::ANSI_STYLE_CODES;
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct Problems {
pub fatally_errored: bool,
@ -26,11 +28,11 @@ impl Problems {
}
pub fn print_to_stdout(&self, total_time: std::time::Duration) {
const GREEN: usize = 32;
const YELLOW: usize = 33;
const GREEN: &str = ANSI_STYLE_CODES.green;
const YELLOW: &str = ANSI_STYLE_CODES.yellow;
print!(
"\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms",
"{}{}\x1B[39m {} and {}{}\x1B[39m {} found in {} ms",
match self.errors {
0 => GREEN,
_ => YELLOW,
@ -54,6 +56,39 @@ impl Problems {
}
}
// prints e.g. `1 error and 0 warnings found in 63 ms.`
pub fn print_error_warning_count(
error_count: usize,
warning_count: usize,
total_time: std::time::Duration,
) {
const GREEN: &str = ANSI_STYLE_CODES.green;
const YELLOW: &str = ANSI_STYLE_CODES.yellow;
print!(
"{}{}\x1B[39m {} and {}{}\x1B[39m {} found in {} ms",
match error_count {
0 => GREEN,
_ => YELLOW,
},
error_count,
match error_count {
1 => "error",
_ => "errors",
},
match warning_count {
0 => GREEN,
_ => YELLOW,
},
warning_count,
match warning_count {
1 => "warning",
_ => "warnings",
},
total_time.as_millis()
);
}
pub fn report_problems(
sources: &MutMap<ModuleId, (PathBuf, Box<str>)>,
interns: &Interns,