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 { if repeat > 1 {
write!(buf, "#{}!{}{}", last, repeat, c)?; write!(buf, "#{last}!{repeat}{c}")?;
} else { } else {
write!(buf, "#{}{}", last, c)?; write!(buf, "#{last}{c}")?;
} }
(last, repeat) = (idx, 1); (last, repeat) = (idx, 1);
} }
if repeat > 1 { if repeat > 1 {
write!(buf, "#{}!{}{}", last, repeat, c)?; write!(buf, "#{last}!{repeat}{c}")?;
} else { } else {
write!(buf, "#{}{}", last, c)?; write!(buf, "#{last}{c}")?;
} }
write!(buf, "$")?; write!(buf, "$")?;

View file

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

View file

@ -77,7 +77,7 @@ impl<'a> Widget for Folder<'a> {
self.file_style(v) 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<_>>(); .collect::<Vec<_>>();

View file

@ -21,10 +21,10 @@ impl<'a> Widget for Select<'a> {
.enumerate() .enumerate()
.map(|(i, v)| { .map(|(i, v)| {
if i != select.rel_cursor() { 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<_>>(); .collect::<Vec<_>>();

View file

@ -27,7 +27,7 @@ impl<'a> Widget for Left<'a> {
// Mode // Mode
spans.push(Span::styled("", primary.fg())); spans.push(Span::styled("", primary.fg()));
spans.push(Span::styled( spans.push(Span::styled(
format!(" {} ", mode), format!(" {mode} "),
primary.bg().fg(**secondary).add_modifier(Modifier::BOLD), 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() => { c if it.peek().is_none() => {
key.code = KeyCode::Char(c.chars().next().unwrap()); 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, "created" => Self::Created,
"modified" => Self::Modified, "modified" => Self::Modified,
"size" => Self::Size, "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> { fn try_from(s: String) -> Result<Self, Self::Error> {
if s.len() < 7 { if s.len() < 7 {
bail!("Invalid color: {}", s); bail!("Invalid color: {s}");
} }
Ok(Self(style::Color::Rgb( Ok(Self(style::Color::Rgb(
u8::from_str_radix(&s[1..3], 16)?, u8::from_str_radix(&s[1..3], 16)?,

View file

@ -99,7 +99,7 @@ impl Manager {
tokio::spawn(async move { tokio::spawn(async move {
let result = emit!(Input(InputOpt { 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(), value: "".to_string(),
position: Position::Top, position: Position::Top,
})); }));

View file

@ -65,7 +65,7 @@ impl Preview {
MimeKind::Image => Self::image(&path).await, MimeKind::Image => Self::image(&path).await,
MimeKind::Video => Self::video(&path).await, MimeKind::Video => Self::video(&path).await,
MimeKind::Archive => Self::archive(&path).await.map(PreviewData::Text), 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())); emit!(Preview(path, mime, result.unwrap_or_default()));

View file

@ -76,7 +76,7 @@ impl Scheduler {
continue; continue;
} }
if let Err(e) = file.work(&mut op).await { 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 { } else {
trace!("Finished task {:?}", op); trace!("Finished task {:?}", op);
} }
@ -87,7 +87,7 @@ impl Scheduler {
continue; continue;
} }
if let Err(e) = precache.work(&mut op).await { 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 { } else {
trace!("Finished task {:?}", op); trace!("Finished task {:?}", op);
} }

View file

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

View file

@ -38,7 +38,7 @@ impl Process {
child.wait().await.ok(); child.wait().await.ok();
} }
Err(e) => { 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() { while fs::symlink_metadata(&p).await.is_ok() {
i += 1; i += 1;
let mut name = name.clone(); let mut name = name.clone();
name.push(format!("_{}", i)); name.push(format!("_{i}"));
p.set_file_name(name); p.set_file_name(name);
} }
p p