summaryrefslogtreecommitdiffstats
path: root/src/output/details.rs
diff options
context:
space:
mode:
authorBenjamin Sago <ogham@bsago.me>2016-04-18 18:39:32 +0100
committerBenjamin Sago <ogham@bsago.me>2016-04-18 18:39:32 +0100
commita02f37cb45532075281152435d7223e772ae62b5 (patch)
tree4bc8f56295698e75e6daad3869dfd3c303d52232 /src/output/details.rs
parent476406f43ba2f45c8c064eae0802bc77ce81d816 (diff)
Change views to print to a Writer, not stdout
This will mean that we can test exa's output as a whole, without having to rely on process or IO or anything like that.
Diffstat (limited to 'src/output/details.rs')
-rw-r--r--src/output/details.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/output/details.rs b/src/output/details.rs
index 0fc4a84..a6ebb65 100644
--- a/src/output/details.rs
+++ b/src/output/details.rs
@@ -71,7 +71,7 @@
//! are used in place of the filename.
-use std::io;
+use std::io::{Write, Error as IOError, Result as IOResult};
use std::ops::Add;
use std::path::PathBuf;
use std::string::ToString;
@@ -186,7 +186,7 @@ impl Details {
/// Print the details of the given vector of files -- all of which will
/// have been read from the given directory, if present -- to stdout.
- pub fn view(&self, dir: Option<&Dir>, files: Vec<File>) {
+ pub fn view<W: Write>(&self, dir: Option<&Dir>, files: Vec<File>, w: &mut W) -> IOResult<()> {
// First, transform the Columns object into a vector of columns for
// the current directory.
@@ -212,8 +212,10 @@ impl Details {
// Then add files to the table and print it out.
self.add_files_to_table(&mut table, files, 0);
for cell in table.print_table() {
- println!("{}", cell.strings());
+ try!(writeln!(w, "{}", cell.strings()));
}
+
+ Ok(())
}
/// Adds files to the table, possibly recursively. This is easily
@@ -230,7 +232,7 @@ impl Details {
struct Egg<'a> {
cells: Vec<TextCell>,
xattrs: Vec<Attribute>,
- errors: Vec<(io::Error, Option<PathBuf>)>,
+ errors: Vec<(IOError, Option<PathBuf>)>,
dir: Option<Dir>,
file: File<'a>,
}
@@ -417,7 +419,7 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
self.rows.push(row);
}
- fn add_error(&mut self, error: &io::Error, depth: usize, last: bool, path: Option<PathBuf>) {
+ fn add_error(&mut self, error: &IOError, depth: usize, last: bool, path: Option<PathBuf>) {
let error_message = match path {
Some(path) => format!("<{}: {}>", path.display(), error),
None => format!("<{}>", error),