mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-09-28 05:09:01 +00:00
Merge branch 'localisation'
This commit is contained in:
commit
113df66408
57
Cargo.lock
generated
57
Cargo.lock
generated
@ -2,11 +2,11 @@
|
|||||||
name = "exa"
|
name = "exa"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ansi_term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"datetime 0.1.2 (git+https://github.com/ogham/rust-datetime.git)",
|
"datetime 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"datetime_macros 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"getopts 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"getopts 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"git2 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"git2 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"locale 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"natord 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"natord 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"number_prefix 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"number_prefix 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pad 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pad 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -15,7 +15,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ansi_term"
|
name = "ansi_term"
|
||||||
version = "0.4.5"
|
version = "0.4.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"regex 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -29,33 +29,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "datetime"
|
name = "datetime"
|
||||||
version = "0.1.2"
|
version = "0.1.4"
|
||||||
source = "git+https://github.com/ogham/rust-datetime.git#c108628eb3519535821bc7907f2305643465acf5"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"locale 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pad 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pad 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex_macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex_macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "datetime"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"pad 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"regex 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"regex_macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "datetime_macros"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"datetime 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"pad 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gcc"
|
name = "gcc"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
@ -63,7 +45,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getopts"
|
name = "getopts"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -75,7 +57,7 @@ version = "0.1.17"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libgit2-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libgit2-sys 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"url 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
"url 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -86,13 +68,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libgit2-sys"
|
name = "libgit2-sys"
|
||||||
version = "0.1.12"
|
version = "0.1.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libssh2-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libssh2-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libz-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libz-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"openssl-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"openssl-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pkg-config 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pkg-config 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -109,7 +91,7 @@ version = "0.1.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libz-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libz-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"openssl-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"openssl-sys 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pkg-config 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pkg-config 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -121,6 +103,11 @@ dependencies = [
|
|||||||
"pkg-config 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pkg-config 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "locale"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
@ -143,12 +130,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl-sys"
|
name = "openssl-sys"
|
||||||
version = "0.3.3"
|
version = "0.3.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gcc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gcc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libressl-pnacl-sys 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libressl-pnacl-sys 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pkg-config 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pkg-config 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -163,7 +150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -7,9 +7,11 @@ authors = [ "ogham@bsago.me" ]
|
|||||||
name = "exa"
|
name = "exa"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ansi_term = "0.4.5"
|
ansi_term = "0.4.6"
|
||||||
datetime_macros = "0.1.2"
|
datetime = "0.1.3"
|
||||||
|
#datetime_macros = "0.1.2"
|
||||||
getopts = "0.2.1"
|
getopts = "0.2.1"
|
||||||
|
locale = "0.1.2"
|
||||||
natord = "1.0.7"
|
natord = "1.0.7"
|
||||||
number_prefix = "0.2.3"
|
number_prefix = "0.2.3"
|
||||||
pad = "0.1.1"
|
pad = "0.1.1"
|
||||||
@ -22,6 +24,3 @@ git = [ "git2" ]
|
|||||||
[dependencies.git2]
|
[dependencies.git2]
|
||||||
version = "0.1.13"
|
version = "0.1.13"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.datetime]
|
|
||||||
git = "https://github.com/ogham/rust-datetime.git"
|
|
||||||
|
59
src/file.rs
59
src/file.rs
@ -8,12 +8,13 @@ use ansi_term::Colour::{Red, Green, Yellow, Blue, Purple, Cyan, Fixed};
|
|||||||
|
|
||||||
use users::Users;
|
use users::Users;
|
||||||
|
|
||||||
use pad::Alignment;
|
use locale;
|
||||||
|
use output::details::UserLocale;
|
||||||
|
|
||||||
use number_prefix::{binary_prefix, decimal_prefix, Prefixed, Standalone, PrefixNames};
|
use number_prefix::{binary_prefix, decimal_prefix, Prefixed, Standalone, PrefixNames};
|
||||||
|
|
||||||
use datetime;
|
|
||||||
use datetime::local::{LocalDateTime, DatePiece};
|
use datetime::local::{LocalDateTime, DatePiece};
|
||||||
|
use datetime::format::{DateFormat};
|
||||||
|
|
||||||
use column::{Column, Cell};
|
use column::{Column, Cell};
|
||||||
use column::Column::*;
|
use column::Column::*;
|
||||||
@ -97,14 +98,14 @@ impl<'a> File<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the data for a column, formatted as a coloured string.
|
/// Get the data for a column, formatted as a coloured string.
|
||||||
pub fn display<U: Users>(&self, column: &Column, users_cache: &mut U) -> Cell {
|
pub fn display<U: Users>(&self, column: &Column, users_cache: &mut U, locale: &UserLocale) -> Cell {
|
||||||
match *column {
|
match *column {
|
||||||
Permissions => self.permissions_string(),
|
Permissions => self.permissions_string(),
|
||||||
FileSize(f) => self.file_size(f),
|
FileSize(f) => self.file_size(f, &locale.numeric),
|
||||||
Timestamp(t, y) => self.timestamp(t, y),
|
Timestamp(t, y) => self.timestamp(t, y, &locale.time),
|
||||||
HardLinks => self.hard_links(),
|
HardLinks => self.hard_links(&locale.numeric),
|
||||||
Inode => self.inode(),
|
Inode => self.inode(),
|
||||||
Blocks => self.blocks(),
|
Blocks => self.blocks(&locale.numeric),
|
||||||
User => self.user(users_cache),
|
User => self.user(users_cache),
|
||||||
Group => self.group(users_cache),
|
Group => self.group(users_cache),
|
||||||
GitStatus => self.git_status(),
|
GitStatus => self.git_status(),
|
||||||
@ -202,9 +203,9 @@ impl<'a> File<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This file's number of hard links as a coloured string.
|
/// This file's number of hard links as a coloured string.
|
||||||
fn hard_links(&self) -> Cell {
|
fn hard_links(&self, locale: &locale::Numeric) -> Cell {
|
||||||
let style = if self.has_multiple_links() { Red.on(Yellow) } else { Red.normal() };
|
let style = if self.has_multiple_links() { Red.on(Yellow) } else { Red.normal() };
|
||||||
Cell::paint(style, &*self.stat.unstable.nlink.to_string())
|
Cell::paint(style, &locale.format_int(self.stat.unstable.nlink as isize)[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether this is a regular file with more than one link.
|
/// Whether this is a regular file with more than one link.
|
||||||
@ -222,9 +223,9 @@ impl<'a> File<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This file's number of filesystem blocks (if available) as a coloured string.
|
/// This file's number of filesystem blocks (if available) as a coloured string.
|
||||||
fn blocks(&self) -> Cell {
|
fn blocks(&self, locale: &locale::Numeric) -> Cell {
|
||||||
if self.stat.kind == io::FileType::RegularFile || self.stat.kind == io::FileType::Symlink {
|
if self.stat.kind == io::FileType::RegularFile || self.stat.kind == io::FileType::Symlink {
|
||||||
Cell::paint(Cyan.normal(), &*self.stat.unstable.blocks.to_string())
|
Cell::paint(Cyan.normal(), &locale.format_int(self.stat.unstable.blocks as isize)[])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Cell { text: GREY.paint("-").to_string(), length: 1 }
|
Cell { text: GREY.paint("-").to_string(), length: 1 }
|
||||||
@ -277,7 +278,7 @@ impl<'a> File<'a> {
|
|||||||
/// some filesystems, I've never looked at one of those numbers and gained
|
/// some filesystems, I've never looked at one of those numbers and gained
|
||||||
/// any information from it, so by emitting "-" instead, the table is less
|
/// any information from it, so by emitting "-" instead, the table is less
|
||||||
/// cluttered with numbers.
|
/// cluttered with numbers.
|
||||||
fn file_size(&self, size_format: SizeFormat) -> Cell {
|
fn file_size(&self, size_format: SizeFormat, locale: &locale::Numeric) -> Cell {
|
||||||
if self.stat.kind == io::FileType::Directory {
|
if self.stat.kind == io::FileType::Directory {
|
||||||
Cell { text: GREY.paint("-").to_string(), length: 1 }
|
Cell { text: GREY.paint("-").to_string(), length: 1 }
|
||||||
}
|
}
|
||||||
@ -285,13 +286,13 @@ impl<'a> File<'a> {
|
|||||||
let result = match size_format {
|
let result = match size_format {
|
||||||
SizeFormat::DecimalBytes => decimal_prefix(self.stat.size as f64),
|
SizeFormat::DecimalBytes => decimal_prefix(self.stat.size as f64),
|
||||||
SizeFormat::BinaryBytes => binary_prefix(self.stat.size as f64),
|
SizeFormat::BinaryBytes => binary_prefix(self.stat.size as f64),
|
||||||
SizeFormat::JustBytes => return Cell::paint(Green.bold(), &*self.stat.size.to_string())
|
SizeFormat::JustBytes => return Cell::paint(Green.bold(), &locale.format_int(self.stat.size as isize)[]),
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Standalone(bytes) => Cell::paint(Green.bold(), &*bytes.to_string()),
|
Standalone(bytes) => Cell::paint(Green.bold(), &*bytes.to_string()),
|
||||||
Prefixed(prefix, n) => {
|
Prefixed(prefix, n) => {
|
||||||
let number = if n < 10f64 { format!("{:.1}", n) } else { format!("{:.0}", n) };
|
let number = if n < 10f64 { locale.format_float(n, 1) } else { locale.format_int(n as isize) };
|
||||||
let symbol = prefix.symbol();
|
let symbol = prefix.symbol();
|
||||||
|
|
||||||
Cell {
|
Cell {
|
||||||
@ -303,7 +304,7 @@ impl<'a> File<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp(&self, time_type: TimeType, current_year: i64) -> Cell {
|
fn timestamp(&self, time_type: TimeType, current_year: i64, locale: &locale::Time) -> Cell {
|
||||||
|
|
||||||
// Need to convert these values from milliseconds into seconds.
|
// Need to convert these values from milliseconds into seconds.
|
||||||
let time_in_seconds = match time_type {
|
let time_in_seconds = match time_type {
|
||||||
@ -315,13 +316,13 @@ impl<'a> File<'a> {
|
|||||||
let date = LocalDateTime::at(time_in_seconds);
|
let date = LocalDateTime::at(time_in_seconds);
|
||||||
|
|
||||||
let format = if date.year() == current_year {
|
let format = if date.year() == current_year {
|
||||||
date_format!("{2>:D} {:M} {2>:h}:{02>:m}")
|
DateFormat::parse("{2>:D} {:M} {2>:h}:{02>:m}").unwrap()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
date_format!("{2>:D} {:M} {4>:Y}")
|
DateFormat::parse("{2>:D} {:M} {4>:Y}").unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
Cell::paint(Blue.normal(), format.format(date).as_slice())
|
Cell::paint(Blue.normal(), format.format(date, locale).as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This file's type, represented by a coloured character.
|
/// This file's type, represented by a coloured character.
|
||||||
@ -445,6 +446,8 @@ pub mod test {
|
|||||||
pub use ansi_term::Style::Plain;
|
pub use ansi_term::Style::Plain;
|
||||||
pub use ansi_term::Colour::Yellow;
|
pub use ansi_term::Colour::Yellow;
|
||||||
|
|
||||||
|
pub use output::details::UserLocale;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn extension() {
|
fn extension() {
|
||||||
assert_eq!(Some("dat".to_string()), super::ext("fester.dat"))
|
assert_eq!(Some("dat".to_string()), super::ext("fester.dat"))
|
||||||
@ -487,6 +490,10 @@ pub mod test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dummy_locale() -> UserLocale {
|
||||||
|
UserLocale::default()
|
||||||
|
}
|
||||||
|
|
||||||
mod users {
|
mod users {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -501,7 +508,7 @@ pub mod test {
|
|||||||
users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
|
users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
|
||||||
|
|
||||||
let cell = Cell::paint(Yellow.bold(), "enoch");
|
let cell = Cell::paint(Yellow.bold(), "enoch");
|
||||||
assert_eq!(cell, file.display(&Column::User, &mut users))
|
assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -514,7 +521,7 @@ pub mod test {
|
|||||||
let mut users = MockUsers::with_current_uid(1000);
|
let mut users = MockUsers::with_current_uid(1000);
|
||||||
|
|
||||||
let cell = Cell::paint(Yellow.bold(), "1000");
|
let cell = Cell::paint(Yellow.bold(), "1000");
|
||||||
assert_eq!(cell, file.display(&Column::User, &mut users))
|
assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -528,7 +535,7 @@ pub mod test {
|
|||||||
users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
|
users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
|
||||||
|
|
||||||
let cell = Cell::paint(Plain, "enoch");
|
let cell = Cell::paint(Plain, "enoch");
|
||||||
assert_eq!(cell, file.display(&Column::User, &mut users))
|
assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -541,7 +548,7 @@ pub mod test {
|
|||||||
let mut users = MockUsers::with_current_uid(3);
|
let mut users = MockUsers::with_current_uid(3);
|
||||||
|
|
||||||
let cell = Cell::paint(Plain, "1000");
|
let cell = Cell::paint(Plain, "1000");
|
||||||
assert_eq!(cell, file.display(&Column::User, &mut users))
|
assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,7 +566,7 @@ pub mod test {
|
|||||||
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] });
|
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] });
|
||||||
|
|
||||||
let cell = Cell::paint(Plain, "folk");
|
let cell = Cell::paint(Plain, "folk");
|
||||||
assert_eq!(cell, file.display(&Column::Group, &mut users))
|
assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -572,7 +579,7 @@ pub mod test {
|
|||||||
let mut users = MockUsers::with_current_uid(3);
|
let mut users = MockUsers::with_current_uid(3);
|
||||||
|
|
||||||
let cell = Cell::paint(Plain, "100");
|
let cell = Cell::paint(Plain, "100");
|
||||||
assert_eq!(cell, file.display(&Column::Group, &mut users))
|
assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -587,7 +594,7 @@ pub mod test {
|
|||||||
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] });
|
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] });
|
||||||
|
|
||||||
let cell = Cell::paint(Yellow.bold(), "folk");
|
let cell = Cell::paint(Yellow.bold(), "folk");
|
||||||
assert_eq!(cell, file.display(&Column::Group, &mut users))
|
assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -602,7 +609,7 @@ pub mod test {
|
|||||||
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![ "eve".to_string() ] });
|
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![ "eve".to_string() ] });
|
||||||
|
|
||||||
let cell = Cell::paint(Yellow.bold(), "folk");
|
let cell = Cell::paint(Yellow.bold(), "folk");
|
||||||
assert_eq!(cell, file.display(&Column::Group, &mut users))
|
assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -1,11 +1,9 @@
|
|||||||
#![feature(collections, core, env, io, libc, os, path, plugin, std_misc)]
|
#![feature(collections, core, env, io, libc, path, plugin, std_misc)]
|
||||||
|
|
||||||
#[plugin] #[no_link]
|
|
||||||
extern crate datetime_macros;
|
|
||||||
|
|
||||||
extern crate ansi_term;
|
extern crate ansi_term;
|
||||||
extern crate datetime;
|
extern crate datetime;
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
extern crate locale;
|
||||||
extern crate natord;
|
extern crate natord;
|
||||||
extern crate number_prefix;
|
extern crate number_prefix;
|
||||||
extern crate pad;
|
extern crate pad;
|
||||||
@ -140,7 +138,7 @@ impl<'a> Exa<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = args();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
match Options::getopts(args.tail()) {
|
match Options::getopts(args.tail()) {
|
||||||
Ok((options, paths)) => {
|
Ok((options, paths)) => {
|
||||||
@ -155,7 +153,3 @@ fn main() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args() -> Vec<String> {
|
|
||||||
env::args().map(|arg| arg.to_string_lossy().into_owned()).collect()
|
|
||||||
}
|
|
||||||
|
@ -32,7 +32,7 @@ pub struct FileFilter {
|
|||||||
sort_field: SortField,
|
sort_field: SortField,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Debug)]
|
#[derive(PartialEq, Debug, Copy)]
|
||||||
pub enum View {
|
pub enum View {
|
||||||
Details(Details),
|
Details(Details),
|
||||||
Lines,
|
Lines,
|
||||||
|
@ -4,6 +4,7 @@ use file::{File, GREY};
|
|||||||
use options::{Columns, FileFilter};
|
use options::{Columns, FileFilter};
|
||||||
use users::OSUsers;
|
use users::OSUsers;
|
||||||
|
|
||||||
|
use locale;
|
||||||
use ansi_term::Style::Plain;
|
use ansi_term::Style::Plain;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Copy)]
|
#[derive(PartialEq, Debug, Copy)]
|
||||||
@ -24,9 +25,10 @@ impl Details {
|
|||||||
// padding the fields during output.
|
// padding the fields during output.
|
||||||
|
|
||||||
let columns = self.columns.for_dir(dir);
|
let columns = self.columns.for_dir(dir);
|
||||||
|
let locale = UserLocale::new();
|
||||||
let mut cache = OSUsers::empty_cache();
|
let mut cache = OSUsers::empty_cache();
|
||||||
let mut table = Vec::new();
|
let mut table = Vec::new();
|
||||||
self.get_files(&columns[], &mut cache, &mut table, files, 0);
|
self.get_files(&columns[], &mut cache, &locale, &mut table, files, 0);
|
||||||
|
|
||||||
if self.header {
|
if self.header {
|
||||||
let row = Row {
|
let row = Row {
|
||||||
@ -73,12 +75,12 @@ impl Details {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_files(&self, columns: &[Column], cache: &mut OSUsers, dest: &mut Vec<Row>, src: &[File], depth: usize) {
|
fn get_files(&self, columns: &[Column], cache: &mut OSUsers, locale: &UserLocale, dest: &mut Vec<Row>, src: &[File], depth: usize) {
|
||||||
for (index, file) in src.iter().enumerate() {
|
for (index, file) in src.iter().enumerate() {
|
||||||
|
|
||||||
let row = Row {
|
let row = Row {
|
||||||
depth: depth,
|
depth: depth,
|
||||||
cells: columns.iter().map(|c| file.display(c, cache)).collect(),
|
cells: columns.iter().map(|c| file.display(c, cache, locale)).collect(),
|
||||||
name: file.file_name_view(),
|
name: file.file_name_view(),
|
||||||
last: index == src.len() - 1,
|
last: index == src.len() - 1,
|
||||||
children: file.this.is_some(),
|
children: file.this.is_some(),
|
||||||
@ -90,7 +92,7 @@ impl Details {
|
|||||||
if let Some(ref dir) = file.this {
|
if let Some(ref dir) = file.this {
|
||||||
let mut files = dir.files(true);
|
let mut files = dir.files(true);
|
||||||
self.filter.transform_files(&mut files);
|
self.filter.transform_files(&mut files);
|
||||||
self.get_files(columns, cache, dest, files.as_slice(), depth + 1);
|
self.get_files(columns, cache, locale, dest, files.as_slice(), depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,3 +106,24 @@ struct Row {
|
|||||||
pub last: bool,
|
pub last: bool,
|
||||||
pub children: bool,
|
pub children: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct UserLocale {
|
||||||
|
pub time: locale::Time,
|
||||||
|
pub numeric: locale::Numeric,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UserLocale {
|
||||||
|
pub fn new() -> UserLocale {
|
||||||
|
UserLocale {
|
||||||
|
time: locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english()),
|
||||||
|
numeric: locale::Numeric::load_user_locale().unwrap_or_else(|_| locale::Numeric::english()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn default() -> UserLocale {
|
||||||
|
UserLocale {
|
||||||
|
time: locale::Time::english(),
|
||||||
|
numeric: locale::Numeric::english(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
mod grid;
|
mod grid;
|
||||||
mod details;
|
pub mod details;
|
||||||
mod lines;
|
mod lines;
|
||||||
|
|
||||||
pub use self::grid::Grid;
|
pub use self::grid::Grid;
|
||||||
|
Loading…
Reference in New Issue
Block a user