Unify string formatting

This commit is contained in:
Hamir Mahal 2024-07-23 18:37:35 -07:00 committed by GitHub
parent 6bd1674bd8
commit d021a7b6f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 27 additions and 30 deletions

View File

@ -524,7 +524,7 @@ mod tests {
let generated = String::from_utf8_lossy(&generated);
let mut completion = String::new();
let mut file = File::open(format!("../extra/completions/{}", file)).unwrap();
let mut file = File::open(format!("../extra/completions/{file}")).unwrap();
file.read_to_string(&mut completion).unwrap();
assert_eq!(generated, completion);

View File

@ -287,7 +287,7 @@ impl Display for Action {
Action::ViMotion(motion) => motion.fmt(f),
Action::Vi(action) => action.fmt(f),
Action::Mouse(action) => action.fmt(f),
_ => write!(f, "{:?}", self),
_ => write!(f, "{self:?}"),
}
}
}
@ -1024,8 +1024,7 @@ impl<'a> Deserialize<'a> for RawBinding {
},
Err(_) => {
return Err(<V::Error as Error>::custom(format!(
"Invalid key binding, scancode is too big: {}",
scancode
"Invalid key binding, scancode is too big: {scancode}"
)));
},
},
@ -1080,8 +1079,7 @@ impl<'a> Deserialize<'a> for RawBinding {
_ => return Err(err),
};
return Err(V::Error::custom(format!(
"unknown keyboard action `{}`",
value
"unknown keyboard action `{value}`"
)));
},
}
@ -1122,8 +1120,7 @@ impl<'a> Deserialize<'a> for RawBinding {
(Some(action @ Action::Mouse(_)), None, None) => {
if mouse.is_none() {
return Err(V::Error::custom(format!(
"action `{}` is only available for mouse bindings",
action,
"action `{action}` is only available for mouse bindings",
)));
}
action

View File

@ -76,12 +76,12 @@ impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Error::ReadingEnvHome(err) => {
write!(f, "Unable to read $HOME environment variable: {}", err)
write!(f, "Unable to read $HOME environment variable: {err}")
},
Error::Io(err) => write!(f, "Error reading config file: {}", err),
Error::Toml(err) => write!(f, "Config error: {}", err),
Error::TomlSe(err) => write!(f, "Yaml conversion error: {}", err),
Error::Yaml(err) => write!(f, "Config error: {}", err),
Error::Io(err) => write!(f, "Error reading config file: {err}"),
Error::Toml(err) => write!(f, "Config error: {err}"),
Error::TomlSe(err) => write!(f, "Yaml conversion error: {err}"),
Error::Yaml(err) => write!(f, "Config error: {err}"),
}
}
}

View File

@ -94,7 +94,7 @@ pub fn foreground_process_path(
}
#[cfg(not(any(target_os = "macos", target_os = "freebsd")))]
let link_path = format!("/proc/{}/cwd", pid);
let link_path = format!("/proc/{pid}/cwd");
#[cfg(target_os = "freebsd")]
let link_path = format!("/compat/linux/proc/{}/cwd", pid);

View File

@ -1241,7 +1241,7 @@ impl Display {
fn draw_search(&mut self, config: &UiConfig, text: &str) {
// Assure text length is at least num_cols.
let num_cols = self.size_info.columns();
let text = format!("{:<1$}", text, num_cols);
let text = format!("{text:<num_cols$}");
let point = Point::new(self.size_info.screen_lines(), Column(0));

View File

@ -76,7 +76,7 @@ impl std::error::Error for Error {
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Error::WindowCreation(err) => write!(f, "Error creating GL context; {}", err),
Error::WindowCreation(err) => write!(f, "Error creating GL context; {err}"),
Error::Font(err) => err.fmt(f),
}
}

View File

@ -294,7 +294,7 @@ fn build_sequence(key: KeyEvent, mods: ModifiersState, mode: TermMode) -> Vec<u8
_ => return Vec::new(),
};
let mut payload = format!("\x1b[{}", payload);
let mut payload = format!("\x1b[{payload}");
// Add modifiers information.
if kitty_event_type || !modifiers.is_empty() || associated_text.is_some() {

View File

@ -809,7 +809,7 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
if self.ctx.terminal().mode().contains(TermMode::FOCUS_IN_OUT) {
let chr = if is_focused { "I" } else { "O" };
let msg = format!("\x1b[{}", chr);
let msg = format!("\x1b[{chr}");
self.ctx.write_to_pty(msg.into_bytes());
}
}

View File

@ -111,7 +111,7 @@ fn find_socket(socket_path: Option<PathBuf>) -> IoResult<UnixStream> {
if let Some(socket_path) = socket_path {
// Ensure we inform the user about an invalid path.
return UnixStream::connect(&socket_path).map_err(|err| {
let message = format!("invalid socket path {:?}", socket_path);
let message = format!("invalid socket path {socket_path:?}");
IoError::new(err.kind(), message)
});
}

View File

@ -108,7 +108,7 @@ impl Logger {
};
#[cfg(not(windows))]
let env_var = format!("${}", ALACRITTY_LOG_ENV);
let env_var = format!("${ALACRITTY_LOG_ENV}");
#[cfg(windows)]
let env_var = format!("%{}%", ALACRITTY_LOG_ENV);
@ -227,7 +227,7 @@ impl OnDemandLogFile {
writeln!(io::stdout(), "Created log file at \"{}\"", self.path.display());
},
Err(e) => {
let _ = writeln!(io::stdout(), "Unable to create log file: {}", e);
let _ = writeln!(io::stdout(), "Unable to create log file: {e}");
return Err(e);
},
}

View File

@ -66,10 +66,10 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Shader(err) => {
write!(f, "There was an error initializing the shaders: {}", err)
write!(f, "There was an error initializing the shaders: {err}")
},
Error::Other(err) => {
write!(f, "{}", err)
write!(f, "{err}")
},
}
}
@ -111,9 +111,9 @@ fn gl_get_string(
Ok(CStr::from_ptr(string_ptr as *const _).to_string_lossy())
},
gl::INVALID_ENUM => {
Err(format!("OpenGL error requesting {}: invalid enum", description).into())
Err(format!("OpenGL error requesting {description}: invalid enum").into())
},
error_id => Err(format!("OpenGL error {} requesting {}", error_id, description).into()),
error_id => Err(format!("OpenGL error {error_id} requesting {description}").into()),
}
}
}

View File

@ -196,9 +196,9 @@ impl std::error::Error for ShaderError {}
impl fmt::Display for ShaderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Compile(reason) => write!(f, "Failed compiling shader: {}", reason),
Self::Link(reason) => write!(f, "Failed linking shader: {}", reason),
Self::Uniform(name) => write!(f, "Failed to get uniform location of {:?}", name),
Self::Compile(reason) => write!(f, "Failed compiling shader: {reason}"),
Self::Link(reason) => write!(f, "Failed linking shader: {reason}"),
Self::Uniform(name) => write!(f, "Failed to get uniform location of {name:?}"),
}
}
}

View File

@ -112,11 +112,11 @@ fn match_arms<T>(fields: &Punctuated<Field, T>) -> Result<TokenStream2, syn::Err
.map(|parsed| {
let value = parsed
.param
.ok_or_else(|| format!("Field \"{}\" has no alias value", ident))?
.ok_or_else(|| format!("Field \"{ident}\" has no alias value"))?
.value();
if value.trim().is_empty() {
return Err(format!("Field \"{}\" has an empty alias value", ident));
return Err(format!("Field \"{ident}\" has an empty alias value"));
}
Ok(value)