Upgrade to Rust alpha

- uint -> usize
- getopts Cargo library
- replace feature gates with unstable APIs
This commit is contained in:
Benjamin Sago 2015-01-12 01:31:24 +01:00
parent 2784baea0a
commit 1c5409e253
7 changed files with 21 additions and 14 deletions

6
Cargo.lock generated
View File

@ -3,6 +3,7 @@ name = "exa"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ansi_term 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "ansi_term 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"natord 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "natord 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"number_prefix 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"users 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "users 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -17,6 +18,11 @@ dependencies = [
"regex_macros 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex_macros 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "getopts"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "natord" name = "natord"
version = "1.0.6" version = "1.0.6"

View File

@ -8,6 +8,7 @@ name = "exa"
[dependencies] [dependencies]
ansi_term = "0.4.2" ansi_term = "0.4.2"
getopts = "0.1.4"
natord = "1.0.6" natord = "1.0.6"
number_prefix = "0.2.1" number_prefix = "0.2.1"
users = "0.2.1" users = "0.2.1"

View File

@ -55,7 +55,7 @@ impl Column {
} }
} }
fn spaces(length: uint) -> String { fn spaces(length: usize) -> String {
repeat(" ").take(length).collect() repeat(" ").take(length).collect()
} }
@ -65,7 +65,7 @@ fn spaces(length: uint) -> String {
// because these strings are usually full of control characters. // because these strings are usually full of control characters.
impl Alignment { impl Alignment {
pub fn pad_string(&self, string: &String, padding: uint) -> String { pub fn pad_string(&self, string: &String, padding: usize) -> String {
match *self { match *self {
Alignment::Left => format!("{}{}", string, spaces(padding).as_slice()), Alignment::Left => format!("{}{}", string, spaces(padding).as_slice()),
Alignment::Right => format!("{}{}", spaces(padding), string.as_slice()), Alignment::Right => format!("{}{}", spaces(padding), string.as_slice()),

View File

@ -1,4 +1,4 @@
#![feature(globs)] #![allow(unstable)]
extern crate ansi_term; extern crate ansi_term;
extern crate number_prefix; extern crate number_prefix;
@ -112,7 +112,7 @@ fn lines_view(files: Vec<File>) {
} }
} }
fn fit_into_grid(across: bool, console_width: uint, files: &Vec<File>) -> Option<(uint, Vec<uint>)> { fn fit_into_grid(across: bool, console_width: usize, files: &Vec<File>) -> Option<(usize, Vec<usize>)> {
// TODO: this function could almost certainly be optimised... // TODO: this function could almost certainly be optimised...
// surely not *all* of the numbers of lines are worth searching through! // surely not *all* of the numbers of lines are worth searching through!
@ -131,7 +131,7 @@ fn fit_into_grid(across: bool, console_width: uint, files: &Vec<File>) -> Option
// *column separators* is bigger than the width of the screen, then // *column separators* is bigger than the width of the screen, then
// don't even try to tabulate it. // don't even try to tabulate it.
// This is actually a necessary check, because the width is stored as // This is actually a necessary check, because the width is stored as
// a uint, and making it go negative makes it huge instead, but it // a usize, and making it go negative makes it huge instead, but it
// also serves as a speed-up. // also serves as a speed-up.
let separator_width = (num_columns - 1) * 2; let separator_width = (num_columns - 1) * 2;
if console_width < separator_width { if console_width < separator_width {
@ -143,7 +143,7 @@ fn fit_into_grid(across: bool, console_width: uint, files: &Vec<File>) -> Option
// Find the width of each column by adding the lengths of the file // Find the width of each column by adding the lengths of the file
// names in that column up. // names in that column up.
let mut column_widths: Vec<uint> = repeat(0).take(num_columns).collect(); let mut column_widths: Vec<usize> = repeat(0).take(num_columns).collect();
for (index, file) in files.iter().enumerate() { for (index, file) in files.iter().enumerate() {
let index = if across { let index = if across {
index % num_columns index % num_columns
@ -164,7 +164,7 @@ fn fit_into_grid(across: bool, console_width: uint, files: &Vec<File>) -> Option
return None; return None;
} }
fn grid_view(across: bool, console_width: uint, files: Vec<File>) { fn grid_view(across: bool, console_width: usize, files: Vec<File>) {
if let Some((num_lines, widths)) = fit_into_grid(across, console_width, &files) { if let Some((num_lines, widths)) = fit_into_grid(across, console_width, &files) {
for y in range(0, num_lines) { for y in range(0, num_lines) {
for x in range(0, widths.len()) { for x in range(0, widths.len()) {
@ -223,11 +223,11 @@ fn details_view(options: &Options, columns: &Vec<Column>, files: Vec<File>) {
// This is fairly expensive to do (it uses a regex), so the // This is fairly expensive to do (it uses a regex), so the
// results are cached. // results are cached.
let lengths: Vec<Vec<uint>> = table.iter() let lengths: Vec<Vec<usize>> = table.iter()
.map(|row| row.iter().map(|col| strip_formatting(col.as_slice()).len()).collect()) .map(|row| row.iter().map(|col| strip_formatting(col.as_slice()).len()).collect())
.collect(); .collect();
let column_widths: Vec<uint> = range(0, columns.len()) let column_widths: Vec<usize> = range(0, columns.len())
.map(|n| lengths.iter().map(|row| row[n]).max().unwrap_or(0)) .map(|n| lengths.iter().map(|row| row[n]).max().unwrap_or(0))
.collect(); .collect();

View File

@ -193,7 +193,7 @@ impl<'a> File<'a> {
} }
} }
pub fn file_name_width(&self) -> uint { pub fn file_name_width(&self) -> usize {
self.name.as_slice().width(false) self.name.as_slice().width(false)
} }

View File

@ -30,7 +30,7 @@ impl SortField {
pub enum View { pub enum View {
Details(Vec<Column>), Details(Vec<Column>),
Lines, Lines,
Grid(bool, uint), Grid(bool, usize),
} }
pub struct Options { pub struct Options {
@ -44,7 +44,7 @@ pub struct Options {
} }
impl Options { impl Options {
pub fn getopts(args: Vec<String>) -> Result<Options, int> { pub fn getopts(args: Vec<String>) -> Result<Options, isize> {
let opts = [ let opts = [
getopts::optflag("1", "oneline", "display one entry per line"), getopts::optflag("1", "oneline", "display one entry per line"),
getopts::optflag("a", "all", "show dot-files"), getopts::optflag("a", "all", "show dot-files"),

View File

@ -37,7 +37,7 @@ mod c {
} }
} }
pub fn dimensions() -> Option<(uint, uint)> { pub fn dimensions() -> Option<(usize, usize)> {
let w = unsafe { c::dimensions() }; let w = unsafe { c::dimensions() };
// If either of the dimensions is 0 then the command failed, // If either of the dimensions is 0 then the command failed,
@ -47,6 +47,6 @@ pub fn dimensions() -> Option<(uint, uint)> {
None None
} }
else { else {
Some((w.ws_col as uint, w.ws_row as uint)) Some((w.ws_col as usize, w.ws_row as usize))
} }
} }