Skip to content

Commit e6d21f0

Browse files
committed
Handle colors correctly
1 parent 2411bc9 commit e6d21f0

File tree

5 files changed

+19
-72
lines changed

5 files changed

+19
-72
lines changed

β€Žjustfileβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ run:
3434
filter PATTERN:
3535
cargo test {{PATTERN}}
3636

37-
[group: 'misc']
3837
[group: 'misc']
3938
build:
4039
cargo build

β€Žsrc/compile_error.rsβ€Ž

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ impl<'src> CompileError<'src> {
1919
}
2020
}
2121

22-
pub(crate) fn render_compile_error(error: &CompileError) {
23-
use ariadne::{Label, Report, ReportKind, Source};
22+
pub(crate) fn render_compile_error(error: &CompileError, color: Color) {
23+
use ariadne::{Config, Label, Report, ReportKind, Source};
2424

2525
let token = error.token;
2626
let source = Source::from(token.src);
@@ -31,7 +31,8 @@ pub(crate) fn render_compile_error(error: &CompileError) {
3131
let path = format!("{}", token.path.display());
3232
let label = Label::new((&path, start..end));
3333

34-
let report = Report::build(ReportKind::Error, &path, start);
34+
let config = Config::default().with_color(color.stderr().active());
35+
let report = Report::build(ReportKind::Error, &path, start).with_config(config);
3536

3637
let report = match &*error.kind {
3738
CompileErrorKind::AttributeArgumentCountMismatch {
@@ -49,27 +50,17 @@ pub(crate) fn render_compile_error(error: &CompileError) {
4950
};
5051

5152
report
52-
.with_code("E01")
5353
.with_message("Attribute argument count mismatch")
5454
.with_label(label.with_message(label_msg))
5555
.with_note(note)
5656
.finish()
5757
}
58-
/*
59-
CompileErrorKind::BacktickShebang => todo!(),
60-
CompileErrorKind::CircularRecipeDependency { recipe, circle } => todo!(),
61-
CompileErrorKind::CircularVariableDependency { variable, circle } => todo!(),
62-
CompileErrorKind::DependencyArgumentCountMismatch { dependency, found, min, max } => todo!(),
63-
CompileErrorKind::Redefinition { first, first_type, name, second_type } => todo!(),
64-
*/
6558
CompileErrorKind::DuplicateAttribute { attribute, first } => {
6659
let original_label = source
6760
.line(*first)
6861
.map(|line| Label::new((&path, line.span())).with_message("original"));
6962

70-
let mut report = report
71-
.with_code("E02")
72-
.with_message(format!("Duplicate attribute `{attribute}`"));
63+
let mut report = report.with_message(format!("Duplicate attribute `{attribute}`"));
7364
if let Some(original) = original_label {
7465
report = report.with_label(original);
7566
}
@@ -78,50 +69,7 @@ pub(crate) fn render_compile_error(error: &CompileError) {
7869
_ => {
7970
let message = format!("{error}");
8071
report.with_message(message).with_label(label).finish()
81-
} /*
82-
CompileErrorKind::DuplicateParameter { recipe, parameter } => todo!(),
83-
CompileErrorKind::DuplicateSet { setting, first } => todo!(),
84-
CompileErrorKind::DuplicateVariable { variable } => todo!(),
85-
CompileErrorKind::DuplicateUnexport { variable } => todo!(),
86-
CompileErrorKind::ExpectedKeyword { expected, found } => todo!(),
87-
CompileErrorKind::ExportUnexported { variable } => todo!(),
88-
CompileErrorKind::ExtraLeadingWhitespace => todo!(),
89-
CompileErrorKind::ExtraneousAttributes { count } => todo!(),
90-
CompileErrorKind::FunctionArgumentCountMismatch { function, found, expected } => todo!(),
91-
CompileErrorKind::Include => todo!(),
92-
CompileErrorKind::InconsistentLeadingWhitespace { expected, found } => todo!(),
93-
CompileErrorKind::Internal { message } => todo!(),
94-
CompileErrorKind::InvalidAttribute { item_kind, item_name, attribute } => todo!(),
95-
CompileErrorKind::InvalidEscapeSequence { character } => todo!(),
96-
CompileErrorKind::MismatchedClosingDelimiter { close, open, open_line } => todo!(),
97-
CompileErrorKind::MixedLeadingWhitespace { whitespace } => todo!(),
98-
CompileErrorKind::ParameterFollowsVariadicParameter { parameter } => todo!(),
99-
CompileErrorKind::ParsingRecursionDepthExceeded => todo!(),
100-
CompileErrorKind::RequiredParameterFollowsDefaultParameter { parameter } => todo!(),
101-
CompileErrorKind::ShebangAndScriptAttribute { recipe } => todo!(),
102-
CompileErrorKind::ShellExpansion { err } => todo!(),
103-
CompileErrorKind::UndefinedVariable { variable } => todo!(),
104-
CompileErrorKind::UnexpectedCharacter { expected } => todo!(),
105-
CompileErrorKind::UnexpectedClosingDelimiter { close } => todo!(),
106-
CompileErrorKind::UnexpectedEndOfToken { expected } => todo!(),
107-
CompileErrorKind::UnexpectedToken { expected, found } => todo!(),
108-
CompileErrorKind::UnicodeEscapeCharacter { character } => todo!(),
109-
CompileErrorKind::UnicodeEscapeDelimiter { character } => todo!(),
110-
CompileErrorKind::UnicodeEscapeEmpty => todo!(),
111-
CompileErrorKind::UnicodeEscapeLength { hex } => todo!(),
112-
CompileErrorKind::UnicodeEscapeRange { hex } => todo!(),
113-
CompileErrorKind::UnicodeEscapeUnterminated => todo!(),
114-
CompileErrorKind::UnknownAliasTarget { alias, target } => todo!(),
115-
CompileErrorKind::UnknownAttribute { attribute } => todo!(),
116-
CompileErrorKind::UnknownDependency { recipe, unknown } => todo!(),
117-
CompileErrorKind::UnknownFunction { function } => todo!(),
118-
CompileErrorKind::UnknownSetting { setting } => todo!(),
119-
CompileErrorKind::UnknownStartOfToken => todo!(),
120-
CompileErrorKind::UnpairedCarriageReturn => todo!(),
121-
CompileErrorKind::UnterminatedBacktick => todo!(),
122-
CompileErrorKind::UnterminatedInterpolation => todo!(),
123-
CompileErrorKind::UnterminatedString => todo!(),
124-
*/
72+
}
12573
};
12674

12775
report.eprint((&path, source)).unwrap();

β€Žsrc/error.rsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl ColorDisplay for Error<'_> {
506506

507507
pub(crate) fn render_error(error: &Error, color: Color) {
508508
match error {
509-
Error::Compile { compile_error } => compile_error::render_compile_error(compile_error),
509+
Error::Compile { compile_error } => compile_error::render_compile_error(compile_error, color),
510510
_ => eprintln!("{}", error.color_display(color.stderr())),
511511
}
512512
}

β€Žtests/string.rsβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,11 @@ fn unicode_escape_non_hex() {
481481
.status(1)
482482
.stderr(
483483
r#"
484-
error: expected hex digit [0-9A-Fa-f] but found `o`
485-
β€”β€”β–Ά justfile:1:6
486-
β”‚
487-
1 β”‚ x := "\u{foo}"
488-
β”‚ ^^^^^^^^^
484+
Error: expected hex digit [0-9A-Fa-f] but found `o`
485+
╭─[justfile:1:6]
486+
β”‚
487+
1 β”‚ x := "\u{foo}"
488+
───╯
489489
"#,
490490
)
491491
.run();

β€Žtests/subsequents.rsβ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ test! {
4545
justfile: "
4646
foo: && foo
4747
",
48-
stderr: "
49-
error: Recipe `foo` depends on itself
50-
β€”β€”β–Ά justfile:1:9
51-
β”‚
52-
1 β”‚ foo: && foo
53-
β”‚ ^^^
54-
",
48+
stderr:
49+
"Error: Recipe `foo` depends on itself
50+
╭─[justfile:1:9]
51+
β”‚
52+
1 β”‚ foo: && foo
53+
───╯
54+
",
5555
status: EXIT_FAILURE,
5656
}
5757

0 commit comments

Comments
Β (0)