Skip to content

Commit

Permalink
feat: change spans command to alternate colors
Browse files Browse the repository at this point in the history
  • Loading branch information
grantlemons committed Dec 4, 2024
1 parent ec4c8e7 commit b7138f6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion harper-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,27 @@ fn main() -> anyhow::Result<()> {
let (doc, source) = load_file(&file)?;

let primary_color = Color::Blue;
let secondary_color = Color::Magenta;
let filename = file
.file_name()
.map(|s| s.to_string_lossy().into())
.unwrap_or("<file>".to_string());

let mut report_builder = Report::build(ReportKind::Advice, &filename, 0);
let mut color = primary_color;
for token in doc.tokens() {
report_builder = report_builder.with_label(
Label::new((&filename, token.span.into()))
.with_message(format!("[{}, {})", token.span.start, token.span.end))
.with_color(primary_color),
.with_color(color),
);

// Alternate colors so spans are clear
color = if color == primary_color {
secondary_color
} else {
primary_color
};
}

let report = report_builder.finish();
Expand Down

0 comments on commit b7138f6

Please sign in to comment.