Move columns to options object

This commit is contained in:
Ben S 2014-05-25 19:42:31 +01:00
parent cb6dd57ca0
commit 566ed0bba8
3 changed files with 14 additions and 13 deletions

View File

@ -5,13 +5,3 @@ pub enum Column {
User, User,
Group, Group,
} }
pub fn defaultColumns() -> ~[Column] {
return ~[
Permissions,
FileSize(false),
User,
Group,
FileName,
];
}

5
exa.rs
View File

@ -6,7 +6,6 @@ use std::os;
use std::io::fs; use std::io::fs;
use file::File; use file::File;
use column::defaultColumns;
use options::Options; use options::Options;
pub mod colours; pub mod colours;
@ -50,7 +49,7 @@ fn exa(options: &Options, path: Path) {
files.reverse(); files.reverse();
} }
let columns = defaultColumns(); let columns = options.columns();
let table: Vec<Vec<StrBuf>> = files.iter() let table: Vec<Vec<StrBuf>> = files.iter()
.filter(|&f| options.show(f)) .filter(|&f| options.show(f))
@ -58,7 +57,7 @@ fn exa(options: &Options, path: Path) {
.collect(); .collect();
let lengths: Vec<Vec<uint>> = table.iter() let lengths: Vec<Vec<uint>> = table.iter()
.map(|row| row.iter().map( |col| colours::strip_formatting(col).len() ).collect()) .map(|row| row.iter().map(|col| colours::strip_formatting(col).len() ).collect())
.collect(); .collect();
let maxes: Vec<uint> = range(0, columns.len()) let maxes: Vec<uint> = range(0, columns.len())

View File

@ -2,6 +2,7 @@ extern crate getopts;
use file::File; use file::File;
use std::cmp::lexical_ordering; use std::cmp::lexical_ordering;
use column::{Column, Permissions, FileName, FileSize, User, Group};
pub enum SortField { pub enum SortField {
Name, Extension, Size Name, Extension, Size
@ -67,4 +68,15 @@ impl Options {
!f.name.starts_with(".") !f.name.starts_with(".")
} }
} }
pub fn columns(&self) -> ~[Column] {
return ~[
Permissions,
FileSize(false),
User,
Group,
FileName,
];
}
} }