From b2a5e5f190a7411f32a22cff9c2d90986e2835c0 Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Mon, 30 Jan 2023 10:47:10 +0100 Subject: [PATCH] refactoring: move ls builtin line formatting --- src/builtins/ls.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/builtins/ls.rs b/src/builtins/ls.rs index 09372c2..1c0e019 100644 --- a/src/builtins/ls.rs +++ b/src/builtins/ls.rs @@ -37,16 +37,18 @@ impl Builtin for Ls { file_type = "link" } println!( - "{:} | {:4} | {}", - right_padding(&file_name, 16), - file_type, - metadata.len() + "{}", + format_line(&right_padding(&file_name, 16), file_type, metadata.len()) ) } 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 { let mut tmp = String::from_str(s).unwrap(); for _ in tmp.len()..max {