mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-01-13 01:01:13 +00:00
Upgrade to Rust alpha
- uint -> usize - getopts Cargo library - replace feature gates with unstable APIs
This commit is contained in:
parent
2784baea0a
commit
1c5409e253
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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()),
|
||||
|
14
src/exa.rs
14
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<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...
|
||||
// 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
|
||||
// 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<File>) -> Option
|
||||
|
||||
// Find the width of each column by adding the lengths of the file
|
||||
// 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() {
|
||||
let index = if across {
|
||||
index % num_columns
|
||||
@ -164,7 +164,7 @@ fn fit_into_grid(across: bool, console_width: uint, files: &Vec<File>) -> Option
|
||||
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) {
|
||||
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<Column>, files: Vec<File>) {
|
||||
// This is fairly expensive to do (it uses a regex), so the
|
||||
// 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())
|
||||
.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))
|
||||
.collect();
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ impl SortField {
|
||||
pub enum View {
|
||||
Details(Vec<Column>),
|
||||
Lines,
|
||||
Grid(bool, uint),
|
||||
Grid(bool, usize),
|
||||
}
|
||||
|
||||
pub struct Options {
|
||||
@ -44,7 +44,7 @@ pub struct Options {
|
||||
}
|
||||
|
||||
impl Options {
|
||||
pub fn getopts(args: Vec<String>) -> Result<Options, int> {
|
||||
pub fn getopts(args: Vec<String>) -> Result<Options, isize> {
|
||||
let opts = [
|
||||
getopts::optflag("1", "oneline", "display one entry per line"),
|
||||
getopts::optflag("a", "all", "show dot-files"),
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user