From a0195e66852970e3f0ffe731a587921b40f2941b Mon Sep 17 00:00:00 2001 From: jaudiger Date: Fri, 17 May 2024 17:37:30 +0200 Subject: [PATCH] examples: run clippy and fix issues Signed-off-by: jaudiger --- examples/256_colors.rs | 2 +- examples/basic_colors.rs | 5 ++++- examples/gradient_colors.rs | 8 ++++---- examples/hyperlink.rs | 2 +- examples/may_sleep/mod.rs | 6 +++--- examples/title.rs | 5 +---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/256_colors.rs b/examples/256_colors.rs index d64ece8..8afe6ac 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/basic_colors.rs b/examples/basic_colors.rs index a446a19..7dd692e 100644 --- a/examples/basic_colors.rs +++ b/examples/basic_colors.rs @@ -1,4 +1,7 @@ -use nu_ansi_term::{Color::*, Style}; +use nu_ansi_term::{ + Color::{Black, Blue, Cyan, Green, Purple, Red, White, Yellow}, + Style, +}; // This example prints out the 16 basic colors. 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..2003ad1 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 }); } _ => {} @@ -29,7 +29,7 @@ pub fn parse_cmd_args() -> Option { pub fn sleep(sleep_ms: Option) { if let Some(sleep_ms) = sleep_ms { - let sleep_ms = std::time::Duration::from_millis(sleep_ms as u64); + let sleep_ms = std::time::Duration::from_millis(u64::from(sleep_ms)); std::thread::sleep(sleep_ms); } } 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