Browse Source

refactoring: move ls builtin line formatting

main
fdai7381 2 years ago
committed by fdai7451
parent
commit
6a6f2d8b38
  1. 10
      src/builtins/ls.rs

10
src/builtins/ls.rs

@ -37,16 +37,18 @@ impl Builtin for Ls {
file_type = "link" file_type = "link"
} }
println!( println!(
"{:} | {:4} | {}",
right_padding(&file_name, 16),
file_type,
metadata.len()
"{}",
format_line(&right_padding(&file_name, 16), file_type, metadata.len())
) )
} }
Ok(()) Ok(())
} }
} }
fn format_line(right_padding: &str, file_type: &str, file_size: u64) -> String {
format!("{:} | {:4} | {}", right_padding, file_type, file_size)
}
fn right_padding(s: &str, max: usize) -> String { fn right_padding(s: &str, max: usize) -> String {
let mut tmp = String::from_str(s).unwrap(); let mut tmp = String::from_str(s).unwrap();
for _ in tmp.len()..max { for _ in tmp.len()..max {

Loading…
Cancel
Save