Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion examples/256_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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} ")));
}
8 changes: 4 additions & 4 deletions examples/gradient_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
"{}",
Expand Down
2 changes: 1 addition & 1 deletion examples/hyperlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fn main() {
.paint("Link to example.com")
.hyperlink("https://example.com");

println!("{}", link);
println!("{link}");
sleep(sleep_ms);
}
4 changes: 2 additions & 2 deletions examples/may_sleep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub fn parse_cmd_args() -> Option<u16> {
.unwrap_or(String::from("5000u16"))
.parse::<u16>()
.ok()
.and_then(|parsed| {
.map(|parsed| {
skip_next = true;
Some(parsed)
parsed
});
}
_ => {}
Expand Down
5 changes: 1 addition & 4 deletions examples/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Style {
written_anything = true;
#[cfg(feature = "gnu_legacy")]
write!(f, "0")?;
write!(f, "{}", c)?;
write!(f, "{c}")?;
Ok(())
};

Expand Down Expand Up @@ -111,7 +111,7 @@ impl Style {
if self.is_plain() {
Ok(())
} else {
write!(f, "{}", RESET)
write!(f, "{RESET}")
}
}
}
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down
12 changes: 6 additions & 6 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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 {
if written_anything {
fmt.write_str(", ")?
}
written_anything = true;
write!(fmt, "on({:?})", bg)?
write!(fmt, "on({bg:?})")?
}

{
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 7 additions & 27 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")?;
}
}

Expand Down Expand Up @@ -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]
Expand Down
28 changes: 0 additions & 28 deletions src/rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading