diff --git a/src/feature/git.rs b/src/feature/git.rs index 17ef7d8..1b58b65 100644 --- a/src/feature/git.rs +++ b/src/feature/git.rs @@ -52,12 +52,12 @@ impl Git { /// The character to display if the file has been modified, but not staged. fn working_tree_status(status: git2::Status) -> file::GitStatus { match status { - s if s.contains(git2::STATUS_WT_NEW) => file::GitStatus::New, - s if s.contains(git2::STATUS_WT_MODIFIED) => file::GitStatus::Modified, - s if s.contains(git2::STATUS_WT_DELETED) => file::GitStatus::Deleted, - s if s.contains(git2::STATUS_WT_RENAMED) => file::GitStatus::Renamed, - s if s.contains(git2::STATUS_WT_TYPECHANGE) => file::GitStatus::TypeChange, - _ => file::GitStatus::NotModified, + s if s.contains(git2::STATUS_WT_NEW) => file::GitStatus::New, + s if s.contains(git2::STATUS_WT_MODIFIED) => file::GitStatus::Modified, + s if s.contains(git2::STATUS_WT_DELETED) => file::GitStatus::Deleted, + s if s.contains(git2::STATUS_WT_RENAMED) => file::GitStatus::Renamed, + s if s.contains(git2::STATUS_WT_TYPECHANGE) => file::GitStatus::TypeChange, + _ => file::GitStatus::NotModified, } } @@ -65,11 +65,11 @@ fn working_tree_status(status: git2::Status) -> file::GitStatus { /// has been staged. fn index_status(status: git2::Status) -> file::GitStatus { match status { - s if s.contains(git2::STATUS_INDEX_NEW) => file::GitStatus::New, - s if s.contains(git2::STATUS_INDEX_MODIFIED) => file::GitStatus::Modified, - s if s.contains(git2::STATUS_INDEX_DELETED) => file::GitStatus::Deleted, - s if s.contains(git2::STATUS_INDEX_RENAMED) => file::GitStatus::Renamed, - s if s.contains(git2::STATUS_INDEX_TYPECHANGE) => file::GitStatus::TypeChange, - _ => file::GitStatus::NotModified, + s if s.contains(git2::STATUS_INDEX_NEW) => file::GitStatus::New, + s if s.contains(git2::STATUS_INDEX_MODIFIED) => file::GitStatus::Modified, + s if s.contains(git2::STATUS_INDEX_DELETED) => file::GitStatus::Deleted, + s if s.contains(git2::STATUS_INDEX_RENAMED) => file::GitStatus::Renamed, + s if s.contains(git2::STATUS_INDEX_TYPECHANGE) => file::GitStatus::TypeChange, + _ => file::GitStatus::NotModified, } } diff --git a/src/options.rs b/src/options.rs index fdc2d04..1fb843f 100644 --- a/src/options.rs +++ b/src/options.rs @@ -135,17 +135,17 @@ impl FileFilter { } match self.sort_field { - SortField::Unsorted => {}, - SortField::Name => files.sort_by(|a, b| natord::compare(&*a.name, &*b.name)), - SortField::Size => files.sort_by(|a, b| a.stat.len().cmp(&b.stat.len())), - SortField::FileInode => files.sort_by(|a, b| a.stat.as_raw().ino().cmp(&b.stat.as_raw().ino())), - SortField::Extension => files.sort_by(|a, b| match a.ext.cmp(&b.ext) { - Ordering::Equal => natord::compare(&*a.name, &*b.name), - order => order + SortField::Unsorted => {}, + SortField::Name => files.sort_by(|a, b| natord::compare(&*a.name, &*b.name)), + SortField::Size => files.sort_by(|a, b| a.stat.len().cmp(&b.stat.len())), + SortField::FileInode => files.sort_by(|a, b| a.stat.as_raw().ino().cmp(&b.stat.as_raw().ino())), + SortField::ModifiedDate => files.sort_by(|a, b| a.stat.as_raw().mtime().cmp(&b.stat.as_raw().mtime())), + SortField::AccessedDate => files.sort_by(|a, b| a.stat.as_raw().atime().cmp(&b.stat.as_raw().atime())), + SortField::CreatedDate => files.sort_by(|a, b| a.stat.as_raw().ctime().cmp(&b.stat.as_raw().ctime())), + SortField::Extension => files.sort_by(|a, b| match a.ext.cmp(&b.ext) { + Ordering::Equal => natord::compare(&*a.name, &*b.name), + order => order, }), - SortField::ModifiedDate => files.sort_by(|a, b| a.stat.as_raw().mtime().cmp(&b.stat.as_raw().mtime())), - SortField::AccessedDate => files.sort_by(|a, b| a.stat.as_raw().atime().cmp(&b.stat.as_raw().atime())), - SortField::CreatedDate => files.sort_by(|a, b| a.stat.as_raw().ctime().cmp(&b.stat.as_raw().ctime())), } if self.reverse { @@ -171,15 +171,15 @@ impl SortField { /// Find which field to use based on a user-supplied word. fn from_word(word: String) -> Result { match &word[..] { - "name" | "filename" => Ok(SortField::Name), - "size" | "filesize" => Ok(SortField::Size), - "ext" | "extension" => Ok(SortField::Extension), - "mod" | "modified" => Ok(SortField::ModifiedDate), - "acc" | "accessed" => Ok(SortField::AccessedDate), - "cr" | "created" => Ok(SortField::CreatedDate), - "none" => Ok(SortField::Unsorted), - "inode" => Ok(SortField::FileInode), - field => Err(SortField::none(field)) + "name" | "filename" => Ok(SortField::Name), + "size" | "filesize" => Ok(SortField::Size), + "ext" | "extension" => Ok(SortField::Extension), + "mod" | "modified" => Ok(SortField::ModifiedDate), + "acc" | "accessed" => Ok(SortField::AccessedDate), + "cr" | "created" => Ok(SortField::CreatedDate), + "none" => Ok(SortField::Unsorted), + "inode" => Ok(SortField::FileInode), + field => Err(SortField::none(field)) } } @@ -229,14 +229,14 @@ impl Misfire { impl fmt::Display for Misfire { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - InvalidOptions(ref e) => write!(f, "{}", e), - Help(ref text) => write!(f, "{}", text), - Version => write!(f, "exa {}", env!("CARGO_PKG_VERSION")), - Conflict(a, b) => write!(f, "Option --{} conflicts with option {}.", a, b), - Useless(a, false, b) => write!(f, "Option --{} is useless without option --{}.", a, b), - Useless(a, true, b) => write!(f, "Option --{} is useless given option --{}.", a, b), - Useless2(a, b1, b2) => write!(f, "Option --{} is useless without options --{} or --{}.", a, b1, b2), - FailedParse(ref e) => write!(f, "Failed to parse number: {}", e), + InvalidOptions(ref e) => write!(f, "{}", e), + Help(ref text) => write!(f, "{}", text), + Version => write!(f, "exa {}", env!("CARGO_PKG_VERSION")), + Conflict(a, b) => write!(f, "Option --{} conflicts with option {}.", a, b), + Useless(a, false, b) => write!(f, "Option --{} is useless without option --{}.", a, b), + Useless(a, true, b) => write!(f, "Option --{} is useless given option --{}.", a, b), + Useless2(a, b1, b2) => write!(f, "Option --{} is useless without options --{} or --{}.", a, b1, b2), + FailedParse(ref e) => write!(f, "Failed to parse number: {}", e), } } } @@ -349,10 +349,10 @@ impl SizeFormat { let bytes = matches.opt_present("bytes"); match (binary, bytes) { - (true, true ) => Err(Misfire::Conflict("binary", "bytes")), - (true, false) => Ok(SizeFormat::BinaryBytes), - (false, true ) => Ok(SizeFormat::JustBytes), - (false, false) => Ok(SizeFormat::DecimalBytes), + (true, true ) => Err(Misfire::Conflict("binary", "bytes")), + (true, false) => Ok(SizeFormat::BinaryBytes), + (false, true ) => Ok(SizeFormat::JustBytes), + (false, false) => Ok(SizeFormat::DecimalBytes), } } } @@ -367,9 +367,9 @@ pub enum TimeType { impl TimeType { pub fn header(&self) -> &'static str { match *self { - TimeType::FileAccessed => "Date Accessed", - TimeType::FileModified => "Date Modified", - TimeType::FileCreated => "Date Created", + TimeType::FileAccessed => "Date Accessed", + TimeType::FileModified => "Date Modified", + TimeType::FileCreated => "Date Created", } } } @@ -439,12 +439,12 @@ impl DirAction { let tree = matches.opt_present("tree"); match (recurse, list, tree) { - (true, true, _ ) => Err(Misfire::Conflict("recurse", "list-dirs")), - (_, true, true ) => Err(Misfire::Conflict("tree", "list-dirs")), - (true, false, false) => Ok(DirAction::Recurse(try!(RecurseOptions::deduce(matches, false)))), - (_ , _, true ) => Ok(DirAction::Recurse(try!(RecurseOptions::deduce(matches, true)))), - (false, true, _ ) => Ok(DirAction::AsFile), - (false, false, _ ) => Ok(DirAction::List), + (true, true, _ ) => Err(Misfire::Conflict("recurse", "list-dirs")), + (_, true, true ) => Err(Misfire::Conflict("tree", "list-dirs")), + (true, false, false) => Ok(DirAction::Recurse(try!(RecurseOptions::deduce(matches, false)))), + (_ , _, true ) => Ok(DirAction::Recurse(try!(RecurseOptions::deduce(matches, true)))), + (false, true, _ ) => Ok(DirAction::AsFile), + (false, false, _ ) => Ok(DirAction::List), } } diff --git a/src/output/details.rs b/src/output/details.rs index 07be52f..9be8cab 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -142,7 +142,6 @@ impl Table { users: OSUsers::empty_cache(), colours: colours, current_year: LocalDateTime::now().year(), - } } @@ -173,7 +172,7 @@ impl Table { children: file.this.is_some(), }; - self.rows.push(row) + self.rows.push(row); } /// Use the list of columns to find which cells should be produced for @@ -205,11 +204,11 @@ impl Table { }; let file_type = match permissions.file_type { - Type::File => self.colours.filetypes.normal.paint("."), - Type::Directory => self.colours.filetypes.directory.paint("d"), - Type::Pipe => self.colours.filetypes.special.paint("|"), - Type::Link => self.colours.filetypes.symlink.paint("l"), - Type::Special => self.colours.filetypes.special.paint("?"), + Type::File => self.colours.filetypes.normal.paint("."), + Type::Directory => self.colours.filetypes.directory.paint("d"), + Type::Pipe => self.colours.filetypes.special.paint("|"), + Type::Link => self.colours.filetypes.symlink.paint("l"), + Type::Special => self.colours.filetypes.special.paint("?"), }; let x_colour = if let Type::File = permissions.file_type { c.user_execute_file } @@ -244,8 +243,8 @@ impl Table { fn render_blocks(&self, blocks: Blocks) -> Cell { match blocks { - Blocks::Some(blocks) => Cell::paint(self.colours.blocks, &blocks.to_string()), - Blocks::None => Cell::paint(self.colours.punctuation, "-"), + Blocks::Some(blocks) => Cell::paint(self.colours.blocks, &blocks.to_string()), + Blocks::None => Cell::paint(self.colours.punctuation, "-"), } } @@ -256,14 +255,14 @@ impl Table { fn render_size(&self, size: Size, size_format: SizeFormat) -> Cell { if let Size::Some(offset) = size { let result = match size_format { - SizeFormat::DecimalBytes => decimal_prefix(offset as f64), - SizeFormat::BinaryBytes => binary_prefix(offset as f64), - SizeFormat::JustBytes => return Cell::paint(self.colours.size.numbers, &self.numeric.format_int(offset)), + SizeFormat::DecimalBytes => decimal_prefix(offset as f64), + SizeFormat::BinaryBytes => binary_prefix(offset as f64), + SizeFormat::JustBytes => return Cell::paint(self.colours.size.numbers, &self.numeric.format_int(offset)), }; match result { - Standalone(bytes) => Cell::paint(self.colours.size.numbers, &*bytes.to_string()), - Prefixed(prefix, n) => { + Standalone(bytes) => Cell::paint(self.colours.size.numbers, &*bytes.to_string()), + Prefixed(prefix, n) => { let number = if n < 10f64 { self.numeric.format_float(n, 1) } else { self.numeric.format_int(n as isize) }; let symbol = prefix.symbol(); @@ -295,12 +294,12 @@ impl Table { fn render_git_status(&self, git: Git) -> Cell { let render_char = |chr| { match chr { - GitStatus::NotModified => self.colours.punctuation.paint("-"), - GitStatus::New => self.colours.git.renamed.paint("N"), - GitStatus::Modified => self.colours.git.renamed.paint("M"), - GitStatus::Deleted => self.colours.git.renamed.paint("D"), - GitStatus::Renamed => self.colours.git.renamed.paint("R"), - GitStatus::TypeChange => self.colours.git.renamed.paint("T"), + GitStatus::NotModified => self.colours.punctuation.paint("-"), + GitStatus::New => self.colours.git.renamed.paint("N"), + GitStatus::Modified => self.colours.git.renamed.paint("M"), + GitStatus::Deleted => self.colours.git.renamed.paint("D"), + GitStatus::Renamed => self.colours.git.renamed.paint("R"), + GitStatus::TypeChange => self.colours.git.renamed.paint("T"), } }; @@ -312,8 +311,8 @@ impl Table { fn render_user(&mut self, user: User) -> Cell { let user_name = match self.users.get_user_by_uid(user.0) { - Some(user) => user.name, - None => user.0.to_string(), + Some(user) => user.name, + None => user.0.to_string(), }; let style = if self.users.get_current_uid() == user.0 { self.colours.users.user_you } @@ -416,10 +415,10 @@ enum TreePart { impl TreePart { fn ascii_art(&self) -> &'static str { match *self { - TreePart::Edge => "├──", - TreePart::Line => "│ ", - TreePart::Corner => "└──", - TreePart::Blank => " ", + TreePart::Edge => "├──", + TreePart::Line => "│ ", + TreePart::Corner => "└──", + TreePart::Blank => " ", } } }