From 05dd644c92ed32ad29117f5ea01bad94e07e9067 Mon Sep 17 00:00:00 2001 From: Ben S Date: Wed, 26 Nov 2014 07:36:09 +0000 Subject: [PATCH] Upgrade to latest ansi_term Yeah, I broke my own code again. --- .gitignore | 1 - Cargo.lock | 12 ++++++++++++ src/exa.rs | 6 +++--- src/file.rs | 37 ++++++++++++++++++------------------- src/filetype.rs | 2 +- 5 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index 1054da5..d9860d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ *~ target -Cargo.lock \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..4625fd6 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,12 @@ +[root] +name = "exa" +version = "0.1.0" +dependencies = [ + "ansi_term 0.3.0 (git+https://github.com/ogham/rust-ansi-term.git)", +] + +[[package]] +name = "ansi_term" +version = "0.3.0" +source = "git+https://github.com/ogham/rust-ansi-term.git#4b9ea6cf266053e1a771e75b935b4e54c586c139" + diff --git a/src/exa.rs b/src/exa.rs index a26aa84..8117b24 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -15,7 +15,7 @@ use column::Alignment::Left; use options::{Options, View}; use unix::Unix; -use ansi_term::{Paint, Plain, strip_formatting}; +use ansi_term::{Plain, strip_formatting}; pub mod column; pub mod dir; @@ -135,7 +135,7 @@ fn grid_view(across: bool, console_width: uint, files: Vec) { let ref file = files[num]; let file_name = file.name.clone(); - let styled_name = file.file_colour().paint(file_name.as_slice()); + let styled_name = file.file_colour().paint(file_name.as_slice()).to_string(); if x == num_columns - 1 { print!("{}", styled_name); } @@ -161,7 +161,7 @@ fn details_view(options: &Options, columns: &Vec, files: Vec) { .collect(); if options.header { - table.insert(0, columns.iter().map(|c| Plain.underline().paint(c.header())).collect()); + table.insert(0, columns.iter().map(|c| Plain.underline().paint(c.header()).to_string()).collect()); } // Each column needs to have its invisible colour-formatting diff --git a/src/file.rs b/src/file.rs index 4cd7ed9..460cac6 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,8 +1,7 @@ use std::io::{fs, IoResult}; use std::io; -use std::str::SendStr; -use ansi_term::{Paint, Colour, Plain, Style, Red, Green, Yellow, Blue, Purple, Cyan, Fixed}; +use ansi_term::{ANSIString, Colour, Plain, Style, Red, Green, Yellow, Blue, Purple, Cyan, Fixed}; use column::Column; use column::Column::*; @@ -121,19 +120,19 @@ impl<'a> File<'a> { // the time. HardLinks => { let style = if self.has_multiple_links() { Red.on(Yellow) } else { Red.normal() }; - style.paint(self.stat.unstable.nlink.to_string().as_slice()) + style.paint(self.stat.unstable.nlink.to_string().as_slice()).to_string() }, Inode => { - Purple.paint(self.stat.unstable.inode.to_string().as_slice()) + Purple.paint(self.stat.unstable.inode.to_string().as_slice()).to_string() }, Blocks => { if self.stat.kind == io::TypeFile || self.stat.kind == io::TypeSymlink { - Cyan.paint(self.stat.unstable.blocks.to_string().as_slice()) + Cyan.paint(self.stat.unstable.blocks.to_string().as_slice()).to_string() } else { - GREY.paint("-") + GREY.paint("-").to_string() } }, @@ -144,7 +143,7 @@ impl<'a> File<'a> { unix.load_user(uid); let user_name = unix.get_user_name(uid).unwrap_or(uid.to_string()); let style = if unix.uid == uid { Yellow.bold() } else { Plain }; - style.paint(user_name.as_slice()) + style.paint(user_name.as_slice()).to_string() }, Group => { @@ -152,7 +151,7 @@ impl<'a> File<'a> { unix.load_group(gid); let group_name = unix.get_group_name(gid).unwrap_or(gid.to_string()); let style = if unix.is_group_member(gid) { Yellow.normal() } else { Plain }; - style.paint(group_name.as_slice()) + style.paint(group_name.as_slice()).to_string() }, } } @@ -169,11 +168,11 @@ impl<'a> File<'a> { }; format!("{} {}", displayed_name, self.target_file_name_and_arrow(target_path)) } - Err(_) => displayed_name, + Err(_) => displayed_name.to_string(), } } else { - displayed_name + displayed_name.to_string() } } @@ -212,7 +211,7 @@ impl<'a> File<'a> { // Don't report file sizes for directories. I've never looked // at one of those numbers and gained any information from it. if self.stat.kind == io::TypeDirectory { - GREY.paint("-") + GREY.paint("-").to_string() } else { let (size, suffix) = if use_iec_prefixes { @@ -226,14 +225,14 @@ impl<'a> File<'a> { } } - fn type_char(&self) -> SendStr { + fn type_char(&self) -> ANSIString { return match self.stat.kind { - io::TypeFile => ".".into_maybe_owned(), - io::TypeDirectory => Blue.paint("d").into_maybe_owned(), - io::TypeNamedPipe => Yellow.paint("|").into_maybe_owned(), - io::TypeBlockSpecial => Purple.paint("s").into_maybe_owned(), - io::TypeSymlink => Cyan.paint("l").into_maybe_owned(), - io::TypeUnknown => "?".into_maybe_owned(), + io::TypeFile => Plain.paint("."), + io::TypeDirectory => Blue.paint("d"), + io::TypeNamedPipe => Yellow.paint("|"), + io::TypeBlockSpecial => Purple.paint("s"), + io::TypeSymlink => Cyan.paint("l"), + io::TypeUnknown => Plain.paint("?"), } } @@ -264,7 +263,7 @@ impl<'a> File<'a> { ); } - fn permission_bit(bits: io::FilePermission, bit: io::FilePermission, character: &'static str, style: Style) -> String { + fn permission_bit(bits: io::FilePermission, bit: io::FilePermission, character: &'static str, style: Style) -> ANSIString { if bits.contains(bit) { style.paint(character.as_slice()) } diff --git a/src/filetype.rs b/src/filetype.rs index 6b4beca..b57a0eb 100644 --- a/src/filetype.rs +++ b/src/filetype.rs @@ -4,7 +4,7 @@ use self::FileType::*; use std::io; use std::ascii::AsciiExt; -use ansi_term::{Paint, Plain, Style, Red, Green, Yellow, Blue, Cyan, Fixed}; +use ansi_term::{Plain, Style, Red, Green, Yellow, Blue, Cyan, Fixed}; pub enum FileType { Normal, Directory, Executable, Immediate, Compiled, Symlink, Special,