diff --git a/exa.rs b/exa.rs index 5878a60..b4d585e 100644 --- a/exa.rs +++ b/exa.rs @@ -45,17 +45,16 @@ fn exa(options: &Options, path: Path) { let unordered_files: Vec = paths.iter().map(|path| File::from_path(path)).collect(); let files: Vec<&File> = options.transform_files(&unordered_files); - let columns = options.columns(); let table: Vec> = files.iter() - .map(|f| columns.iter().map(|c| f.display(c)).collect()) + .map(|f| options.columns.iter().map(|c| f.display(c)).collect()) .collect(); let lengths: Vec> = table.iter() .map(|row| row.iter().map(|col| colours::strip_formatting(col).len()).collect()) .collect(); - let maxes: Vec = range(0, columns.len()) + let maxes: Vec = range(0, options.columns.len()) .map(|n| lengths.iter().map(|row| *row.get(n)).max().unwrap()) .collect(); diff --git a/options.rs b/options.rs index 82ae47a..2cb5793 100644 --- a/options.rs +++ b/options.rs @@ -13,6 +13,7 @@ pub struct Options { pub sortField: SortField, pub reverse: bool, pub dirs: Vec, + pub columns: ~[Column], } impl SortField { @@ -30,6 +31,7 @@ impl Options { pub fn getopts(args: Vec) -> Result { let opts = ~[ getopts::optflag("a", "all", "show dot-files"), + getopts::optflag("b", "binary", "use binary prefixes in file sizes"), getopts::optflag("r", "reverse", "reverse order of files"), getopts::optopt("s", "sort", "field to sort by", "WORD"), ]; @@ -40,11 +42,22 @@ impl Options { showInvisibles: matches.opt_present("all"), reverse: matches.opt_present("reverse"), sortField: matches.opt_str("sort").map(|word| SortField::from_word(word)).unwrap_or(Name), - dirs: matches.free, + dirs: matches.free.clone(), + columns: Options::columns(matches), }) } } + fn columns(matches: getopts::Matches) -> ~[Column] { + return ~[ + Permissions, + FileSize(matches.opt_present("binary")), + User, + Group, + FileName, + ]; + } + fn show(&self, f: &File) -> bool { if self.showInvisibles { true @@ -74,15 +87,4 @@ impl Options { return files; } - - pub fn columns(&self) -> ~[Column] { - return ~[ - Permissions, - FileSize(false), - User, - Group, - FileName, - ]; - } - }