Various unimportant style changes

This commit is contained in:
Ben S 2015-06-08 21:33:39 +01:00
parent 549f59092c
commit 2d8a9b49be
16 changed files with 110 additions and 79 deletions

View File

@ -1,7 +1,6 @@
use ansi_term::Style; use ansi_term::Style;
use ansi_term::Colour::{Red, Green, Yellow, Blue, Cyan, Purple, Fixed}; use ansi_term::Colour::{Red, Green, Yellow, Blue, Cyan, Purple, Fixed};
use std::default::Default;
#[derive(Clone, Copy, Debug, Default, PartialEq)] #[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Colours { pub struct Colours {

View File

@ -1,10 +1,9 @@
use std::iter::repeat; use std::iter::repeat;
use options::{SizeFormat, TimeType};
use ansi_term::Style; use ansi_term::Style;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use options::{SizeFormat, TimeType};
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Debug, Copy, Clone)]

View File

@ -1,10 +1,11 @@
use feature::Git;
use file::{File, fields};
use std::io; use std::io;
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use feature::Git;
use file::{File, fields};
/// A **Dir** provides a cached list of the file paths in a directory that's /// A **Dir** provides a cached list of the file paths in a directory that's
/// being listed. /// being listed.
/// ///

View File

@ -4,6 +4,7 @@ use git2;
use file::fields; use file::fields;
/// Container of Git statuses for all the files in this folder's Git repository. /// Container of Git statuses for all the files in this folder's Git repository.
pub struct Git { pub struct Git {
statuses: Vec<(PathBuf, git2::Status)>, statuses: Vec<(PathBuf, git2::Status)>,

View File

@ -8,6 +8,8 @@
#[cfg(not(any(target_os = "macos", target_os = "linux")))] use std::old_io as io; #[cfg(not(any(target_os = "macos", target_os = "linux")))] use std::old_io as io;
#[cfg(not(any(target_os = "macos", target_os = "linux")))] #[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[derive(Clone)] #[derive(Clone)]
pub struct Attribute; pub struct Attribute;
@ -38,7 +40,6 @@ impl Attribute {
} }
// Git support // Git support
#[cfg(feature="git")] mod git; #[cfg(feature="git")] mod git;
@ -47,6 +48,7 @@ impl Attribute {
#[cfg(not(feature="git"))] pub struct Git; #[cfg(not(feature="git"))] pub struct Git;
#[cfg(not(feature="git"))] use std::path::Path; #[cfg(not(feature="git"))] use std::path::Path;
#[cfg(not(feature="git"))] use file::fields; #[cfg(not(feature="git"))] use file::fields;
#[cfg(not(feature="git"))] #[cfg(not(feature="git"))]
impl Git { impl Git {
pub fn scan(_: &Path) -> Result<Git, ()> { pub fn scan(_: &Path) -> Result<Git, ()> {

View File

@ -2,17 +2,20 @@
extern crate libc; extern crate libc;
use std::io; use std::io;
use std::mem;
use std::path::Path; use std::path::Path;
use std::ptr; use std::ptr;
use std::mem;
use self::libc::{c_int, size_t, ssize_t, c_char, c_void, uint32_t}; use self::libc::{c_int, size_t, ssize_t, c_char, c_void, uint32_t};
/// Don't follow symbolic links /// Don't follow symbolic links
const XATTR_NOFOLLOW: c_int = 0x0001; const XATTR_NOFOLLOW: c_int = 0x0001;
/// Expose HFS Compression extended attributes /// Expose HFS Compression extended attributes
const XATTR_SHOWCOMPRESSION: c_int = 0x0020; const XATTR_SHOWCOMPRESSION: c_int = 0x0020;
extern "C" { extern "C" {
fn listxattr(path: *const c_char, namebuf: *mut c_char, fn listxattr(path: *const c_char, namebuf: *mut c_char,
size: size_t, options: c_int) -> ssize_t; size: size_t, options: c_int) -> ssize_t;
@ -21,6 +24,7 @@ extern "C" {
options: c_int) -> ssize_t; options: c_int) -> ssize_t;
} }
/// Attributes which can be passed to `Attribute::list_with_flags` /// Attributes which can be passed to `Attribute::list_with_flags`
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum ListFlags { pub enum ListFlags {
@ -30,6 +34,7 @@ pub enum ListFlags {
ShowCompression = XATTR_SHOWCOMPRESSION as isize ShowCompression = XATTR_SHOWCOMPRESSION as isize
} }
/// Extended attribute /// Extended attribute
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Attribute { pub struct Attribute {

View File

@ -5,8 +5,10 @@ use std::ffi::CString;
use std::io; use std::io;
use std::path::Path; use std::path::Path;
use std::ptr; use std::ptr;
use self::libc::{size_t, ssize_t, c_char, c_void}; use self::libc::{size_t, ssize_t, c_char, c_void};
extern "C" { extern "C" {
fn listxattr(path: *const c_char, list: *mut c_char, size: size_t) -> ssize_t; fn listxattr(path: *const c_char, list: *mut c_char, size: size_t) -> ssize_t;
fn llistxattr(path: *const c_char, list: *mut c_char, size: size_t) -> ssize_t; fn llistxattr(path: *const c_char, list: *mut c_char, size: size_t) -> ssize_t;
@ -18,6 +20,7 @@ extern "C" {
) -> ssize_t; ) -> ssize_t;
} }
/// Attributes which can be passed to `Attribute::list_with_flags` /// Attributes which can be passed to `Attribute::list_with_flags`
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum FollowSymlinks { pub enum FollowSymlinks {
@ -25,6 +28,7 @@ pub enum FollowSymlinks {
No No
} }
/// Extended attribute /// Extended attribute
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Attribute { pub struct Attribute {

View File

@ -423,6 +423,7 @@ fn ext(name: &str) -> Option<String> {
name.rfind('.').map(|p| name[p+1..].to_ascii_lowercase()) name.rfind('.').map(|p| name[p+1..].to_ascii_lowercase())
} }
/// Wrapper types for the values returned from `File` objects. /// Wrapper types for the values returned from `File` objects.
/// ///
/// The methods of `File` don't return formatted strings; neither do they /// The methods of `File` don't return formatted strings; neither do they

View File

@ -3,6 +3,7 @@ use ansi_term::Style;
use file::File; use file::File;
use colours::Colours; use colours::Colours;
pub fn file_colour(colours: &Colours, file: &File) -> Style { pub fn file_colour(colours: &Colours, file: &File) -> Style {
match file { match file {
f if f.is_directory() => colours.filetypes.directory, f if f.is_directory() => colours.filetypes.directory,
@ -23,6 +24,7 @@ pub fn file_colour(colours: &Colours, file: &File) -> Style {
} }
} }
trait FileTypes { trait FileTypes {
fn is_immediate(&self) -> bool; fn is_immediate(&self) -> bool;
fn is_image(&self) -> bool; fn is_image(&self) -> bool;
@ -114,6 +116,7 @@ impl<'_> FileTypes for File<'_> {
} }
} }
#[cfg(broken_test)] #[cfg(broken_test)]
mod test { mod test {
use super::*; use super::*;

View File

@ -11,18 +11,19 @@ extern crate num_cpus;
extern crate number_prefix; extern crate number_prefix;
extern crate pad; extern crate pad;
extern crate threadpool; extern crate threadpool;
extern crate users;
extern crate unicode_width; extern crate unicode_width;
extern crate users;
#[cfg(feature="git")] #[cfg(feature="git")]
extern crate git2; extern crate git2;
use std::env; use std::env;
use std::fs; use std::fs;
use std::path::{Component, Path, PathBuf}; use std::path::{Component, Path, PathBuf};
use std::sync::mpsc::channel;
use threadpool::ThreadPool; use threadpool::ThreadPool;
use std::sync::mpsc::channel;
use dir::Dir; use dir::Dir;
use file::File; use file::File;
@ -183,6 +184,7 @@ impl<'dir> Exa<'dir> {
} }
} }
#[cfg(not(test))] #[cfg(not(test))]
fn main() { fn main() {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();

View File

@ -1,13 +1,5 @@
use colours::Colours; use std::cmp;
use dir::Dir; use std::default;
use file::File;
use column::Column;
use column::Column::*;
use feature::Attribute;
use output::{Grid, Details, Lines};
use term::dimensions;
use std::cmp::Ordering;
use std::fmt; use std::fmt;
use std::num::ParseIntError; use std::num::ParseIntError;
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
@ -15,7 +7,15 @@ use std::os::unix::fs::MetadataExt;
use getopts; use getopts;
use natord; use natord;
use self::Misfire::*; use colours::Colours;
use column::Column;
use column::Column::*;
use dir::Dir;
use feature::Attribute;
use file::File;
use output::{Grid, Details, Lines};
use term::dimensions;
/// The *Options* struct represents a parsed version of the user's /// The *Options* struct represents a parsed version of the user's
/// command-line options. /// command-line options.
@ -26,21 +26,6 @@ pub struct Options {
pub view: View, pub view: View,
} }
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct FileFilter {
list_dirs_first: bool,
reverse: bool,
show_invisibles: bool,
sort_field: SortField,
}
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum View {
Details(Details),
Lines(Lines),
Grid(Grid),
}
impl Options { impl Options {
/// Call getopts on the given slice of command-line strings. /// Call getopts on the given slice of command-line strings.
@ -126,6 +111,15 @@ impl Options {
} }
} }
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct FileFilter {
list_dirs_first: bool,
reverse: bool,
show_invisibles: bool,
sort_field: SortField,
}
impl FileFilter { impl FileFilter {
/// Transform the files (sorting, reversing, filtering) before listing them. /// Transform the files (sorting, reversing, filtering) before listing them.
pub fn transform_files(&self, files: &mut Vec<File>) { pub fn transform_files(&self, files: &mut Vec<File>) {
@ -143,8 +137,8 @@ impl FileFilter {
SortField::AccessedDate => files.sort_by(|a, b| a.metadata.as_raw().atime().cmp(&b.metadata.as_raw().atime())), SortField::AccessedDate => files.sort_by(|a, b| a.metadata.as_raw().atime().cmp(&b.metadata.as_raw().atime())),
SortField::CreatedDate => files.sort_by(|a, b| a.metadata.as_raw().ctime().cmp(&b.metadata.as_raw().ctime())), SortField::CreatedDate => files.sort_by(|a, b| a.metadata.as_raw().ctime().cmp(&b.metadata.as_raw().ctime())),
SortField::Extension => files.sort_by(|a, b| match a.ext.cmp(&b.ext) { SortField::Extension => files.sort_by(|a, b| match a.ext.cmp(&b.ext) {
Ordering::Equal => natord::compare(&*a.name, &*b.name), cmp::Ordering::Equal => natord::compare(&*a.name, &*b.name),
order => order, order => order,
}), }),
} }
@ -166,7 +160,7 @@ pub enum SortField {
ModifiedDate, AccessedDate, CreatedDate, ModifiedDate, AccessedDate, CreatedDate,
} }
impl Default for SortField { impl default::Default for SortField {
fn default() -> SortField { fn default() -> SortField {
SortField::Name SortField::Name
} }
@ -195,6 +189,7 @@ impl SortField {
} }
} }
/// One of these things could happen instead of listing files. /// One of these things could happen instead of listing files.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub enum Misfire { pub enum Misfire {
@ -227,13 +222,15 @@ pub enum Misfire {
impl Misfire { impl Misfire {
/// The OS return code this misfire should signify. /// The OS return code this misfire should signify.
pub fn error_code(&self) -> i32 { pub fn error_code(&self) -> i32 {
if let Help(_) = *self { 2 } if let Misfire::Help(_) = *self { 2 }
else { 3 } else { 3 }
} }
} }
impl fmt::Display for Misfire { impl fmt::Display for Misfire {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Misfire::*;
match *self { match *self {
InvalidOptions(ref e) => write!(f, "{}", e), InvalidOptions(ref e) => write!(f, "{}", e),
Help(ref text) => write!(f, "{}", text), Help(ref text) => write!(f, "{}", text),
@ -247,14 +244,24 @@ impl fmt::Display for Misfire {
} }
} }
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum View {
Details(Details),
Lines(Lines),
Grid(Grid),
}
impl View { impl View {
pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<View, Misfire> { pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<View, Misfire> {
use self::Misfire::*;
if matches.opt_present("long") { if matches.opt_present("long") {
if matches.opt_present("across") { if matches.opt_present("across") {
Err(Misfire::Useless("across", true, "long")) Err(Useless("across", true, "long"))
} }
else if matches.opt_present("oneline") { else if matches.opt_present("oneline") {
Err(Misfire::Useless("oneline", true, "long")) Err(Useless("oneline", true, "long"))
} }
else { else {
let details = Details { let details = Details {
@ -269,45 +276,45 @@ impl View {
} }
} }
else if matches.opt_present("binary") { else if matches.opt_present("binary") {
Err(Misfire::Useless("binary", false, "long")) Err(Useless("binary", false, "long"))
} }
else if matches.opt_present("bytes") { else if matches.opt_present("bytes") {
Err(Misfire::Useless("bytes", false, "long")) Err(Useless("bytes", false, "long"))
} }
else if matches.opt_present("inode") { else if matches.opt_present("inode") {
Err(Misfire::Useless("inode", false, "long")) Err(Useless("inode", false, "long"))
} }
else if matches.opt_present("links") { else if matches.opt_present("links") {
Err(Misfire::Useless("links", false, "long")) Err(Useless("links", false, "long"))
} }
else if matches.opt_present("header") { else if matches.opt_present("header") {
Err(Misfire::Useless("header", false, "long")) Err(Useless("header", false, "long"))
} }
else if matches.opt_present("blocks") { else if matches.opt_present("blocks") {
Err(Misfire::Useless("blocks", false, "long")) Err(Useless("blocks", false, "long"))
} }
else if cfg!(feature="git") && matches.opt_present("git") { else if cfg!(feature="git") && matches.opt_present("git") {
Err(Misfire::Useless("git", false, "long")) Err(Useless("git", false, "long"))
} }
else if matches.opt_present("time") { else if matches.opt_present("time") {
Err(Misfire::Useless("time", false, "long")) Err(Useless("time", false, "long"))
} }
else if matches.opt_present("tree") { else if matches.opt_present("tree") {
Err(Misfire::Useless("tree", false, "long")) Err(Useless("tree", false, "long"))
} }
else if matches.opt_present("group") { else if matches.opt_present("group") {
Err(Misfire::Useless("group", false, "long")) Err(Useless("group", false, "long"))
} }
else if matches.opt_present("level") && !matches.opt_present("recurse") { else if matches.opt_present("level") && !matches.opt_present("recurse") {
Err(Misfire::Useless2("level", "recurse", "tree")) Err(Useless2("level", "recurse", "tree"))
} }
else if Attribute::feature_implemented() && matches.opt_present("extended") { else if Attribute::feature_implemented() && matches.opt_present("extended") {
Err(Misfire::Useless("extended", false, "long")) Err(Useless("extended", false, "long"))
} }
else if let Some((width, _)) = dimensions() { else if let Some((width, _)) = dimensions() {
if matches.opt_present("oneline") { if matches.opt_present("oneline") {
if matches.opt_present("across") { if matches.opt_present("across") {
Err(Misfire::Useless("across", true, "oneline")) Err(Useless("across", true, "oneline"))
} }
else { else {
let lines = Lines { let lines = Lines {
@ -341,7 +348,6 @@ impl View {
} }
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Debug, Copy, Clone)]
pub enum SizeFormat { pub enum SizeFormat {
DecimalBytes, DecimalBytes,
@ -349,7 +355,7 @@ pub enum SizeFormat {
JustBytes, JustBytes,
} }
impl Default for SizeFormat { impl default::Default for SizeFormat {
fn default() -> SizeFormat { fn default() -> SizeFormat {
SizeFormat::DecimalBytes SizeFormat::DecimalBytes
} }
@ -393,7 +399,7 @@ pub struct TimeTypes {
created: bool, created: bool,
} }
impl Default for TimeTypes { impl default::Default for TimeTypes {
fn default() -> TimeTypes { fn default() -> TimeTypes {
TimeTypes { accessed: false, modified: true, created: false } TimeTypes { accessed: false, modified: true, created: false }
} }
@ -599,12 +605,11 @@ impl Columns {
mod test { mod test {
use super::Options; use super::Options;
use super::Misfire; use super::Misfire;
use super::Misfire::*;
use feature::Attribute; use feature::Attribute;
fn is_helpful<T>(misfire: Result<T, Misfire>) -> bool { fn is_helpful<T>(misfire: Result<T, Misfire>) -> bool {
match misfire { match misfire {
Err(Help(_)) => true, Misfire::Err(Help(_)) => true,
_ => false, _ => false,
} }
} }

View File

@ -1,25 +1,25 @@
use colours::Colours; use colours::Colours;
use column::{Alignment, Column, Cell}; use column::{Alignment, Column, Cell};
use feature::Attribute;
use dir::Dir; use dir::Dir;
use file::File; use feature::Attribute;
use file::fields as f; use file::fields as f;
use file::File;
use options::{Columns, FileFilter, RecurseOptions, SizeFormat}; use options::{Columns, FileFilter, RecurseOptions, SizeFormat};
use users::{OSUsers, Users};
use users::mock::MockUsers;
use super::filename;
use ansi_term::{ANSIString, ANSIStrings, Style}; use ansi_term::{ANSIString, ANSIStrings, Style};
use datetime::local::{LocalDateTime, DatePiece};
use datetime::format::{DateFormat};
use datetime::zoned::{VariableOffset, TimeZone};
use locale; use locale;
use number_prefix::{binary_prefix, decimal_prefix, Prefixed, Standalone, PrefixNames}; use number_prefix::{binary_prefix, decimal_prefix, Prefixed, Standalone, PrefixNames};
use datetime::local::{LocalDateTime, DatePiece}; use users::{OSUsers, Users};
use datetime::format::{DateFormat}; use users::mock::MockUsers;
use datetime::zoned::{VariableOffset, TimeZone};
use super::filename;
/// With the **Details** view, the output gets formatted into columns, with /// With the **Details** view, the output gets formatted into columns, with
@ -97,6 +97,7 @@ impl Details {
} }
} }
struct Row { struct Row {
/// Vector of cells to display. /// Vector of cells to display.
@ -122,6 +123,7 @@ struct Row {
children: bool, children: bool,
} }
/// A **Table** object gets built up by the view as it lists files and /// A **Table** object gets built up by the view as it lists files and
/// directories. /// directories.
pub struct Table<U> { pub struct Table<U> {
@ -427,6 +429,7 @@ impl<U> Table<U> where U: Users {
} }
} }
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Debug, Clone)]
enum TreePart { enum TreePart {

View File

@ -1,11 +1,13 @@
use std::cmp::max;
use std::iter::repeat;
use colours::Colours; use colours::Colours;
use column::Alignment::Left; use column::Alignment::Left;
use file::File; use file::File;
use filetype::file_colour; use filetype::file_colour;
use super::lines::Lines; use super::lines::Lines;
use std::cmp::max;
use std::iter::repeat;
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Debug, Copy, Clone)]
pub struct Grid { pub struct Grid {

View File

@ -1,7 +1,9 @@
use colours::Colours; use colours::Colours;
use file::File; use file::File;
use super::filename; use super::filename;
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub struct Lines { pub struct Lines {
pub colours: Colours, pub colours: Colours,

View File

@ -1,16 +1,18 @@
mod grid; use ansi_term::ANSIStrings;
pub mod details;
mod lines;
use colours::Colours; use colours::Colours;
use file::File; use file::File;
use filetype::file_colour; use filetype::file_colour;
use ansi_term::ANSIStrings;
pub use self::grid::Grid;
pub use self::details::Details; pub use self::details::Details;
pub use self::grid::Grid;
pub use self::lines::Lines; pub use self::lines::Lines;
mod grid;
pub mod details;
mod lines;
pub fn filename(file: &File, colours: &Colours) -> String { pub fn filename(file: &File, colours: &Colours) -> String {
if file.is_link() { if file.is_link() {
symlink_filename(file, colours) symlink_filename(file, colours)

View File

@ -1,6 +1,6 @@
mod c { mod c {
pub use libc::{c_int, c_ushort, c_ulong, STDOUT_FILENO};
use std::mem::zeroed; use std::mem::zeroed;
use libc::{c_int, c_ushort, c_ulong, STDOUT_FILENO};
// Getting the terminal size is done using an ioctl command that // Getting the terminal size is done using an ioctl command that
// takes the file handle to the terminal (which in our case is // takes the file handle to the terminal (which in our case is