|
@ -1,4 +1,8 @@ |
|
|
use std::{fs::metadata, path::PathBuf, str::FromStr};
|
|
|
|
|
|
|
|
|
use std::{
|
|
|
|
|
|
fs::{metadata, Permissions},
|
|
|
|
|
|
path::PathBuf,
|
|
|
|
|
|
str::FromStr,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
use chrono::{DateTime, Datelike, Local};
|
|
|
use chrono::{DateTime, Datelike, Local};
|
|
|
|
|
|
|
|
@ -19,7 +23,7 @@ impl Builtin for Ls { |
|
|
//for entry in entries.by_ref().into_iter() {}
|
|
|
//for entry in entries.by_ref().into_iter() {}
|
|
|
|
|
|
|
|
|
println!(
|
|
|
println!(
|
|
|
"{} | dir | size | modified | accessed | created |",
|
|
|
|
|
|
|
|
|
"{} | dir | size | modified | accessed | created | readonly |",
|
|
|
right_padding(" filename", 20)
|
|
|
right_padding(" filename", 20)
|
|
|
);
|
|
|
);
|
|
|
|
|
|
|
|
@ -52,6 +56,8 @@ impl Builtin for Ls { |
|
|
Err(_) => Local::now(),
|
|
|
Err(_) => Local::now(),
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let permissions = metadata.permissions();
|
|
|
|
|
|
|
|
|
let mut file_type = "unknown";
|
|
|
let mut file_type = "unknown";
|
|
|
if metadata.file_type().is_dir() {
|
|
|
if metadata.file_type().is_dir() {
|
|
|
file_type = "dir"
|
|
|
file_type = "dir"
|
|
@ -69,7 +75,8 @@ impl Builtin for Ls { |
|
|
metadata.len(),
|
|
|
metadata.len(),
|
|
|
modified,
|
|
|
modified,
|
|
|
accessed,
|
|
|
accessed,
|
|
|
created
|
|
|
|
|
|
|
|
|
created,
|
|
|
|
|
|
permissions
|
|
|
)
|
|
|
)
|
|
|
);
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@ -106,15 +113,17 @@ fn format_line( |
|
|
modified: DateTime<Local>,
|
|
|
modified: DateTime<Local>,
|
|
|
accessed: DateTime<Local>,
|
|
|
accessed: DateTime<Local>,
|
|
|
created: DateTime<Local>,
|
|
|
created: DateTime<Local>,
|
|
|
|
|
|
permissions: Permissions,
|
|
|
) -> 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),
|
|
|
right_padding(&format_date(modified), 10),
|
|
|
right_padding(&format_date(modified), 10),
|
|
|
right_padding(&format_date(accessed), 10),
|
|
|
right_padding(&format_date(accessed), 10),
|
|
|
right_padding(&format_date(created), 10),
|
|
|
right_padding(&format_date(created), 10),
|
|
|
|
|
|
right_padding(&permissions.readonly().to_string(), 5),
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|