mirror of
https://github.com/lsd-rs/lsd
synced 2025-01-20 15:33:56 +00:00
Add the file_type into the Permission struct
This commit is contained in:
parent
21cc041775
commit
033181ca9b
3 changed files with 13 additions and 16 deletions
|
@ -106,7 +106,7 @@ impl<'a> Core<'a> {
|
||||||
for meta in metas {
|
for meta in metas {
|
||||||
println!(
|
println!(
|
||||||
"{} {} {} {} {} {}{}",
|
"{} {} {} {} {} {}{}",
|
||||||
self.formatter.format_permissions(&meta),
|
meta.permissions.render(),
|
||||||
self.formatter.format_user(&meta.user, max_user_length),
|
self.formatter.format_user(&meta.user, max_user_length),
|
||||||
self.formatter.format_group(&meta.group, max_group_length),
|
self.formatter.format_group(&meta.group, max_group_length),
|
||||||
meta.size
|
meta.size
|
||||||
|
|
|
@ -73,20 +73,6 @@ impl Formatter {
|
||||||
color.paint(time.ctime().to_string()).to_string()
|
color.paint(time.ctime().to_string()).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_permissions(&self, meta: &Meta) -> String {
|
|
||||||
let mut res = String::with_capacity(11);
|
|
||||||
|
|
||||||
match meta.node_type {
|
|
||||||
Type::File => res += &Colors[&Elem::File].paint("."),
|
|
||||||
Type::Directory => res += &Colors[&Elem::Dir].paint("d"),
|
|
||||||
Type::SymLink(_) => res += &Colors[&Elem::SymLink].paint("l"),
|
|
||||||
}
|
|
||||||
|
|
||||||
res += &meta.permissions.render();
|
|
||||||
|
|
||||||
res.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn format_user(&self, user_name: &str, max_user_size: usize) -> String {
|
pub fn format_user(&self, user_name: &str, max_user_size: usize) -> String {
|
||||||
if user_name.len() == max_user_size {
|
if user_name.len() == max_user_size {
|
||||||
return Colors[&Elem::User].paint(user_name).to_string();
|
return Colors[&Elem::User].paint(user_name).to_string();
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use super::Type;
|
||||||
use ansi_term::{ANSIString, Colour};
|
use ansi_term::{ANSIString, Colour};
|
||||||
use color::{Colors, Elem};
|
use color::{Colors, Elem};
|
||||||
use std::fs::Metadata;
|
use std::fs::Metadata;
|
||||||
|
@ -5,6 +6,8 @@ use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Permissions {
|
pub struct Permissions {
|
||||||
|
pub file_type: Type,
|
||||||
|
|
||||||
pub user_read: bool,
|
pub user_read: bool,
|
||||||
pub user_write: bool,
|
pub user_write: bool,
|
||||||
pub user_execute: bool,
|
pub user_execute: bool,
|
||||||
|
@ -28,6 +31,8 @@ impl<'a> From<&'a Metadata> for Permissions {
|
||||||
let has_bit = |bit| bits & bit == bit;
|
let has_bit = |bit| bits & bit == bit;
|
||||||
|
|
||||||
Permissions {
|
Permissions {
|
||||||
|
file_type: Type::from(meta),
|
||||||
|
|
||||||
user_read: has_bit(modes::USER_READ),
|
user_read: has_bit(modes::USER_READ),
|
||||||
user_write: has_bit(modes::USER_WRITE),
|
user_write: has_bit(modes::USER_WRITE),
|
||||||
user_execute: has_bit(modes::USER_EXECUTE),
|
user_execute: has_bit(modes::USER_EXECUTE),
|
||||||
|
@ -49,7 +54,13 @@ impl<'a> From<&'a Metadata> for Permissions {
|
||||||
|
|
||||||
impl Permissions {
|
impl Permissions {
|
||||||
pub fn render(&self) -> String {
|
pub fn render(&self) -> String {
|
||||||
let mut res = String::with_capacity(10);
|
let mut res = String::with_capacity(11);
|
||||||
|
|
||||||
|
match self.file_type {
|
||||||
|
Type::File => res += &Colors[&Elem::File].paint("."),
|
||||||
|
Type::Directory => res += &Colors[&Elem::Dir].paint("d"),
|
||||||
|
Type::SymLink(_) => res += &Colors[&Elem::SymLink].paint("l"),
|
||||||
|
}
|
||||||
|
|
||||||
let bit = |bit, chr: &'static str, color: Colour| {
|
let bit = |bit, chr: &'static str, color: Colour| {
|
||||||
if bit {
|
if bit {
|
||||||
|
|
Loading…
Reference in a new issue