From a721d7f0bec228a591b897632db6137682fcdcd2 Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Mon, 25 Aug 2025 17:04:15 -0700 Subject: [PATCH] Resolve new clippy warnings --- examples/256_colors.rs | 2 +- examples/gradient_colors.rs | 8 ++++---- examples/hyperlink.rs | 2 +- examples/may_sleep/mod.rs | 4 ++-- examples/title.rs | 5 +---- src/ansi.rs | 12 ++++++------ src/debug.rs | 12 ++++++------ src/display.rs | 34 +++++++--------------------------- src/rgb.rs | 28 ---------------------------- 9 files changed, 28 insertions(+), 79 deletions(-) diff --git a/examples/256_colors.rs b/examples/256_colors.rs index d64ece8..9069bcf 100644 --- a/examples/256_colors.rs +++ b/examples/256_colors.rs @@ -70,5 +70,5 @@ fn main() { fn glow(c: u8, light_bg: bool) { let base = if light_bg { Color::Black } else { Color::White }; let style = base.on(Color::Fixed(c)); - print!("{}", style.paint(&format!(" {:3} ", c))); + print!("{}", style.paint(format!(" {c:3} "))); } diff --git a/examples/gradient_colors.rs b/examples/gradient_colors.rs index 7ca2bbb..df3d355 100644 --- a/examples/gradient_colors.rs +++ b/examples/gradient_colors.rs @@ -25,13 +25,13 @@ fn main() { let gradient3 = gradient.reverse(); let build_fg = gradient.build(text, TargetGround::Foreground); - println!("{}", build_fg); + println!("{build_fg}"); let build_bg = gradient.build(text, TargetGround::Background); - println!("{}", build_bg); + println!("{build_bg}"); let bgt = build_all_gradient_text(text, gradient, gradient2); - println!("{}", bgt); + println!("{bgt}"); let bgt2 = build_all_gradient_text(text, gradient, gradient3); - println!("{}", bgt2); + println!("{bgt2}"); println!( "{}", diff --git a/examples/hyperlink.rs b/examples/hyperlink.rs index abb284c..a0cf48d 100644 --- a/examples/hyperlink.rs +++ b/examples/hyperlink.rs @@ -12,6 +12,6 @@ fn main() { .paint("Link to example.com") .hyperlink("https://example.com"); - println!("{}", link); + println!("{link}"); sleep(sleep_ms); } diff --git a/examples/may_sleep/mod.rs b/examples/may_sleep/mod.rs index 04724d4..1ff27ad 100644 --- a/examples/may_sleep/mod.rs +++ b/examples/may_sleep/mod.rs @@ -15,9 +15,9 @@ pub fn parse_cmd_args() -> Option { .unwrap_or(String::from("5000u16")) .parse::() .ok() - .and_then(|parsed| { + .map(|parsed| { skip_next = true; - Some(parsed) + parsed }); } _ => {} diff --git a/examples/title.rs b/examples/title.rs index c043d87..855efa9 100644 --- a/examples/title.rs +++ b/examples/title.rs @@ -8,10 +8,7 @@ fn main() { let sleep_ms = parse_cmd_args(); let title = AnsiGenericString::title("My Title"); - println!( - "{}Terminal title set for the next {:?} milliseconds", - title, sleep_ms - ); + println!("{title}Terminal title set for the next {sleep_ms:?} milliseconds"); // sleep because often prompts change this before you can see // the results diff --git a/src/ansi.rs b/src/ansi.rs index 6f46dee..ae89713 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -31,7 +31,7 @@ impl Style { written_anything = true; #[cfg(feature = "gnu_legacy")] write!(f, "0")?; - write!(f, "{}", c)?; + write!(f, "{c}")?; Ok(()) }; @@ -111,7 +111,7 @@ impl Style { if self.is_plain() { Ok(()) } else { - write!(f, "{}", RESET) + write!(f, "{RESET}") } } } @@ -131,8 +131,8 @@ impl Color { Color::Magenta => write!(f, "35"), Color::Cyan => write!(f, "36"), Color::White => write!(f, "37"), - Color::Fixed(num) => write!(f, "38;5;{}", num), - Color::Rgb(r, g, b) => write!(f, "38;2;{};{};{}", r, g, b), + Color::Fixed(num) => write!(f, "38;5;{num}"), + Color::Rgb(r, g, b) => write!(f, "38;2;{r};{g};{b}"), Color::Default => write!(f, "39"), Color::DarkGray => write!(f, "90"), Color::LightRed => write!(f, "91"), @@ -157,8 +157,8 @@ impl Color { Color::Magenta => write!(f, "45"), Color::Cyan => write!(f, "46"), Color::White => write!(f, "47"), - Color::Fixed(num) => write!(f, "48;5;{}", num), - Color::Rgb(r, g, b) => write!(f, "48;2;{};{};{}", r, g, b), + Color::Fixed(num) => write!(f, "48;5;{num}"), + Color::Rgb(r, g, b) => write!(f, "48;2;{r};{g};{b}"), Color::Default => write!(f, "49"), Color::DarkGray => write!(f, "100"), Color::LightRed => write!(f, "101"), diff --git a/src/debug.rs b/src/debug.rs index 6997bab..6fd41e1 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -37,7 +37,7 @@ impl fmt::Debug for Style { fmt.write_str(", ")? } written_anything = true; - write!(fmt, "fg({:?})", fg)? + write!(fmt, "fg({fg:?})")? } if let Some(bg) = self.background { @@ -45,7 +45,7 @@ impl fmt::Debug for Style { fmt.write_str(", ")? } written_anything = true; - write!(fmt, "on({:?})", bg)? + write!(fmt, "on({bg:?})")? } { @@ -133,10 +133,10 @@ mod test { }"; let style = Blue.bold(); - let style_fmt_debug = format!("{:?}", style); - let style_fmt_pretty = format!("{:#?}", style); - println!("style_fmt_debug:\n{}", style_fmt_debug); - println!("style_fmt_pretty:\n{}", style_fmt_pretty); + let style_fmt_debug = format!("{style:?}"); + let style_fmt_pretty = format!("{style:#?}"); + println!("style_fmt_debug:\n{style_fmt_debug}"); + println!("style_fmt_pretty:\n{style_fmt_pretty}"); assert_eq!(expected_debug, style_fmt_debug); assert_eq!(expected_pretty_repat, style_fmt_pretty); diff --git a/src/display.rs b/src/display.rs index cfc1aec..fa5009c 100644 --- a/src/display.rs +++ b/src/display.rs @@ -372,7 +372,7 @@ where // have already been written by this point. if let Some(last) = self.0.last() { if !last.style.is_plain() { - write!(w, "{}", RESET)?; + write!(w, "{RESET}")?; } } @@ -409,47 +409,27 @@ mod tests { assert!(joined.starts_with("\x1B[32mBefore is Green. \x1B[0m")); assert!( joined.ends_with(unstyled_s.as_str()), - "{:?} does not end with {:?}", - joined, - unstyled_s + "{joined:?} does not end with {unstyled_s:?}" ); // check that RESET does not follow unstyled when appending styled let joined = AnsiStrings(&[unstyled.clone(), after_g.clone()]).to_string(); assert!( joined.starts_with(unstyled_s.as_str()), - "{:?} does not start with {:?}", - joined, - unstyled_s + "{joined:?} does not start with {unstyled_s:?}" ); assert!(joined.ends_with("\x1B[32m After is Green.\x1B[0m")); // does not introduce spurious SGR codes (reset or otherwise) adjacent // to plain strings let joined = AnsiStrings(&[unstyled.clone()]).to_string(); - assert!( - !joined.contains("\x1B["), - "{:?} does contain \\x1B[", - joined - ); + assert!(!joined.contains("\x1B["), "{joined:?} does contain \\x1B["); let joined = AnsiStrings(&[before.clone(), unstyled.clone()]).to_string(); - assert!( - !joined.contains("\x1B["), - "{:?} does contain \\x1B[", - joined - ); + assert!(!joined.contains("\x1B["), "{joined:?} does contain \\x1B["); let joined = AnsiStrings(&[before.clone(), unstyled.clone(), after.clone()]).to_string(); - assert!( - !joined.contains("\x1B["), - "{:?} does contain \\x1B[", - joined - ); + assert!(!joined.contains("\x1B["), "{joined:?} does contain \\x1B["); let joined = AnsiStrings(&[unstyled.clone(), after.clone()]).to_string(); - assert!( - !joined.contains("\x1B["), - "{:?} does contain \\x1B[", - joined - ); + assert!(!joined.contains("\x1B["), "{joined:?} does contain \\x1B["); } #[test] diff --git a/src/rgb.rs b/src/rgb.rs index c1634dc..410bd47 100644 --- a/src/rgb.rs +++ b/src/rgb.rs @@ -66,34 +66,6 @@ impl Rgb { Self::from_f32(x, x, x) } - /// Creates a new [Rgb] color from a [HSL] color - // pub fn from_hsl(hsl: HSL) -> Self { - // if hsl.s == 0.0 { - // return Self::gray_f32(hsl.l); - // } - - // let q = if hsl.l < 0.5 { - // hsl.l * (1.0 + hsl.s) - // } else { - // hsl.l + hsl.s - hsl.l * hsl.s - // }; - // let p = 2.0 * hsl.l - q; - // let h2c = |t: f32| { - // let t = t.clamp(0.0, 1.0); - // if 6.0 * t < 1.0 { - // p + 6.0 * (q - p) * t - // } else if t < 0.5 { - // q - // } else if 1.0 < 1.5 * t { - // p + 6.0 * (q - p) * (1.0 / 1.5 - t) - // } else { - // p - // } - // }; - - // Self::from_f32(h2c(hsl.h + 1.0 / 3.0), h2c(hsl.h), h2c(hsl.h - 1.0 / 3.0)) - // } - /// Computes the linear interpolation between `self` and `other` for `t` pub fn lerp(&self, other: Self, t: f32) -> Self { let t = t.clamp(0.0, 1.0);