Browse Source

feat: improve ls command output formatting

main
fdai7375 2 years ago
parent
commit
68a8c3fb25
  1. 9
      src/builtins/ls.rs

9
src/builtins/ls.rs

@ -18,6 +18,11 @@ impl Builtin for Ls {
//for entry in entries.by_ref().into_iter() {} //for entry in entries.by_ref().into_iter() {}
println!(
"{} | dir | size | modified |",
right_padding(" filename", 20)
);
for entry in entries { for entry in entries {
let Ok(entry) = entry else { let Ok(entry) = entry else {
eprintln!("Couldn't get directory entry"); eprintln!("Couldn't get directory entry");
@ -83,11 +88,11 @@ fn format_line(
modified: DateTime<Local>, modified: DateTime<Local>,
) -> String { ) -> String {
format!( format!(
"{} | {:4} | {:6} | {}",
"{} | {:4} | {:6} | {} |",
right_padding(file_name, max_name_len), right_padding(file_name, max_name_len),
file_type, file_type,
format_filesize(file_size), format_filesize(file_size),
format_date(modified)
right_padding(&format_date(modified), 10)
) )
} }

Loading…
Cancel
Save