mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-09 13:05:29 +00:00
Print directory listings in alphabetical order
This commit is contained in:
parent
bd7b542048
commit
9683146851
1 changed files with 6 additions and 3 deletions
|
|
@ -229,6 +229,7 @@ async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result
|
||||||
log::info!("Listing directory {:?}", path);
|
log::info!("Listing directory {:?}", path);
|
||||||
send_text_gemini_header(stream).await?;
|
send_text_gemini_header(stream).await?;
|
||||||
let mut entries = async_std::fs::read_dir(path).await?;
|
let mut entries = async_std::fs::read_dir(path).await?;
|
||||||
|
let mut lines = vec![];
|
||||||
while let Some(entry) = entries.next().await {
|
while let Some(entry) = entries.next().await {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let mut name = entry.file_name().into_string().or(Err("Non-Unicode filename"))?;
|
let mut name = entry.file_name().into_string().or(Err("Non-Unicode filename"))?;
|
||||||
|
|
@ -238,9 +239,11 @@ async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result
|
||||||
if entry.file_type().await?.is_dir() {
|
if entry.file_type().await?.is_dir() {
|
||||||
name += "/";
|
name += "/";
|
||||||
}
|
}
|
||||||
stream.write_all(b"=> ").await?;
|
lines.push(format!("=> {}\n", name));
|
||||||
stream.write_all(name.as_bytes()).await?;
|
}
|
||||||
stream.write_all(b"\n").await?;
|
lines.sort();
|
||||||
|
for line in lines {
|
||||||
|
stream.write_all(line.as_bytes()).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue