Browse Source

feat: add ls command accessed timestamp

main
fdai7375 2 years ago
parent
commit
c83dbe08ba
  1. 22
      src/builtins/ls.rs

22
src/builtins/ls.rs

@ -19,7 +19,7 @@ impl Builtin for Ls {
//for entry in entries.by_ref().into_iter() {}
println!(
"{} | dir | size | modified |",
"{} | dir | size | modified | accessed |",
right_padding(" filename", 20)
);
@ -42,6 +42,11 @@ impl Builtin for Ls {
Err(_) => Local::now(),
};
let accessed: DateTime<Local> = match metadata.accessed() {
Ok(t) => DateTime::from(t),
Err(_) => Local::now(),
};
let mut file_type = "unknown";
if metadata.file_type().is_dir() {
file_type = "dir"
@ -52,7 +57,14 @@ impl Builtin for Ls {
}
println!(
"{}",
format_line(20, &file_name, file_type, metadata.len(), modified)
format_line(
20,
&file_name,
file_type,
metadata.len(),
modified,
accessed
)
);
}
Ok(())
@ -86,13 +98,15 @@ fn format_line(
file_type: &str,
file_size: u64,
modified: DateTime<Local>,
accessed: DateTime<Local>,
) -> String {
format!(
"{} | {:4} | {:6} | {} |",
"{} | {:4} | {:6} | {} | {} |",
right_padding(file_name, max_name_len),
file_type,
format_filesize(file_size),
right_padding(&format_date(modified), 10)
right_padding(&format_date(modified), 10),
right_padding(&format_date(accessed), 10)
)
}

Loading…
Cancel
Save