summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2023-08-25 22:53:35 +0200
committerGitHub <noreply@github.com>2023-08-25 22:53:35 +0200
commit77967148b6e5b37e862842a2add183c85bc91e4c (patch)
tree3d65d3c5f91e33434abb67b60eaabadea0bb32d5 /src/config.rs
parentd3ec97f86f4a3f1dda40d640e35be708e4c8c98c (diff)
chore: handle rust 1.72 clippy & fmt changes (#5399)
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs106
1 files changed, 52 insertions, 54 deletions
diff --git a/src/config.rs b/src/config.rs
index f778cf310..9ff37f1d8 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -287,64 +287,62 @@ pub fn parse_style_string(
) -> Option<nu_ansi_term::Style> {
style_string
.split_whitespace()
- .fold(Some(nu_ansi_term::Style::new()), |maybe_style, token| {
- maybe_style.and_then(|style| {
- let token = token.to_lowercase();
-
- // Check for FG/BG identifiers and strip them off if appropriate
- // If col_fg is true, color the foreground. If it's false, color the background.
- let (token, col_fg) = if token.as_str().starts_with("fg:") {
- (token.trim_start_matches("fg:").to_owned(), true)
- } else if token.as_str().starts_with("bg:") {
- (token.trim_start_matches("bg:").to_owned(), false)
- } else {
- (token, true) // Bare colors are assumed to color the foreground
- };
-
- match token.as_str() {
- "underline" => Some(style.underline()),
- "bold" => Some(style.bold()),
- "italic" => Some(style.italic()),
- "dimmed" => Some(style.dimmed()),
- "inverted" => Some(style.reverse()),
- "blink" => Some(style.blink()),
- "hidden" => Some(style.hidden()),
- "strikethrough" => Some(style.strikethrough()),
- // When the string is supposed to be a color:
- // Decide if we yield none, reset background or set color.
- color_string => {
- if color_string == "none" && col_fg {
- None // fg:none yields no style.
+ .try_fold(nu_ansi_term::Style::new(), |style, token| {
+ let token = token.to_lowercase();
+
+ // Check for FG/BG identifiers and strip them off if appropriate
+ // If col_fg is true, color the foreground. If it's false, color the background.
+ let (token, col_fg) = if token.as_str().starts_with("fg:") {
+ (token.trim_start_matches("fg:").to_owned(), true)
+ } else if token.as_str().starts_with("bg:") {
+ (token.trim_start_matches("bg:").to_owned(), false)
+ } else {
+ (token, true) // Bare colors are assumed to color the foreground
+ };
+
+ match token.as_str() {
+ "underline" => Some(style.underline()),
+ "bold" => Some(style.bold()),
+ "italic" => Some(style.italic()),
+ "dimmed" => Some(style.dimmed()),
+ "inverted" => Some(style.reverse()),
+ "blink" => Some(style.blink()),
+ "hidden" => Some(style.hidden()),
+ "strikethrough" => Some(style.strikethrough()),
+ // When the string is supposed to be a color:
+ // Decide if we yield none, reset background or set color.
+ color_string => {
+ if color_string == "none" && col_fg {
+ None // fg:none yields no style.
+ } else {
+ // Either bg or valid color or both.
+ let parsed = parse_color_string(
+ color_string,
+ context.and_then(|x| {
+ get_palette(
+ &x.root_config.palettes,
+ x.root_config.palette.as_deref(),
+ )
+ }),
+ );
+ // bg + invalid color = reset the background to default.
+ if !col_fg && parsed.is_none() {
+ let mut new_style = style;
+ new_style.background = Option::None;
+ Some(new_style)
} else {
- // Either bg or valid color or both.
- let parsed = parse_color_string(
- color_string,
- context.and_then(|x| {
- get_palette(
- &x.root_config.palettes,
- x.root_config.palette.as_deref(),
- )
- }),
- );
- // bg + invalid color = reset the background to default.
- if !col_fg && parsed.is_none() {
- let mut new_style = style;
- new_style.background = Option::None;
- Some(new_style)
- } else {
- // Valid color, apply color to either bg or fg
- parsed.map(|ansi_color| {
- if col_fg {
- style.fg(ansi_color)
- } else {
- style.on(ansi_color)
- }
- })
- }
+ // Valid color, apply color to either bg or fg
+ parsed.map(|ansi_color| {
+ if col_fg {
+ style.fg(ansi_color)
+ } else {
+ style.on(ansi_color)
+ }
+ })
}
}
}
- })
+ }
})
}