mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-24 21:53:21 +00:00
fix: cargo lint sorting and color parsing
This commit is contained in:
parent
9692366d12
commit
258005a41a
2 changed files with 14 additions and 22 deletions
|
@ -99,7 +99,6 @@ string_slice = "warn"
|
||||||
string_to_string = "warn"
|
string_to_string = "warn"
|
||||||
unnecessary_self_imports = "warn"
|
unnecessary_self_imports = "warn"
|
||||||
use_self = "warn"
|
use_self = "warn"
|
||||||
string_slice = "warn"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
#! The crate provides a set of optional features that can be enabled in your `cargo.toml` file.
|
#! The crate provides a set of optional features that can be enabled in your `cargo.toml` file.
|
||||||
|
|
|
@ -313,17 +313,20 @@ impl FromStr for Color {
|
||||||
_ => {
|
_ => {
|
||||||
if let Ok(index) = s.parse::<u8>() {
|
if let Ok(index) = s.parse::<u8>() {
|
||||||
Self::Indexed(index)
|
Self::Indexed(index)
|
||||||
} else if let (Ok(r), Ok(g), Ok(b)) = {
|
} else if s.starts_with('#') && s.len() == 7 {
|
||||||
if !s.starts_with('#') || s.len() != 7 {
|
let red = s
|
||||||
return Err(ParseColorError);
|
.get(1..3)
|
||||||
}
|
.and_then(|v| u8::from_str_radix(v, 16).ok())
|
||||||
(
|
.ok_or(ParseColorError)?;
|
||||||
u8::from_str_radix(&s.chars().skip(1).take(2).collect::<String>(), 16),
|
let green = s
|
||||||
u8::from_str_radix(&s.chars().skip(3).take(2).collect::<String>(), 16),
|
.get(3..5)
|
||||||
u8::from_str_radix(&s.chars().skip(5).take(2).collect::<String>(), 16),
|
.and_then(|v| u8::from_str_radix(v, 16).ok())
|
||||||
)
|
.ok_or(ParseColorError)?;
|
||||||
} {
|
let blue = s
|
||||||
Self::Rgb(r, g, b)
|
.get(5..7)
|
||||||
|
.and_then(|v| u8::from_str_radix(v, 16).ok())
|
||||||
|
.ok_or(ParseColorError)?;
|
||||||
|
Self::Rgb(red, green, blue)
|
||||||
} else {
|
} else {
|
||||||
return Err(ParseColorError);
|
return Err(ParseColorError);
|
||||||
}
|
}
|
||||||
|
@ -333,16 +336,6 @@ impl FromStr for Color {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_hex_color(input: &str) -> Option<(u8, u8, u8)> {
|
|
||||||
if !input.starts_with('#') || input.len() != 7 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let r = u8::from_str_radix(input.get(1..3)?, 16).ok()?;
|
|
||||||
let g = u8::from_str_radix(input.get(3..5)?, 16).ok()?;
|
|
||||||
let b = u8::from_str_radix(input.get(5..7)?, 16).ok()?;
|
|
||||||
Some((r, g, b))
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Color {
|
impl fmt::Display for Color {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in a new issue