Fix the lint errors

This commit is contained in:
Peltoche 2018-12-13 16:50:47 +01:00 committed by Pierre Peltier
parent c621352f8a
commit be41956919
13 changed files with 252 additions and 260 deletions

View file

@ -34,7 +34,7 @@ fn main() {
}; };
fs::create_dir_all(&outdir).unwrap(); fs::create_dir_all(&outdir).unwrap();
let mut app = build_app(); let mut app = build();
app.gen_completions("lsd", Shell::Bash, &outdir); app.gen_completions("lsd", Shell::Bash, &outdir);
app.gen_completions("lsd", Shell::Fish, &outdir); app.gen_completions("lsd", Shell::Fish, &outdir);
app.gen_completions("lsd", Shell::Zsh, &outdir); app.gen_completions("lsd", Shell::Zsh, &outdir);

View file

@ -1,6 +1,6 @@
use clap::{App, Arg}; use clap::{App, Arg};
pub fn build_app() -> App<'static, 'static> { pub fn build() -> App<'static, 'static> {
App::new("lsd") App::new("lsd")
.version(crate_version!()) .version(crate_version!())
.about("An ls comment with a lot of pretty colors and some other stuff.") .about("An ls comment with a lot of pretty colors and some other stuff.")

View file

@ -55,10 +55,10 @@ impl Colors {
pub fn new(theme: Theme) -> Self { pub fn new(theme: Theme) -> Self {
let colors = match theme { let colors = match theme {
Theme::NoColor => None, Theme::NoColor => None,
Theme::Default => Some(Colors::get_light_theme_colour_map()), Theme::Default => Some(Self::get_light_theme_colour_map()),
}; };
Colors { colors } Self { colors }
} }
pub fn colorize<'a>(&self, input: String, elem: &Elem) -> ColoredString<'a> { pub fn colorize<'a>(&self, input: String, elem: &Elem) -> ColoredString<'a> {

View file

@ -15,7 +15,7 @@ pub struct Core {
} }
impl Core { impl Core {
pub fn new(flags: Flags) -> Core { pub fn new(flags: Flags) -> Self {
// terminal_size allows us to know if the stdout is a tty or not. // terminal_size allows us to know if the stdout is a tty or not.
let tty_available = terminal_size().is_some(); let tty_available = terminal_size().is_some();
@ -43,7 +43,7 @@ impl Core {
inner_flags.display_online = true; inner_flags.display_online = true;
}; };
Core { Self {
flags, flags,
display: Display::new(inner_flags), display: Display::new(inner_flags),
colors: Colors::new(color_theme), colors: Colors::new(color_theme),
@ -118,14 +118,14 @@ impl Core {
if elem.file_type == FileType::Directory { if elem.file_type == FileType::Directory {
self.display.print_tree_row( self.display.print_tree_row(
elem.name.render(&self.colors, &self.icons).to_string(), &elem.name.render(&self.colors, &self.icons),
depth, depth,
last, last,
); );
self.run_inner(vec![elem.path], depth + 1); self.run_inner(vec![elem.path], depth + 1);
} else { } else {
self.display.print_tree_row( self.display.print_tree_row(
elem.name.render(&self.colors, &self.icons).to_string(), &elem.name.render(&self.colors, &self.icons),
depth, depth,
last, last,
); );

View file

@ -1,19 +1,20 @@
use color::ColoredString;
use flags::Flags; use flags::Flags;
use std::io::Write; use std::io::Write;
use term_grid::{Cell, Direction, Filling, Grid, GridOptions}; use term_grid::{Cell, Direction, Filling, Grid, GridOptions};
use terminal_size::terminal_size; use terminal_size::terminal_size;
const EDGE: &str = "├──"; const EDGE: &str = "\u{251c}\u{2500}\u{2500}"; // "├──"
const LINE: &str = ""; const LINE: &str = "\u{2502} "; // "├ "
const CORNER: &str = "└──"; const CORNER: &str = "\u{2514}\u{2500}\u{2500}"; // "└──"
pub struct Display { pub struct Display {
flags: Flags, flags: Flags,
} }
impl Display { impl Display {
pub fn new(flags: Flags) -> Display { pub fn new(flags: Flags) -> Self {
Display { flags } Self { flags }
} }
pub fn print_outputs(&self, outputs: Vec<String>) { pub fn print_outputs(&self, outputs: Vec<String>) {
@ -44,24 +45,18 @@ impl Display {
if let Some(gridded_output) = grid.fit_into_width(term_width) { if let Some(gridded_output) = grid.fit_into_width(term_width) {
print!("{}", gridded_output); print!("{}", gridded_output);
std::io::stdout() std::io::stdout().flush().expect("Could not flush stdout");
.flush()
.ok()
.expect("Could not flush stdout");
} else { } else {
//does not fit into grid, usually because (some) filename(s) //does not fit into grid, usually because (some) filename(s)
//are longer or almost as long as term_width //are longer or almost as long as term_width
//print line by line instead! //print line by line instead!
let lined_output = grid.fit_into_columns(1); let lined_output = grid.fit_into_columns(1);
print!("{}", lined_output); print!("{}", lined_output);
std::io::stdout() std::io::stdout().flush().expect("Could not flush stdout");
.flush()
.ok()
.expect("Could not flush stdout");
} }
} }
pub fn print_tree_row(&self, output: String, depth: usize, last: bool) { pub fn print_tree_row(&self, output: &ColoredString, depth: usize, last: bool) {
let mut res = String::new(); let mut res = String::new();
for _ in 0..depth { for _ in 0..depth {
@ -88,10 +83,7 @@ impl Display {
} }
print!("{}", res); print!("{}", res);
std::io::stdout() std::io::stdout().flush().expect("Could not flush stdout");
.flush()
.ok()
.expect("Could not flush stdout");
} }
fn get_visible_width(&self, input: &str) -> usize { fn get_visible_width(&self, input: &str) -> usize {

View file

@ -21,10 +21,10 @@ const ICON_SPACE: &str = " ";
// s#\\u[0-9a-f]*#\=eval('"'.submatch(0).'"')# // s#\\u[0-9a-f]*#\=eval('"'.submatch(0).'"')#
impl Icons { impl Icons {
pub fn new(theme: Theme) -> Self { pub fn new(theme: Theme) -> Self {
Icons { Self {
display_icons: theme == Theme::Default, display_icons: theme == Theme::Default,
icons_by_name: Icons::get_default_icons_by_name(), icons_by_name: Self::get_default_icons_by_name(),
icons_by_extension: Icons::get_default_icons_by_extension(), icons_by_extension: Self::get_default_icons_by_extension(),
} }
} }
@ -50,8 +50,8 @@ impl Icons {
if res.is_empty() { if res.is_empty() {
// Use the default icons. // Use the default icons.
res += match name.file_type() { res += match name.file_type() {
FileType::Directory => "", FileType::Directory => "\u{f115}", // 
_ => "", _ => "\u{f016}", // 
}; };
} }
@ -62,28 +62,27 @@ impl Icons {
fn get_default_icons_by_name() -> HashMap<&'static str, &'static str> { fn get_default_icons_by_name() -> HashMap<&'static str, &'static str> {
let mut m = HashMap::new(); let mut m = HashMap::new();
m.insert(".Trash", ""); m.insert(".Trash", "\u{f1f8}"); // ""
m.insert(".atom", ""); m.insert(".atom", "\u{e764}"); // ""
m.insert(".git", ""); m.insert(".git", "\u{f1d3}"); // ""
m.insert(".github", ""); m.insert(".github", "\u{f408}"); // ""
m.insert(".rvm", ""); m.insert(".rvm", "\u{e21e}"); // ""
m.insert(".vscode", ""); m.insert(".vscode", "\u{e70c}"); // ""
m.insert("bin", ""); m.insert("bin", "\u{e5fc}"); // ""
m.insert("config", ""); m.insert("config", "\u{e5fc}"); // ""
m.insert("ds_store", ""); m.insert("ds_store", "\u{f179}"); // ""
m.insert("folder", ""); m.insert("gitconfig", "\u{f1d3}"); // ""
m.insert("gitconfig", ""); m.insert("gitignore", "\u{f1d3}"); // ""
m.insert("gitignore", ""); m.insert("gitignore_global", "\u{f1d3}"); // ""
m.insert("gitignore_global", ""); m.insert("gradle", "\u{e70e}"); // ""
m.insert("gradle", ""); m.insert("hidden", "\u{f023}"); // ""
m.insert("hidden", ""); m.insert("include", "\u{e5fc}"); // ""
m.insert("include", ""); m.insert("lib", "\u{f121}"); // ""
m.insert("lib", ""); m.insert("localized", "\u{f179}"); // ""
m.insert("localized", ""); m.insert("node_modules", "\u{e718}"); // ""
m.insert("node_modules", ""); m.insert("npmignore", "\u{e71e}"); // ""
m.insert("npmignore", ""); m.insert("rubydoc", "\u{e73b}"); // ""
m.insert("rubydoc", ""); m.insert("yarn.lock", "\u{e718}"); // ""
m.insert("yarn.lock", "");
m m
} }
@ -91,191 +90,186 @@ impl Icons {
fn get_default_icons_by_extension() -> HashMap<&'static str, &'static str> { fn get_default_icons_by_extension() -> HashMap<&'static str, &'static str> {
let mut m = HashMap::new(); let mut m = HashMap::new();
m.insert("ai", ""); m.insert("apk", "\u{e70e}"); // ""
m.insert("apk", ""); m.insert("apk", "\u{e70e}"); // ""
m.insert("apk", ""); m.insert("avi", "\u{f03d}"); // ""
m.insert("avi", ""); m.insert("avro", "\u{e60b}"); // ""
m.insert("avro", ""); m.insert("bash", "\u{f489}"); // ""
m.insert("bash", ""); m.insert("bash_history", "\u{f489}"); // ""
m.insert("bash_history", ""); m.insert("bash_profile", "\u{f489}"); // ""
m.insert("bash_profile", ""); m.insert("bashrc", "\u{f489}"); // ""
m.insert("bashrc", ""); m.insert("bat", "\u{f17a}"); // ""
m.insert("bat", ""); m.insert("bmp", "\u{f1c5}"); // ""
m.insert("bmp", ""); m.insert("bmp", "\u{f1c5}"); // ""
m.insert("bmp", ""); m.insert("c", "\u{e61e}"); // ""
m.insert("c", ""); m.insert("cfg", "\u{e615}"); // ""
m.insert("cfg", ""); m.insert("clj", "\u{e768}"); // ""
m.insert("clj", ""); m.insert("cls", "\u{e600}"); // ""
m.insert("cls", ""); m.insert("coffee", "\u{f0f4}"); // ""
m.insert("coffee", ""); m.insert("conf", "\u{e615}"); // ""
m.insert("conf", ""); m.insert("cpp", "\u{e61d}"); // ""
m.insert("cpp", ""); m.insert("css", "\u{e749}"); // ""
m.insert("css", ""); m.insert("csv", "\u{f1c3}"); // ""
m.insert("csv", ""); m.insert("d", "\u{e7af}"); // ""
m.insert("d", ""); m.insert("dart", "\u{e798}"); // ""
m.insert("dart", ""); m.insert("db", "\u{f1c0}"); // ""
m.insert("db", ""); m.insert("diff", "\u{f440}"); // ""
m.insert("diff", ""); m.insert("doc", "\u{f1c2}"); // ""
m.insert("doc", ""); m.insert("docx", "\u{f1c2}"); // ""
m.insert("docx", ""); m.insert("docx", "\u{f1c2}"); // ""
m.insert("docx", ""); m.insert("ds_store", "\u{f179}"); // ""
m.insert("ds_store", ""); m.insert("ds_store", "\u{f179}"); // ""
m.insert("ds_store", ""); m.insert("ebook", "\u{e28b}"); // ""
m.insert("ebook", ""); m.insert("editorconfig", "\u{e615}"); // ""
m.insert("editorconfig", ""); m.insert("env", "\u{f462}"); // ""
m.insert("env", ""); m.insert("eot", "\u{f031}"); // ""
m.insert("eot", ""); m.insert("eot", "\u{f031}"); // ""
m.insert("eot", ""); m.insert("epub", "\u{e28a}"); // ""
m.insert("epub", ""); m.insert("erb", "\u{e73b}"); // ""
m.insert("erb", ""); m.insert("erl", "\u{e7b1}"); // ""
m.insert("erl", ""); m.insert("exe", "\u{f17a}"); // ""
m.insert("exe", ""); m.insert("fish", "\u{f489}"); // ""
m.insert("file", ""); m.insert("flac", "\u{f001}"); // ""
m.insert("fish", ""); m.insert("flac", "\u{f001}"); // ""
m.insert("flac", ""); m.insert("flv", "\u{f03d}"); // ""
m.insert("flac", ""); m.insert("font", "\u{f031}"); // ""
m.insert("flv", ""); m.insert("gdoc", "\u{f1c2}"); // ""
m.insert("font", ""); m.insert("gdoc", "\u{f1c2}"); // ""
m.insert("gdoc", ""); m.insert("gemfile", "\u{e21e}"); // ""
m.insert("gdoc", ""); m.insert("gemspec", "\u{e21e}"); // ""
m.insert("gemfile", ""); m.insert("gform", "\u{f298}"); // ""
m.insert("gemspec", ""); m.insert("gif", "\u{f1c5}"); // ""
m.insert("gform", ""); m.insert("gif", "\u{f1c5}"); // ""
m.insert("gif", ""); m.insert("git", "\u{f1d3}"); // ""
m.insert("gif", ""); m.insert("go", "\u{e626}"); // ""
m.insert("git", ""); m.insert("gradle", "\u{e70e}"); // ""
m.insert("go", ""); m.insert("gsheet", "\u{f1c3}"); // ""
m.insert("gradle", ""); m.insert("gslides", "\u{f1c4}"); // ""
m.insert("gradle", ""); m.insert("guardfile", "\u{e21e}"); // ""
m.insert("gsheet", ""); m.insert("gz", "\u{f410}"); // ""
m.insert("gslides", ""); m.insert("hs", "\u{e777}"); // ""
m.insert("guardfile", ""); m.insert("htm", "\u{f13b}"); // ""
m.insert("gz", ""); m.insert("html", "\u{f13b}"); // ""
m.insert("hs", ""); m.insert("ico", "\u{f1c5}"); // ""
m.insert("htm", ""); m.insert("ico", "\u{f1c5}"); // ""
m.insert("html", ""); m.insert("image", "\u{f1c5}"); // ""
m.insert("ico", ""); m.insert("iml", "\u{e7b5}"); // ""
m.insert("ico", ""); m.insert("ini", "\u{f17a}"); // ""
m.insert("image", ""); m.insert("ipynb", "\u{e606}"); // ""
m.insert("iml", ""); m.insert("jar", "\u{e204}"); // ""
m.insert("ini", ""); m.insert("java", "\u{e204}"); // ""
m.insert("ipynb", ""); m.insert("jpeg", "\u{f1c5}"); // ""
m.insert("jar", ""); m.insert("jpeg", "\u{f1c5}"); // ""
m.insert("jar", ""); m.insert("jpg", "\u{f1c5}"); // ""
m.insert("java", ""); m.insert("jpg", "\u{f1c5}"); // ""
m.insert("jpeg", ""); m.insert("js", "\u{e74e}"); // ""
m.insert("jpeg", ""); m.insert("json", "\u{e60b}"); // ""
m.insert("jpg", ""); m.insert("jsx", "\u{e7ba}"); // ""
m.insert("jpg", ""); m.insert("less", "\u{e758}"); // ""
m.insert("js", ""); m.insert("lhs", "\u{e777}"); // ""
m.insert("json", ""); m.insert("lhs", "\u{e777}"); // ""
m.insert("jsx", ""); m.insert("license", "\u{f48a}"); // ""
m.insert("less", ""); m.insert("localized", "\u{f179}"); // ""
m.insert("lhs", ""); m.insert("localized", "\u{f179}"); // ""
m.insert("lhs", ""); m.insert("lock", "\u{e21e}"); // ""
m.insert("license", ""); m.insert("log", "\u{f18d}"); // ""
m.insert("localized", ""); m.insert("lua", "\u{e620}"); // ""
m.insert("localized", ""); m.insert("m4a", "\u{f001}"); // ""
m.insert("lock", ""); m.insert("m4a", "\u{f001}"); // ""
m.insert("log", ""); m.insert("markdown", "\u{f48a}"); // ""
m.insert("lua", ""); m.insert("md", "\u{f48a}"); // ""
m.insert("m4a", ""); m.insert("mkd", "\u{f48a}"); // ""
m.insert("m4a", ""); m.insert("mkv", "\u{f03d}"); // ""
m.insert("markdown", ""); m.insert("mobi", "\u{e28b}"); // ""
m.insert("md", ""); m.insert("mobi", "\u{e28b}"); // ""
m.insert("mkd", ""); m.insert("mov", "\u{f03d}"); // ""
m.insert("mkv", ""); m.insert("mp3", "\u{f001}"); // ""
m.insert("mobi", ""); m.insert("mp3", "\u{f001}"); // ""
m.insert("mobi", ""); m.insert("mp4", "\u{f03d}"); // ""
m.insert("mov", ""); m.insert("mustache", "\u{e60f}"); // ""
m.insert("mp3", ""); m.insert("npmignore", "\u{e71e}"); // ""
m.insert("mp3", ""); m.insert("ogg", "\u{f001}"); // ""
m.insert("mp4", ""); m.insert("ogg", "\u{f001}"); // ""
m.insert("mustache", ""); m.insert("ogv", "\u{f03d}"); // ""
m.insert("npmignore", ""); m.insert("otf", "\u{f031}"); // ""
m.insert("ogg", ""); m.insert("otf", "\u{f031}"); // ""
m.insert("ogg", ""); m.insert("pdf", "\u{f1c1}"); // ""
m.insert("ogv", ""); m.insert("php", "\u{e73d}"); // ""
m.insert("otf", ""); m.insert("pl", "\u{e769}"); // ""
m.insert("otf", ""); m.insert("png", "\u{f1c5}"); // ""
m.insert("pdf", ""); m.insert("png", "\u{f1c5}"); // ""
m.insert("php", ""); m.insert("ppt", "\u{f1c4}"); // ""
m.insert("pl", ""); m.insert("pptx", "\u{f1c4}"); // ""
m.insert("png", ""); m.insert("procfile", "\u{e21e}"); // ""
m.insert("png", ""); m.insert("properties", "\u{e60b}"); // ""
m.insert("ppt", ""); m.insert("psd", "\u{e7b8}"); // ""
m.insert("pptx", ""); m.insert("pxm", "\u{f1c5}"); // ""
m.insert("procfile", ""); m.insert("pxm", "\u{f1c5}"); // ""
m.insert("properties", ""); m.insert("py", "\u{e606}"); // ""
m.insert("psd", ""); m.insert("pyc", "\u{e606}"); // ""
m.insert("pxm", ""); m.insert("r", "\u{f25d}"); // ""
m.insert("pxm", ""); m.insert("rakefile", "\u{e21e}"); // ""
m.insert("py", ""); m.insert("rar", "\u{f410}"); // ""
m.insert("pyc", ""); m.insert("rb", "\u{e21e}"); // ""
m.insert("r", ""); m.insert("rdata", "\u{f25d}"); // ""
m.insert("rakefile", ""); m.insert("rdb", "\u{e76d}"); // ""
m.insert("rar", ""); m.insert("rdoc", "\u{f48a}"); // ""
m.insert("rb", ""); m.insert("rdoc", "\u{f48a}"); // ""
m.insert("rdata", ""); m.insert("rds", "\u{f25d}"); // ""
m.insert("rdb", ""); m.insert("readme", "\u{f48a}"); // ""
m.insert("rdoc", ""); m.insert("rs", "\u{e7a8}"); // ""
m.insert("rdoc", ""); m.insert("rspec", "\u{e21e}"); // ""
m.insert("rds", ""); m.insert("rspec_parallel", "\u{e21e}"); // ""
m.insert("readme", ""); m.insert("rspec_status", "\u{e21e}"); // ""
m.insert("rs", ""); m.insert("rss", "\u{f09e}"); // ""
m.insert("rspec", ""); m.insert("ru", "\u{e21e}"); // ""
m.insert("rspec_parallel", ""); m.insert("rubydoc", "\u{e73b}"); // ""
m.insert("rspec_status", ""); m.insert("sass", "\u{e603}"); // ""
m.insert("rss", ""); m.insert("scala", "\u{e737}"); // ""
m.insert("ru", ""); m.insert("scss", "\u{e749}"); // ""
m.insert("rubydoc", ""); m.insert("scss", "\u{e749}"); // ""
m.insert("sass", ""); m.insert("sh", "\u{f489}"); // ""
m.insert("scala", ""); m.insert("shell", "\u{f489}"); // ""
m.insert("scss", ""); m.insert("slim", "\u{e73b}"); // ""
m.insert("scss", ""); m.insert("sqlite3", "\u{e7c4}"); // ""
m.insert("sh", ""); m.insert("styl", "\u{e600}"); // ""
m.insert("shell", ""); m.insert("stylus", "\u{e600}"); // ""
m.insert("slim", ""); m.insert("svg", "\u{f1c5}"); // ""
m.insert("sqlite3", ""); m.insert("svg", "\u{f1c5}"); // ""
m.insert("styl", ""); m.insert("swift", "\u{e755}"); // ""
m.insert("stylus", ""); m.insert("tar", "\u{f410}"); // ""
m.insert("svg", ""); m.insert("tex", "\u{e600}"); // ""
m.insert("svg", ""); m.insert("tiff", "\u{f1c5}"); // ""
m.insert("swift", ""); m.insert("tiff", "\u{f1c5}"); // ""
m.insert("tar", ""); m.insert("ts", "\u{e628}"); // ""
m.insert("tex", ""); m.insert("tsx", "\u{e7ba}"); // ""
m.insert("tiff", ""); m.insert("ttf", "\u{f031}"); // ""
m.insert("tiff", ""); m.insert("ttf", "\u{f031}"); // ""
m.insert("ts", ""); m.insert("twig", "\u{e61c}"); // ""
m.insert("tsx", ""); m.insert("txt", "\u{f15c}"); // ""
m.insert("tsx", ""); m.insert("video", "\u{f03d}"); // ""
m.insert("ttf", ""); m.insert("vim", "\u{e62b}"); // ""
m.insert("ttf", ""); m.insert("wav", "\u{f001}"); // ""
m.insert("twig", ""); m.insert("wav", "\u{f001}"); // ""
m.insert("txt", ""); m.insert("webm", "\u{f03d}"); // ""
m.insert("video", ""); m.insert("webp", "\u{f1c5}"); // ""
m.insert("vim", ""); m.insert("webp", "\u{f1c5}"); // ""
m.insert("wav", ""); m.insert("windows", "\u{f17a}"); // ""
m.insert("wav", ""); m.insert("woff", "\u{f031}"); // ""
m.insert("webm", ""); m.insert("woff", "\u{f031}"); // ""
m.insert("webp", ""); m.insert("woff2", "\u{f031}"); // ""
m.insert("webp", ""); m.insert("woff2", "\u{f031}"); // ""
m.insert("windows", ""); m.insert("xls", "\u{f1c3}"); // ""
m.insert("woff", ""); m.insert("xlsx", "\u{f1c3}"); // ""
m.insert("woff", ""); m.insert("xml", "\u{e619}"); // ""
m.insert("woff2", ""); m.insert("xul", "\u{e619}"); // ""
m.insert("woff2", ""); m.insert("yaml", "\u{f481}"); // ""
m.insert("xls", ""); m.insert("yarn.lock", "\u{e718}"); // ""
m.insert("xlsx", ""); m.insert("yml", "\u{f481}"); // ""
m.insert("xml", ""); m.insert("zip", "\u{f410}"); // ""
m.insert("xul", ""); m.insert("zsh", "\u{f489}"); // ""
m.insert("yaml", ""); m.insert("zsh-theme", "\u{f489}"); // ""
m.insert("yarn.lock", ""); m.insert("zshrc", "\u{f489}"); // ""
m.insert("yml", "");
m.insert("zip", "");
m.insert("zsh", "");
m.insert("zsh-theme", "");
m.insert("zshrc", "");
m m
} }

View file

@ -1,3 +1,9 @@
#![allow(
clippy::cast_precision_loss,
clippy::cast_sign_loss,
clippy::match_same_arms
)]
#![warn(clippy::cast_possible_wrap)]
#[macro_use] #[macro_use]
extern crate clap; extern crate clap;
extern crate ansi_term; extern crate ansi_term;
@ -24,7 +30,7 @@ use flags::Flags;
use std::path::PathBuf; use std::path::PathBuf;
fn main() { fn main() {
let matches = app::build_app().get_matches(); let matches = app::build().get_matches();
let inputs = matches let inputs = matches
.values_of("FILE") .values_of("FILE")

View file

@ -54,7 +54,7 @@ impl Meta {
let file_type = FileType::new(&metadata, &permissions); let file_type = FileType::new(&metadata, &permissions);
let name = Name::new(&path, file_type); let name = Name::new(&path, file_type);
Some(Meta { Some(Self {
path: path.to_path_buf(), path: path.to_path_buf(),
symlink: SymLink::from(path.as_path()), symlink: SymLink::from(path.as_path()),
size: Size::from(&metadata), size: Size::from(&metadata),

View file

@ -28,7 +28,7 @@ impl Name {
); );
} }
Name { Self {
name, name,
extension, extension,
file_type, file_type,
@ -72,19 +72,19 @@ impl Name {
} }
impl Ord for Name { impl Ord for Name {
fn cmp(&self, other: &Name) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
self.name.cmp(&other.name) self.name.cmp(&other.name)
} }
} }
impl PartialOrd for Name { impl PartialOrd for Name {
fn partial_cmp(&self, other: &Name) -> Option<Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.name.to_lowercase().cmp(&other.name.to_lowercase())) Some(self.name.to_lowercase().cmp(&other.name.to_lowercase()))
} }
} }
impl PartialEq for Name { impl PartialEq for Name {
fn eq(&self, other: &Name) -> bool { fn eq(&self, other: &Self) -> bool {
self.name.eq_ignore_ascii_case(&other.name) self.name.eq_ignore_ascii_case(&other.name)
} }
} }

View file

@ -23,7 +23,7 @@ impl<'a> From<&'a Metadata> for Owner {
.to_string_lossy() .to_string_lossy()
.to_string(); .to_string();
Owner { user, group } Self { user, group }
} }
} }

View file

@ -27,7 +27,7 @@ impl<'a> From<&'a Metadata> for Permissions {
let bits = meta.permissions().mode(); let bits = meta.permissions().mode();
let has_bit = |bit| bits & bit == bit; let has_bit = |bit| bits & bit == bit;
Permissions { Self {
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),

View file

@ -13,7 +13,7 @@ pub enum Unit {
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct Size { pub struct Size {
value: i64, value: u64,
unit: Unit, unit: Unit,
} }
@ -22,9 +22,9 @@ impl<'a> From<&'a Metadata> for Size {
let len = meta.len(); let len = meta.len();
if meta.is_file() { if meta.is_file() {
Size::from_bytes(len as i64) Self::from_bytes(len)
} else { } else {
Size { Self {
value: 0, value: 0,
unit: Unit::None, unit: Unit::None,
} }
@ -33,29 +33,29 @@ impl<'a> From<&'a Metadata> for Size {
} }
impl Size { impl Size {
fn from_bytes(len: i64) -> Self { fn from_bytes(len: u64) -> Self {
if len < 1024 { if len < 1024 {
Size { Self {
value: len * 1024, value: len * 1024,
unit: Unit::Byte, unit: Unit::Byte,
} }
} else if len < 1024 * 1024 { } else if len < 1024 * 1024 {
Size { Self {
value: len, value: len,
unit: Unit::Kilo, unit: Unit::Kilo,
} }
} else if len < 1024 * 1024 * 1024 { } else if len < 1024 * 1024 * 1024 {
Size { Self {
value: len / 1024, value: len / 1024,
unit: Unit::Mega, unit: Unit::Mega,
} }
} else if len < 1024 * 1024 * 1024 * 1024 { } else if len < 1024 * 1024 * 1024 * 1024 {
Size { Self {
value: len / (1024 * 1024), value: len / (1024 * 1024),
unit: Unit::Giga, unit: Unit::Giga,
} }
} else { } else {
Size { Self {
value: len / (1024 * 1024 * 1024), value: len / (1024 * 1024 * 1024),
unit: Unit::Tera, unit: Unit::Tera,
} }
@ -103,7 +103,7 @@ impl Size {
pub fn render_value(&self) -> String { pub fn render_value(&self) -> String {
let size_str = match self.unit { let size_str = match self.unit {
Unit::None => "".to_string(), Unit::None => "".to_string(),
_ => (self.value as f32 / 1024.0).to_string(), _ => (self.value as f64 / 1024.0).to_string(),
}; };
// Check if there is a fraction. // Check if there is a fraction.

View file

@ -13,7 +13,7 @@ impl<'a> From<&'a Path> for SymLink {
fn from(path: &'a Path) -> Self { fn from(path: &'a Path) -> Self {
if let Ok(target) = read_link(path) { if let Ok(target) = read_link(path) {
if target.is_absolute() || path.parent() == None { if target.is_absolute() || path.parent() == None {
return SymLink { return Self {
valid: target.exists(), valid: target.exists(),
target: Some( target: Some(
target target
@ -24,7 +24,7 @@ impl<'a> From<&'a Path> for SymLink {
}; };
} }
return SymLink { return Self {
target: Some( target: Some(
target target
.to_str() .to_str()
@ -35,7 +35,7 @@ impl<'a> From<&'a Path> for SymLink {
}; };
} }
SymLink { Self {
target: None, target: None,
valid: false, valid: false,
} }
@ -52,7 +52,7 @@ impl SymLink {
}; };
let strings: &[ColoredString] = &[ let strings: &[ColoredString] = &[
ColoredString::from(" "), ColoredString::from(" \u{21d2} "), // ⇒
colors.colorize(target.to_string(), elem), colors.colorize(target.to_string(), elem),
]; ];