1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 11:22:30 +01:00

Inline format! args wherever possible

This commit is contained in:
Lena
2024-02-24 22:36:14 +01:00
committed by Martin Nordholts
parent 487bed2d95
commit 4c85483486
17 changed files with 35 additions and 40 deletions

View File

@@ -380,7 +380,7 @@ fn asset_from_contents<T: serde::de::DeserializeOwned>(
} else {
bincode::deserialize_from(contents)
}
.map_err(|_| format!("Could not parse {}", description).into())
.map_err(|_| format!("Could not parse {description}").into())
}
fn asset_from_cache<T: serde::de::DeserializeOwned>(
@@ -396,7 +396,7 @@ fn asset_from_cache<T: serde::de::DeserializeOwned>(
)
})?;
asset_from_contents(&contents[..], description, compressed)
.map_err(|_| format!("Could not parse cached {}", description).into())
.map_err(|_| format!("Could not parse cached {description}").into())
}
#[cfg(target_os = "macos")]
@@ -466,7 +466,7 @@ mod tests {
let file_path = self.temp_dir.path().join(file_name);
{
let mut temp_file = File::create(&file_path).unwrap();
writeln!(temp_file, "{}", first_line).unwrap();
writeln!(temp_file, "{first_line}").unwrap();
}
let input = Input::ordinary_file(&file_path);
@@ -514,8 +514,7 @@ mod tests {
if !consistent {
eprintln!(
"Inconsistent syntax detection:\nFor File: {}\nFor Reader: {}",
as_file, as_reader
"Inconsistent syntax detection:\nFor File: {as_file}\nFor Reader: {as_reader}"
)
}

View File

@@ -93,7 +93,7 @@ fn print_unlinked_contexts(syntax_set: &SyntaxSet) {
if !missing_contexts.is_empty() {
println!("Some referenced contexts could not be found!");
for context in missing_contexts {
println!("- {}", context);
println!("- {context}");
}
}
}
@@ -152,7 +152,7 @@ pub(crate) fn asset_to_contents<T: serde::Serialize>(
} else {
bincode::serialize_into(&mut contents, asset)
}
.map_err(|_| format!("Could not serialize {}", description))?;
.map_err(|_| format!("Could not serialize {description}"))?;
Ok(contents)
}

View File

@@ -80,7 +80,7 @@ fn handle_license(path: &Path) -> Result<Option<String>> {
} else if license_not_needed_in_acknowledgements(&license_text) {
Ok(None)
} else {
Err(format!("ERROR: License is of unknown type: {:?}", path).into())
Err(format!("ERROR: License is of unknown type: {path:?}").into())
}
}
@@ -125,7 +125,7 @@ fn append_to_acknowledgements(
relative_path: &str,
license_text: &str,
) {
write!(acknowledgements, "## {}\n\n{}", relative_path, license_text).ok();
write!(acknowledgements, "## {relative_path}\n\n{license_text}").ok();
// Make sure the last char is a newline to not mess up formatting later
if acknowledgements

View File

@@ -88,7 +88,7 @@ impl TryFrom<ThemeSet> for LazyThemeSet {
let lazy_theme = LazyTheme {
serialized: crate::assets::build_assets::asset_to_contents(
&theme,
&format!("theme {}", name),
&format!("theme {name}"),
COMPRESS_LAZY_THEMES,
)?,
deserialized: OnceCell::new(),

View File

@@ -44,7 +44,7 @@ pub fn assets_from_cache_or_binary(
}
fn clear_asset(path: PathBuf, description: &str) {
print!("Clearing {} ... ", description);
print!("Clearing {description} ... ");
match fs::remove_file(&path) {
Err(err) if err.kind() == io::ErrorKind::NotFound => {
println!("skipped (not present)");

View File

@@ -430,7 +430,7 @@ pub fn build_app(interactive_output: bool) -> Command {
});
if let Some(invalid) = invalid_vals.next() {
Err(format!("Unknown style, '{}'", invalid))
Err(format!("Unknown style, '{invalid}'"))
} else {
Ok(val.to_owned())
}

View File

@@ -222,7 +222,7 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
)?;
} else {
for theme in assets.themes() {
writeln!(stdout, "{}", theme)?;
writeln!(stdout, "{theme}")?;
}
}
@@ -232,10 +232,7 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
fn set_terminal_title_to(new_terminal_title: String) {
let osc_command_for_setting_terminal_title = "\x1b]0;";
let osc_end_command = "\x07";
print!(
"{}{}{}",
osc_command_for_setting_terminal_title, new_terminal_title, osc_end_command
);
print!("{osc_command_for_setting_terminal_title}{new_terminal_title}{osc_end_command}");
io::stdout().flush().unwrap();
}

View File

@@ -56,7 +56,7 @@ impl Decoration for LineNumberDecoration {
self.cached_wrap.clone()
} else {
let plain: String = format!("{:4}", line_number);
let plain: String = format!("{line_number:4}");
DecorationText {
width: plain.len(),
text: self.color.paint(plain).to_string(),

View File

@@ -197,7 +197,7 @@ impl<'a> Input<'a> {
InputKind::StdIn => {
if let Some(stdout) = stdout_identifier {
let input_identifier = Identifier::try_from(clircle::Stdio::Stdin)
.map_err(|e| format!("Stdin: Error identifying file: {}", e))?;
.map_err(|e| format!("Stdin: Error identifying file: {e}"))?;
if stdout.surely_conflicts_with(&input_identifier) {
return Err("IO circle detected. The input from stdin is also an output. Aborting to avoid infinite loop.".into());
}

View File

@@ -160,7 +160,7 @@ impl<'a> Printer for SimplePrinter<'a> {
self.config.tab_width,
self.config.nonprintable_notation,
);
write!(handle, "{}", line)?;
write!(handle, "{line}")?;
} else {
match handle {
OutputHandle::IoWrite(handle) => handle.write_all(line_buffer)?,
@@ -333,7 +333,7 @@ impl<'a> InteractivePrinter<'a> {
" ".repeat(self.panel_width - 1 - text_truncated.len())
);
if self.config.style_components.grid() {
format!("{}", text_filled)
format!("{text_filled}")
} else {
text_filled
}
@@ -368,7 +368,7 @@ impl<'a> InteractivePrinter<'a> {
content: &str,
) -> Result<()> {
self.print_header_component_indent(handle)?;
writeln!(handle, "{}", content)
writeln!(handle, "{content}")
}
fn print_header_multiline_component(
@@ -494,7 +494,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
"{}{}{}",
description
.kind()
.map(|kind| format!("{}: ", kind))
.map(|kind| format!("{kind}: "))
.unwrap_or_else(|| "".into()),
self.colors.header_value.paint(description.title()),
mode
@@ -552,7 +552,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
"{}",
self.colors
.grid
.paint(format!("{}{}{}{}", panel, snip_left, title, snip_right))
.paint(format!("{panel}{snip_left}{title}{snip_right}"))
)?;
Ok(())

View File

@@ -80,7 +80,7 @@ impl FromStr for StyleComponent {
"full" => Ok(StyleComponent::Full),
"default" => Ok(StyleComponent::Default),
"plain" => Ok(StyleComponent::Plain),
_ => Err(format!("Unknown style '{}'", s).into()),
_ => Err(format!("Unknown style '{s}'").into()),
}
}
}

View File

@@ -73,7 +73,7 @@ fn internal_suffixes() {
let file_names = ignored_suffixes
.values
.iter()
.map(|suffix| format!("test.json{}", suffix));
.map(|suffix| format!("test.json{suffix}"));
for file_name_str in file_names {
let file_name = OsStr::new(&file_name_str);
let expected_stripped_file_name = OsStr::new("test.json");
@@ -95,7 +95,7 @@ fn external_suffixes() {
let file_names = ignored_suffixes
.values
.iter()
.map(|suffix| format!("test.json{}", suffix));
.map(|suffix| format!("test.json{suffix}"));
for file_name_str in file_names {
let file_name = OsStr::new(&file_name_str);
let expected_stripped_file_name = OsStr::new("test.json");

View File

@@ -221,11 +221,11 @@ impl Attributes {
8 => match parameters.next() {
Some(5) /* 256-color */ => format!("\x1B[{};5;{}m", color, join(";", 1, parameters)),
Some(2) /* 24-bit color */ => format!("\x1B[{};2;{}m", color, join(";", 3, parameters)),
Some(c) => format!("\x1B[{};{}m", color, c),
Some(c) => format!("\x1B[{color};{c}m"),
_ => "".to_owned(),
},
9 => "".to_owned(),
_ => format!("\x1B[{}m", color),
_ => format!("\x1B[{color}m"),
}
}
@@ -435,7 +435,7 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
}
Some((_, tc)) => {
panic!("this should not be reached: char {:?}", tc)
panic!("this should not be reached: char {tc:?}")
}
}
}