refactor: using string interpolation

This commit is contained in:
sxyazi 2023-08-03 21:54:59 +08:00
parent 85f09e0103
commit 4af79f8f4a
No known key found for this signature in database
14 changed files with 22 additions and 22 deletions

View File

@ -69,18 +69,18 @@ impl Sixel {
}
if repeat > 1 {
write!(buf, "#{}!{}{}", last, repeat, c)?;
write!(buf, "#{last}!{repeat}{c}")?;
} else {
write!(buf, "#{}{}", last, c)?;
write!(buf, "#{last}{c}")?;
}
(last, repeat) = (idx, 1);
}
if repeat > 1 {
write!(buf, "#{}!{}{}", last, repeat, c)?;
write!(buf, "#{last}!{repeat}{c}")?;
} else {
write!(buf, "#{}{}", last, c)?;
write!(buf, "#{last}{c}")?;
}
write!(buf, "$")?;

View File

@ -3,7 +3,7 @@ use config::LOG;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::{fmt, prelude::__tracing_subscriber_SubscriberExt, Registry};
pub(super) struct Logs {}
pub(super) struct Logs;
impl Logs {
pub(super) fn init() -> Result<WorkerGuard> {

View File

@ -77,7 +77,7 @@ impl<'a> Widget for Folder<'a> {
self.file_style(v)
};
ListItem::new(format!(" {} {}", icon, readable_path(k, &self.folder.cwd))).style(style)
ListItem::new(format!(" {icon} {}", readable_path(k, &self.folder.cwd))).style(style)
})
.collect::<Vec<_>>();

View File

@ -21,10 +21,10 @@ impl<'a> Widget for Select<'a> {
.enumerate()
.map(|(i, v)| {
if i != select.rel_cursor() {
return ListItem::new(format!(" {}", v));
return ListItem::new(format!(" {v}"));
}
ListItem::new(format!("{}", v)).style(Style::new().fg(Color::Magenta))
ListItem::new(format!("{v}")).style(Style::new().fg(Color::Magenta))
})
.collect::<Vec<_>>();

View File

@ -27,7 +27,7 @@ impl<'a> Widget for Left<'a> {
// Mode
spans.push(Span::styled("", primary.fg()));
spans.push(Span::styled(
format!(" {} ", mode),
format!(" {mode} "),
primary.bg().fg(**secondary).add_modifier(Modifier::BOLD),
));

View File

@ -92,7 +92,7 @@ impl TryFrom<String> for Key {
c if it.peek().is_none() => {
key.code = KeyCode::Char(c.chars().next().unwrap());
}
k => bail!("unknown key: {}", k),
k => bail!("unknown key: {k}"),
}
}

View File

@ -20,7 +20,7 @@ impl TryFrom<String> for SortBy {
"created" => Self::Created,
"modified" => Self::Modified,
"size" => Self::Size,
_ => bail!("invalid sort_by value: {}", s),
_ => bail!("invalid sort_by value: {s}"),
})
}
}

View File

@ -17,7 +17,7 @@ impl TryFrom<String> for Color {
fn try_from(s: String) -> Result<Self, Self::Error> {
if s.len() < 7 {
bail!("Invalid color: {}", s);
bail!("Invalid color: {s}");
}
Ok(Self(style::Color::Rgb(
u8::from_str_radix(&s[1..3], 16)?,

View File

@ -99,7 +99,7 @@ impl Manager {
tokio::spawn(async move {
let result = emit!(Input(InputOpt {
title: format!("There are {} tasks running, sure to quit? (y/N)", tasks),
title: format!("There are {tasks} tasks running, sure to quit? (y/N)"),
value: "".to_string(),
position: Position::Top,
}));

View File

@ -65,7 +65,7 @@ impl Preview {
MimeKind::Image => Self::image(&path).await,
MimeKind::Video => Self::video(&path).await,
MimeKind::Archive => Self::archive(&path).await.map(PreviewData::Text),
MimeKind::Others => Err(anyhow!("Unsupported mimetype: {}", mime)),
MimeKind::Others => Err(anyhow!("Unsupported mimetype: {mime}")),
};
emit!(Preview(path, mime, result.unwrap_or_default()));

View File

@ -76,7 +76,7 @@ impl Scheduler {
continue;
}
if let Err(e) = file.work(&mut op).await {
info!("Failed to work on task {:?}: {}", op, e);
info!("Failed to work on task {:?}: {e}", op);
} else {
trace!("Finished task {:?}", op);
}
@ -87,7 +87,7 @@ impl Scheduler {
continue;
}
if let Err(e) = precache.work(&mut op).await {
info!("Failed to work on task {:?}: {}", op, e);
info!("Failed to work on task {:?}: {e}", op);
} else {
trace!("Finished task {:?}", op);
}

View File

@ -90,7 +90,7 @@ impl File {
break;
}
Ok(n) => {
self.log(task.id, format!("Paste task advanced {}: {:?}", n, task))?;
self.log(task.id, format!("Paste task advanced {n}: {:?}", task))?;
self.sch.send(TaskOp::Adv(task.id, 0, n))?
}
Err(e) if e.kind() == NotFound => {
@ -132,7 +132,7 @@ impl File {
FileOp::Delete(task) => {
if let Err(e) = fs::remove_file(&task.target).await {
if e.kind() != NotFound && fs::symlink_metadata(&task.target).await.is_ok() {
self.log(task.id, format!("Delete task failed: {:?}, {}", task, e))?;
self.log(task.id, format!("Delete task failed: {:?}, {e}", task))?;
Err(e)?
}
}
@ -192,7 +192,7 @@ impl File {
let dest = root.join(src.components().skip(skip).collect::<PathBuf>());
match fs::create_dir(&dest).await {
Err(e) if e.kind() != AlreadyExists => {
self.log(task.id, format!("Create dir failed: {:?}, {}", dest, e))?;
self.log(task.id, format!("Create dir failed: {:?}, {e}", dest))?;
continue;
}
_ => {}
@ -201,7 +201,7 @@ impl File {
let mut it = match fs::read_dir(&src).await {
Ok(it) => it,
Err(e) => {
self.log(task.id, format!("Read dir failed: {:?}, {}", src, e))?;
self.log(task.id, format!("Read dir failed: {:?}, {e}", src))?;
continue;
}
};

View File

@ -38,7 +38,7 @@ impl Process {
child.wait().await.ok();
}
Err(e) => {
trace!("Failed to spawn {}: {}", task.cmd, e);
trace!("Failed to spawn {}: {e}", task.cmd);
}
}

View File

@ -53,7 +53,7 @@ pub async fn unique_path(mut p: PathBuf) -> PathBuf {
while fs::symlink_metadata(&p).await.is_ok() {
i += 1;
let mut name = name.clone();
name.push(format!("_{}", i));
name.push(format!("_{i}"));
p.set_file_name(name);
}
p