Skip to content

Commit 11418de

Browse files
committed
fixed the monstrosity /spelling
1 parent c48b9ea commit 11418de

File tree

1 file changed

+13
-101
lines changed

1 file changed

+13
-101
lines changed

src/single.rs

Lines changed: 13 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,17 @@
1-
extern crate pretty_bytes;
2-
use ansi_term::Style;
3-
use chrono::{DateTime, Utc};
4-
use pretty_bytes::converter::convert;
5-
use std::fs;
6-
use std::os::unix::fs::MetadataExt;
7-
use termion::color;
8-
use users::{get_user_by_uid, get_group_by_gid};
9-
use libc::{S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR};
1+
use crate::file_perms;
2+
use crate::file_size;
3+
use crate::time_mod;
4+
use crate::show_group_name;
5+
use crate::show_user_name;
6+
use crate::show_file_name;
107

11-
pub fn single(e: &std::path::PathBuf, size_count: usize) -> Result<(), Box<dyn std::error::Error>> {
12-
let meta = fs::symlink_metadata(&e)?;
13-
let mode = meta.mode();
14-
let mut mode_count = 0;
15-
16-
let mode_count = perms(mode as u16).len();
17-
18-
print!("{}", color::Fg(color::White));
19-
20-
print!("{}", perms(mode as u16));
21-
22-
23-
for _ in 0..(13 - mode_count) {
24-
print!(" ")
25-
}
26-
27-
for _ in 0..(size_count - convert(fs::metadata(&e)?.size() as f64).len()) {
28-
print!(" ")
29-
}
30-
print!("{}", color::Fg(color::Green));
31-
print!(
32-
" {}",
33-
Style::new()
34-
.bold()
35-
.paint(convert(fs::metadata(&e)?.size() as f64))
36-
);
37-
38-
if let Ok(time) = e.metadata()?.modified() {
39-
print!("{}", color::Fg(color::LightRed));
40-
let datetime: DateTime<Utc> = time.into();
41-
print!(" {} ", datetime.format("%d-%m-%Y"));
42-
print!("{}", datetime.format("%T"))
43-
}
44-
45-
print!("{}", color::Fg(color::Yellow));
468

47-
print!(
48-
" {} ",
49-
Style::new().bold().paint(
50-
get_group_by_gid(fs::metadata(e)?.gid())
51-
.unwrap()
52-
.name()
53-
.to_str()
54-
.unwrap()
55-
)
56-
);
57-
58-
print!("{}", color::Fg(color::LightYellow));
59-
60-
print!(
61-
"{} ",
62-
Style::new().bold().paint(
63-
get_user_by_uid(fs::metadata(e)?.uid())
64-
.unwrap()
65-
.name()
66-
.to_str()
67-
.unwrap()
68-
)
69-
);
70-
71-
print!("{}", color::Fg(color::White));
72-
if e.metadata()?.is_dir() {
73-
print!("{}", color::Fg(color::LightBlue));
74-
println!("{}/", &e.file_name().unwrap().to_str().unwrap());
75-
} else {
76-
print!("{}", color::Fg(color::LightGreen));
77-
println!(
78-
"{}",
79-
Style::new()
80-
.bold()
81-
.paint(e.file_name().unwrap().to_str().unwrap())
82-
);
83-
}
9+
pub fn single(e: &std::path::PathBuf, size_count: usize) -> Result<(), Box<dyn std::error::Error>> {
10+
let _ = file_perms(&e);
11+
let _ = file_size(size_count, &e);
12+
let _ = time_mod(e);
13+
let _ = show_group_name(e);
14+
let _ = show_user_name(e);
15+
let _ = show_file_name(&e);
8416
Ok(())
8517
}
86-
87-
fn triplet(mode: u16, read: u16, write: u16, execute: u16) -> String {
88-
match (mode & read, mode & write, mode & execute) {
89-
(0, 0, 0) => "---",
90-
(_, 0, 0) => "r--",
91-
(0, _, 0) => "-w-",
92-
(0, 0, _) => "--x",
93-
(_, 0, _) => "r-x",
94-
(_, _, 0) => "rw-",
95-
(0, _, _) => "-wx",
96-
(_, _, _) => "rwx",
97-
}.to_string()
98-
}
99-
100-
fn perms(mode: u16) -> String {
101-
let user = triplet(mode, S_IRUSR as u16, S_IWUSR as u16, S_IXUSR as u16);
102-
let group = triplet(mode, S_IRGRP as u16, S_IWGRP as u16, S_IXGRP as u16);
103-
let other = triplet(mode, S_IROTH as u16, S_IWOTH as u16, S_IXOTH as u16);
104-
[user, group, other].join("")
105-
}

0 commit comments

Comments
 (0)