Skip to content

Commit

Permalink
fix more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jun 21, 2024
1 parent cdf92c0 commit 47f08e0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
9 changes: 2 additions & 7 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@ use crate::ThemeCharacters;
use crate::ThemeStyles;

/// Settings to control the color format used for graphical rendering.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
pub enum RgbColors {
/// Use RGB colors even if the terminal does not support them
Always,
/// Use RGB colors instead of ANSI if the terminal supports RGB
Preferred,
/// Always use ANSI, regardless of terminal support for RGB
#[default]
Never,
}

impl Default for RgbColors {
fn default() -> RgbColors {
RgbColors::Never
}
}

/**
Create a custom [`MietteHandler`] from options.
Expand Down
24 changes: 8 additions & 16 deletions src/handlers/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl GraphicalReportHandler {

// If there was no header, remove the leading newline
let inner = inner.trim_start_matches('\n');
writeln!(f, "{}", self.wrap(&inner, opts))?;
writeln!(f, "{}", self.wrap(inner, opts))?;
}
ErrorKind::StdError(err) => {
writeln!(f, "{}", self.wrap(&err.to_string(), opts))?;
Expand Down Expand Up @@ -667,7 +667,7 @@ impl GraphicalReportHandler {
f,
max_gutter,
line,
&labels,
labels,
LabelRenderMode::SingleLine,
)?;

Expand All @@ -683,7 +683,7 @@ impl GraphicalReportHandler {
f,
max_gutter,
line,
&labels,
labels,
LabelRenderMode::MultiLineFirst,
)?;

Expand All @@ -701,7 +701,7 @@ impl GraphicalReportHandler {
f,
max_gutter,
line,
&labels,
labels,
LabelRenderMode::MultiLineRest,
)?;
self.render_multi_line_end_single(
Expand All @@ -714,13 +714,7 @@ impl GraphicalReportHandler {
}
} else {
// gutter _again_
self.render_highlight_gutter(
f,
max_gutter,
line,
&labels,
LabelRenderMode::SingleLine,
)?;
self.render_highlight_gutter(f, max_gutter, line, labels, LabelRenderMode::SingleLine)?;
// has no label
writeln!(f, "{}", self.theme.characters.hbar.style(label.style))?;
}
Expand Down Expand Up @@ -894,12 +888,10 @@ impl GraphicalReportHandler {
} else {
result.push_str(opts.initial_indent);
}
} else if line.trim().is_empty() {
result.push_str(trimmed_indent);
} else {
if line.trim().is_empty() {
result.push_str(trimmed_indent);
} else {
result.push_str(opts.subsequent_indent);
}
result.push_str(opts.subsequent_indent);
}
result.push_str(line);
}
Expand Down
7 changes: 4 additions & 3 deletions src/highlighters/syntect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::Path;

// all syntect imports are explicitly qualified, but their paths are shortened for convenience
#[allow(clippy::module_inception)]
mod syntect {
pub(super) use syntect::{
highlighting::{
Expand Down Expand Up @@ -96,7 +97,7 @@ impl SyntectHighlighter {
}
// finally, attempt to guess syntax based on first line
return self.syntax_set.find_syntax_by_first_line(
&std::str::from_utf8(contents.data())
std::str::from_utf8(contents.data())
.ok()?
.split('\n')
.next()?,
Expand All @@ -116,13 +117,13 @@ pub(crate) struct SyntectHighlighterState<'h> {

impl<'h> HighlighterState for SyntectHighlighterState<'h> {
fn highlight_line<'s>(&mut self, line: &'s str) -> Vec<Styled<&'s str>> {
if let Ok(ops) = self.parse_state.parse_line(line, &self.syntax_set) {
if let Ok(ops) = self.parse_state.parse_line(line, self.syntax_set) {
let use_bg_color = self.use_bg_color;
syntect::HighlightIterator::new(
&mut self.highlight_state,
&ops,
line,
&mut self.highlighter,
&self.highlighter,
)
.map(|(style, str)| (convert_style(style, use_bg_color).style(str)))
.collect()
Expand Down
2 changes: 1 addition & 1 deletion src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn set_panic_hook() {
message = msg.to_string();
}
if let Some(msg) = payload.downcast_ref::<String>() {
message = msg.clone();
message.clone_from(msg);
}
let mut report: Result<()> = Err(Panic(message).into());
if let Some(loc) = info.location() {
Expand Down

0 comments on commit 47f08e0

Please sign in to comment.