mirror of
https://github.com/sxyazi/yazi.git
synced 2024-11-24 09:53:12 +03:00
refactor: using string interpolation
This commit is contained in:
parent
85f09e0103
commit
4af79f8f4a
@ -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, "$")?;
|
||||
|
@ -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> {
|
||||
|
@ -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<_>>();
|
||||
|
||||
|
@ -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<_>>();
|
||||
|
||||
|
@ -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),
|
||||
));
|
||||
|
||||
|
@ -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}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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}"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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)?,
|
||||
|
@ -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,
|
||||
}));
|
||||
|
@ -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()));
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user