mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 05:37:35 +00:00
chore: handle rust 1.72 clippy & fmt changes (#5399)
This commit is contained in:
parent
d3ec97f86f
commit
77967148b6
2
build.rs
2
build.rs
@ -22,7 +22,7 @@ fn gen_presets_hook(mut file: &File) -> SdResult<()> {
|
|||||||
println!("cargo:rerun-if-changed=docs/.vuepress/public/presets/toml");
|
println!("cargo:rerun-if-changed=docs/.vuepress/public/presets/toml");
|
||||||
let paths = fs::read_dir("docs/.vuepress/public/presets/toml")?;
|
let paths = fs::read_dir("docs/.vuepress/public/presets/toml")?;
|
||||||
let mut sortedpaths = paths.collect::<io::Result<Vec<_>>>()?;
|
let mut sortedpaths = paths.collect::<io::Result<Vec<_>>>()?;
|
||||||
sortedpaths.sort_by_key(|e| e.path());
|
sortedpaths.sort_by_key(std::fs::DirEntry::path);
|
||||||
|
|
||||||
let mut presets = String::new();
|
let mut presets = String::new();
|
||||||
let mut match_arms = String::new();
|
let mut match_arms = String::new();
|
||||||
|
102
src/config.rs
102
src/config.rs
@ -287,64 +287,62 @@ pub fn parse_style_string(
|
|||||||
) -> Option<nu_ansi_term::Style> {
|
) -> Option<nu_ansi_term::Style> {
|
||||||
style_string
|
style_string
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.fold(Some(nu_ansi_term::Style::new()), |maybe_style, token| {
|
.try_fold(nu_ansi_term::Style::new(), |style, token| {
|
||||||
maybe_style.and_then(|style| {
|
let token = token.to_lowercase();
|
||||||
let token = token.to_lowercase();
|
|
||||||
|
|
||||||
// Check for FG/BG identifiers and strip them off if appropriate
|
// 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.
|
// 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:") {
|
let (token, col_fg) = if token.as_str().starts_with("fg:") {
|
||||||
(token.trim_start_matches("fg:").to_owned(), true)
|
(token.trim_start_matches("fg:").to_owned(), true)
|
||||||
} else if token.as_str().starts_with("bg:") {
|
} else if token.as_str().starts_with("bg:") {
|
||||||
(token.trim_start_matches("bg:").to_owned(), false)
|
(token.trim_start_matches("bg:").to_owned(), false)
|
||||||
} else {
|
} else {
|
||||||
(token, true) // Bare colors are assumed to color the foreground
|
(token, true) // Bare colors are assumed to color the foreground
|
||||||
};
|
};
|
||||||
|
|
||||||
match token.as_str() {
|
match token.as_str() {
|
||||||
"underline" => Some(style.underline()),
|
"underline" => Some(style.underline()),
|
||||||
"bold" => Some(style.bold()),
|
"bold" => Some(style.bold()),
|
||||||
"italic" => Some(style.italic()),
|
"italic" => Some(style.italic()),
|
||||||
"dimmed" => Some(style.dimmed()),
|
"dimmed" => Some(style.dimmed()),
|
||||||
"inverted" => Some(style.reverse()),
|
"inverted" => Some(style.reverse()),
|
||||||
"blink" => Some(style.blink()),
|
"blink" => Some(style.blink()),
|
||||||
"hidden" => Some(style.hidden()),
|
"hidden" => Some(style.hidden()),
|
||||||
"strikethrough" => Some(style.strikethrough()),
|
"strikethrough" => Some(style.strikethrough()),
|
||||||
// When the string is supposed to be a color:
|
// When the string is supposed to be a color:
|
||||||
// Decide if we yield none, reset background or set color.
|
// Decide if we yield none, reset background or set color.
|
||||||
color_string => {
|
color_string => {
|
||||||
if color_string == "none" && col_fg {
|
if color_string == "none" && col_fg {
|
||||||
None // fg:none yields no style.
|
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 {
|
} else {
|
||||||
// Either bg or valid color or both.
|
// Valid color, apply color to either bg or fg
|
||||||
let parsed = parse_color_string(
|
parsed.map(|ansi_color| {
|
||||||
color_string,
|
if col_fg {
|
||||||
context.and_then(|x| {
|
style.fg(ansi_color)
|
||||||
get_palette(
|
} else {
|
||||||
&x.root_config.palettes,
|
style.on(ansi_color)
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,12 +546,12 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_escaped_chars() {
|
fn test_escaped_chars() {
|
||||||
const FORMAT_STR: &str = r#"\\\[\$text\]\(red bold\)"#;
|
const FORMAT_STR: &str = r"\\\[\$text\]\(red bold\)";
|
||||||
|
|
||||||
let formatter = StringFormatter::new(FORMAT_STR).unwrap().map(empty_mapper);
|
let formatter = StringFormatter::new(FORMAT_STR).unwrap().map(empty_mapper);
|
||||||
let result = formatter.parse(None, None).unwrap();
|
let result = formatter.parse(None, None).unwrap();
|
||||||
let mut result_iter = result.iter();
|
let mut result_iter = result.iter();
|
||||||
match_next!(result_iter, r#"\[$text](red bold)"#, None);
|
match_next!(result_iter, r"\[$text](red bold)", None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -37,12 +37,12 @@ pub fn cleanup_log_files<P: AsRef<Path>>(path: P) {
|
|||||||
let log_dir = path.as_ref();
|
let log_dir = path.as_ref();
|
||||||
let Ok(log_files) = fs::read_dir(log_dir) else {
|
let Ok(log_files) = fs::read_dir(log_dir) else {
|
||||||
// Avoid noisily handling errors in this cleanup function.
|
// Avoid noisily handling errors in this cleanup function.
|
||||||
return
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
for file in log_files {
|
for file in log_files {
|
||||||
// Skip files that can't be read.
|
// Skip files that can't be read.
|
||||||
let Ok (file) = file else {
|
let Ok(file) = file else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ where
|
|||||||
strs.into_iter()
|
strs.into_iter()
|
||||||
.chain(std::iter::once(fill.ansi_string(fill_size)))
|
.chain(std::iter::once(fill.ansi_string(fill_size)))
|
||||||
})
|
})
|
||||||
.chain(current.into_iter())
|
.chain(current)
|
||||||
.collect::<Vec<AnsiString>>()
|
.collect::<Vec<AnsiString>>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ fn get_meson_version(context: &Context, config: &PackageConfig) -> Option<String
|
|||||||
.split_ascii_whitespace()
|
.split_ascii_whitespace()
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
|
|
||||||
let re = Regex::new(r#"project\([^())]*,version:'(?P<version>[^']+)'[^())]*\)"#).unwrap();
|
let re = Regex::new(r"project\([^())]*,version:'(?P<version>[^']+)'[^())]*\)").unwrap();
|
||||||
let caps = re.captures(&file_contents)?;
|
let caps = re.captures(&file_contents)?;
|
||||||
|
|
||||||
format_version(&caps["version"], config.version_format)
|
format_version(&caps["version"], config.version_format)
|
||||||
@ -487,12 +487,12 @@ mod tests {
|
|||||||
fn test_extract_nimble_package_version() -> io::Result<()> {
|
fn test_extract_nimble_package_version() -> io::Result<()> {
|
||||||
let config_name = "test_project.nimble";
|
let config_name = "test_project.nimble";
|
||||||
|
|
||||||
let config_content = r##"
|
let config_content = r#"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
author = "Mr. nimble"
|
author = "Mr. nimble"
|
||||||
description = "A new awesome nimble package"
|
description = "A new awesome nimble package"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
"##;
|
"#;
|
||||||
|
|
||||||
let project_dir = create_project_dir()?;
|
let project_dir = create_project_dir()?;
|
||||||
fill_config(&project_dir, config_name, Some(config_content))?;
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
||||||
@ -505,7 +505,7 @@ license = "MIT"
|
|||||||
.cmd(
|
.cmd(
|
||||||
"nimble dump --json",
|
"nimble dump --json",
|
||||||
Some(CommandOutput {
|
Some(CommandOutput {
|
||||||
stdout: r##"
|
stdout: r#"
|
||||||
{
|
{
|
||||||
"name": "test_project.nimble",
|
"name": "test_project.nimble",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
@ -524,7 +524,7 @@ license = "MIT"
|
|||||||
"srcDir": "",
|
"srcDir": "",
|
||||||
"backend": "c"
|
"backend": "c"
|
||||||
}
|
}
|
||||||
"##
|
"#
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
stderr: String::new(),
|
stderr: String::new(),
|
||||||
}),
|
}),
|
||||||
@ -547,12 +547,12 @@ license = "MIT"
|
|||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let config_name = "test_project.nimble";
|
let config_name = "test_project.nimble";
|
||||||
|
|
||||||
let config_content = r##"
|
let config_content = r#"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
author = "Mr. nimble"
|
author = "Mr. nimble"
|
||||||
description = "A new awesome nimble package"
|
description = "A new awesome nimble package"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
"##;
|
"#;
|
||||||
|
|
||||||
let project_dir = create_project_dir()?;
|
let project_dir = create_project_dir()?;
|
||||||
fill_config(&project_dir, config_name, Some(config_content))?;
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
||||||
|
@ -81,7 +81,7 @@ fn create_offset_time_string(
|
|||||||
if utc_time_offset_in_hours < 24_f32 && utc_time_offset_in_hours > -24_f32 {
|
if utc_time_offset_in_hours < 24_f32 && utc_time_offset_in_hours > -24_f32 {
|
||||||
let utc_offset_in_seconds: i32 = (utc_time_offset_in_hours * 3600_f32) as i32;
|
let utc_offset_in_seconds: i32 = (utc_time_offset_in_hours * 3600_f32) as i32;
|
||||||
let Some(timezone_offset) = FixedOffset::east_opt(utc_offset_in_seconds) else {
|
let Some(timezone_offset) = FixedOffset::east_opt(utc_offset_in_seconds) else {
|
||||||
return Err("Invalid offset")
|
return Err("Invalid offset");
|
||||||
};
|
};
|
||||||
log::trace!("Target timezone offset is {}", timezone_offset);
|
log::trace!("Target timezone offset is {}", timezone_offset);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user