From 1c5409e253a34184f0fced80b488df61565e8f06 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Mon, 12 Jan 2015 01:31:24 +0100 Subject: [PATCH] Upgrade to Rust alpha - uint -> usize - getopts Cargo library - replace feature gates with unstable APIs --- Cargo.lock | 6 ++++++ Cargo.toml | 1 + src/column.rs | 4 ++-- src/exa.rs | 14 +++++++------- src/file.rs | 2 +- src/options.rs | 4 ++-- src/term.rs | 4 ++-- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e07335..f6e9215 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,6 +3,7 @@ name = "exa" version = "0.1.0" dependencies = [ "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)", "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)", @@ -17,6 +18,11 @@ dependencies = [ "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]] name = "natord" version = "1.0.6" diff --git a/Cargo.toml b/Cargo.toml index 59358ac..466105d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ name = "exa" [dependencies] ansi_term = "0.4.2" +getopts = "0.1.4" natord = "1.0.6" number_prefix = "0.2.1" users = "0.2.1" diff --git a/src/column.rs b/src/column.rs index 5a4bdb0..4ef4f76 100644 --- a/src/column.rs +++ b/src/column.rs @@ -55,7 +55,7 @@ impl Column { } } -fn spaces(length: uint) -> String { +fn spaces(length: usize) -> String { repeat(" ").take(length).collect() } @@ -65,7 +65,7 @@ fn spaces(length: uint) -> String { // because these strings are usually full of control characters. impl Alignment { - pub fn pad_string(&self, string: &String, padding: uint) -> String { + pub fn pad_string(&self, string: &String, padding: usize) -> String { match *self { Alignment::Left => format!("{}{}", string, spaces(padding).as_slice()), Alignment::Right => format!("{}{}", spaces(padding), string.as_slice()), diff --git a/src/exa.rs b/src/exa.rs index 67c8b9e..e84414c 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -1,4 +1,4 @@ -#![feature(globs)] +#![allow(unstable)] extern crate ansi_term; extern crate number_prefix; @@ -112,7 +112,7 @@ fn lines_view(files: Vec) { } } -fn fit_into_grid(across: bool, console_width: uint, files: &Vec) -> Option<(uint, Vec)> { +fn fit_into_grid(across: bool, console_width: usize, files: &Vec) -> Option<(usize, Vec)> { // TODO: this function could almost certainly be optimised... // 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) -> Option // *column separators* is bigger than the width of the screen, then // don't even try to tabulate it. // 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. let separator_width = (num_columns - 1) * 2; if console_width < separator_width { @@ -143,7 +143,7 @@ fn fit_into_grid(across: bool, console_width: uint, files: &Vec) -> Option // Find the width of each column by adding the lengths of the file // names in that column up. - let mut column_widths: Vec = repeat(0).take(num_columns).collect(); + let mut column_widths: Vec = repeat(0).take(num_columns).collect(); for (index, file) in files.iter().enumerate() { let index = if across { index % num_columns @@ -164,7 +164,7 @@ fn fit_into_grid(across: bool, console_width: uint, files: &Vec) -> Option return None; } -fn grid_view(across: bool, console_width: uint, files: Vec) { +fn grid_view(across: bool, console_width: usize, files: Vec) { if let Some((num_lines, widths)) = fit_into_grid(across, console_width, &files) { for y in range(0, num_lines) { for x in range(0, widths.len()) { @@ -223,11 +223,11 @@ fn details_view(options: &Options, columns: &Vec, files: Vec) { // This is fairly expensive to do (it uses a regex), so the // results are cached. - let lengths: Vec> = table.iter() + let lengths: Vec> = table.iter() .map(|row| row.iter().map(|col| strip_formatting(col.as_slice()).len()).collect()) .collect(); - let column_widths: Vec = range(0, columns.len()) + let column_widths: Vec = range(0, columns.len()) .map(|n| lengths.iter().map(|row| row[n]).max().unwrap_or(0)) .collect(); diff --git a/src/file.rs b/src/file.rs index 9fb283c..6f19819 100644 --- a/src/file.rs +++ b/src/file.rs @@ -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) } diff --git a/src/options.rs b/src/options.rs index 65e5d6e..3a284b9 100644 --- a/src/options.rs +++ b/src/options.rs @@ -30,7 +30,7 @@ impl SortField { pub enum View { Details(Vec), Lines, - Grid(bool, uint), + Grid(bool, usize), } pub struct Options { @@ -44,7 +44,7 @@ pub struct Options { } impl Options { - pub fn getopts(args: Vec) -> Result { + pub fn getopts(args: Vec) -> Result { let opts = [ getopts::optflag("1", "oneline", "display one entry per line"), getopts::optflag("a", "all", "show dot-files"), diff --git a/src/term.rs b/src/term.rs index dc52acc..c0849be 100644 --- a/src/term.rs +++ b/src/term.rs @@ -37,7 +37,7 @@ mod c { } } -pub fn dimensions() -> Option<(uint, uint)> { +pub fn dimensions() -> Option<(usize, usize)> { let w = unsafe { c::dimensions() }; // If either of the dimensions is 0 then the command failed, @@ -47,6 +47,6 @@ pub fn dimensions() -> Option<(uint, uint)> { None } else { - Some((w.ws_col as uint, w.ws_row as uint)) + Some((w.ws_col as usize, w.ws_row as usize)) } }