Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter label color if config.with_color(false) #61

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,13 @@ impl<'a, S: Span> ReportBuilder<'a, S> {

/// Add a label to the report.
pub fn add_label(&mut self, label: Label<S>) {
self.labels.push(label);
self.add_labels(std::iter::once(label));
}

/// Add multiple labels to the report.
pub fn add_labels<L: IntoIterator<Item = Label<S>>>(&mut self, labels: L) {
self.labels.extend(labels);
let config = &self.config; // This would not be necessary in Rust 2021 edition
self.labels.extend(labels.into_iter().map(|mut label| { label.color = config.filter_color(label.color); label }));
}

/// Add a label to the report.
Expand Down Expand Up @@ -392,6 +393,7 @@ impl Config {
fn margin_color(&self) -> Option<Color> { Some(Color::Fixed(246)).filter(|_| self.color) }
fn unimportant_color(&self) -> Option<Color> { Some(Color::Fixed(249)).filter(|_| self.color) }
fn note_color(&self) -> Option<Color> { Some(Color::Fixed(115)).filter(|_| self.color) }
fn filter_color(&self, color: Option<Color>) -> Option<Color> { color.filter(|_| self.color) }

// Find the character that should be drawn and the number of times it should be drawn for each char
fn char_width(&self, c: char, col: usize) -> (char, usize) {
Expand Down