mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-25 21:37:33 +00:00
IO import changes
This commit is contained in:
parent
6f2d8cc26c
commit
ecbe63bf1e
4
build.rs
4
build.rs
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
extern crate datetime;
|
extern crate datetime;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::Result as IOResult;
|
use std::io;
|
||||||
|
|
||||||
|
|
||||||
fn git_hash() -> String {
|
fn git_hash() -> String {
|
||||||
@ -46,7 +46,7 @@ fn build_date() -> String {
|
|||||||
format!("{}", now.date().iso())
|
format!("{}", now.date().iso())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_statics() -> IOResult<()> {
|
fn write_statics() -> io::Result<()> {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::fs::feature::git::GitCache;
|
use crate::fs::feature::git::GitCache;
|
||||||
use crate::fs::fields::GitStatus;
|
use crate::fs::fields::GitStatus;
|
||||||
use std::io::{self, Result as IOResult};
|
use std::io;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::slice::Iter as SliceIter;
|
use std::slice::Iter as SliceIter;
|
||||||
@ -35,7 +35,7 @@ impl Dir {
|
|||||||
/// The `read_dir` iterator doesn’t actually yield the `.` and `..`
|
/// The `read_dir` iterator doesn’t actually yield the `.` and `..`
|
||||||
/// entries, so if the user wants to see them, we’ll have to add them
|
/// entries, so if the user wants to see them, we’ll have to add them
|
||||||
/// ourselves after the files have been read.
|
/// ourselves after the files have been read.
|
||||||
pub fn read_dir(path: PathBuf) -> IOResult<Self> {
|
pub fn read_dir(path: PathBuf) -> io::Result<Self> {
|
||||||
info!("Reading directory {:?}", &path);
|
info!("Reading directory {:?}", &path);
|
||||||
|
|
||||||
let contents = fs::read_dir(&path)?
|
let contents = fs::read_dir(&path)?
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//! Files, and methods and fields to access their metadata.
|
//! Files, and methods and fields to access their metadata.
|
||||||
|
|
||||||
use std::io::Error as IOError;
|
use std::io;
|
||||||
use std::io::Result as IOResult;
|
|
||||||
use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt};
|
use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
@ -67,7 +66,7 @@ pub struct File<'dir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'dir> File<'dir> {
|
impl<'dir> File<'dir> {
|
||||||
pub fn from_args<PD, FN>(path: PathBuf, parent_dir: PD, filename: FN) -> IOResult<File<'dir>>
|
pub fn from_args<PD, FN>(path: PathBuf, parent_dir: PD, filename: FN) -> io::Result<File<'dir>>
|
||||||
where PD: Into<Option<&'dir Dir>>,
|
where PD: Into<Option<&'dir Dir>>,
|
||||||
FN: Into<Option<String>>
|
FN: Into<Option<String>>
|
||||||
{
|
{
|
||||||
@ -82,7 +81,7 @@ impl<'dir> File<'dir> {
|
|||||||
Ok(File { path, parent_dir, metadata, ext, name, is_all_all })
|
Ok(File { path, parent_dir, metadata, ext, name, is_all_all })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_aa_current(parent_dir: &'dir Dir) -> IOResult<File<'dir>> {
|
pub fn new_aa_current(parent_dir: &'dir Dir) -> io::Result<File<'dir>> {
|
||||||
let path = parent_dir.path.to_path_buf();
|
let path = parent_dir.path.to_path_buf();
|
||||||
let ext = File::ext(&path);
|
let ext = File::ext(&path);
|
||||||
|
|
||||||
@ -94,7 +93,7 @@ impl<'dir> File<'dir> {
|
|||||||
Ok(File { path, parent_dir, metadata, ext, name: ".".into(), is_all_all })
|
Ok(File { path, parent_dir, metadata, ext, name: ".".into(), is_all_all })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir) -> IOResult<File<'dir>> {
|
pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir) -> io::Result<File<'dir>> {
|
||||||
let ext = File::ext(&path);
|
let ext = File::ext(&path);
|
||||||
|
|
||||||
debug!("Statting file {:?}", &path);
|
debug!("Statting file {:?}", &path);
|
||||||
@ -162,7 +161,7 @@ impl<'dir> File<'dir> {
|
|||||||
///
|
///
|
||||||
/// Returns an IO error upon failure, but this shouldn’t be used to check
|
/// Returns an IO error upon failure, but this shouldn’t be used to check
|
||||||
/// if a `File` is a directory or not! For that, just use `is_directory()`.
|
/// if a `File` is a directory or not! For that, just use `is_directory()`.
|
||||||
pub fn to_dir(&self) -> IOResult<Dir> {
|
pub fn to_dir(&self) -> io::Result<Dir> {
|
||||||
Dir::read_dir(self.path.clone())
|
Dir::read_dir(self.path.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,10 +458,10 @@ pub enum FileTarget<'dir> {
|
|||||||
/// There was an IO error when following the link. This can happen if the
|
/// There was an IO error when following the link. This can happen if the
|
||||||
/// file isn’t a link to begin with, but also if, say, we don’t have
|
/// file isn’t a link to begin with, but also if, say, we don’t have
|
||||||
/// permission to follow it.
|
/// permission to follow it.
|
||||||
Err(IOError),
|
Err(io::Error),
|
||||||
|
|
||||||
// Err is its own variant, instead of having the whole thing be inside an
|
// Err is its own variant, instead of having the whole thing be inside an
|
||||||
// `IOResult`, because being unable to follow a symlink is not a serious
|
// `io::Result`, because being unable to follow a symlink is not a serious
|
||||||
// error — we just display the error message and move on.
|
// error — we just display the error message and move on.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
src/main.rs
20
src/main.rs
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
use std::io::{stdout, Stdout, stderr, Write, Result as IOResult, ErrorKind};
|
use std::io::{self, Write, ErrorKind};
|
||||||
use std::path::{Component, PathBuf};
|
use std::path::{Component, PathBuf};
|
||||||
|
|
||||||
use ansi_term::{ANSIStrings, Style};
|
use ansi_term::{ANSIStrings, Style};
|
||||||
@ -40,7 +40,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let git = git_options(&options, &input_paths);
|
let git = git_options(&options, &input_paths);
|
||||||
let writer = stdout();
|
let writer = io::stdout();
|
||||||
let exa = Exa { options, writer, input_paths, git };
|
let exa = Exa { options, writer, input_paths, git };
|
||||||
|
|
||||||
match exa.run() {
|
match exa.run() {
|
||||||
@ -88,7 +88,7 @@ pub struct Exa<'args> {
|
|||||||
pub options: Options,
|
pub options: Options,
|
||||||
|
|
||||||
/// The output handle that we write to.
|
/// The output handle that we write to.
|
||||||
pub writer: Stdout,
|
pub writer: io::Stdout,
|
||||||
|
|
||||||
/// List of the free command-line arguments that should correspond to file
|
/// List of the free command-line arguments that should correspond to file
|
||||||
/// names (anything that isn’t an option).
|
/// names (anything that isn’t an option).
|
||||||
@ -122,7 +122,7 @@ fn git_options(options: &Options, args: &[&OsStr]) -> Option<GitCache> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'args> Exa<'args> {
|
impl<'args> Exa<'args> {
|
||||||
pub fn run(mut self) -> IOResult<i32> {
|
pub fn run(mut self) -> io::Result<i32> {
|
||||||
debug!("Running with options: {:#?}", self.options);
|
debug!("Running with options: {:#?}", self.options);
|
||||||
|
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
@ -133,14 +133,14 @@ impl<'args> Exa<'args> {
|
|||||||
match File::from_args(PathBuf::from(file_path), None, None) {
|
match File::from_args(PathBuf::from(file_path), None, None) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
exit_status = 2;
|
exit_status = 2;
|
||||||
writeln!(stderr(), "{:?}: {}", file_path, e)?;
|
writeln!(io::stderr(), "{:?}: {}", file_path, e)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
if f.points_to_directory() && ! self.options.dir_action.treat_dirs_as_files() {
|
if f.points_to_directory() && ! self.options.dir_action.treat_dirs_as_files() {
|
||||||
match f.to_dir() {
|
match f.to_dir() {
|
||||||
Ok(d) => dirs.push(d),
|
Ok(d) => dirs.push(d),
|
||||||
Err(e) => writeln!(stderr(), "{:?}: {}", file_path, e)?,
|
Err(e) => writeln!(io::stderr(), "{:?}: {}", file_path, e)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -163,7 +163,7 @@ impl<'args> Exa<'args> {
|
|||||||
self.print_dirs(dirs, no_files, is_only_dir, exit_status)
|
self.print_dirs(dirs, no_files, is_only_dir, exit_status)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_dirs(&mut self, dir_files: Vec<Dir>, mut first: bool, is_only_dir: bool, exit_status: i32) -> IOResult<i32> {
|
fn print_dirs(&mut self, dir_files: Vec<Dir>, mut first: bool, is_only_dir: bool, exit_status: i32) -> io::Result<i32> {
|
||||||
for dir in dir_files {
|
for dir in dir_files {
|
||||||
|
|
||||||
// Put a gap between directories, or between the list of files and
|
// Put a gap between directories, or between the list of files and
|
||||||
@ -186,7 +186,7 @@ impl<'args> Exa<'args> {
|
|||||||
for file in dir.files(self.options.filter.dot_filter, self.git.as_ref(), git_ignore) {
|
for file in dir.files(self.options.filter.dot_filter, self.git.as_ref(), git_ignore) {
|
||||||
match file {
|
match file {
|
||||||
Ok(file) => children.push(file),
|
Ok(file) => children.push(file),
|
||||||
Err((path, e)) => writeln!(stderr(), "[{}: {}]", path.display(), e)?,
|
Err((path, e)) => writeln!(io::stderr(), "[{}: {}]", path.display(), e)?,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ impl<'args> Exa<'args> {
|
|||||||
for child_dir in children.iter().filter(|f| f.is_directory() && ! f.is_all_all) {
|
for child_dir in children.iter().filter(|f| f.is_directory() && ! f.is_all_all) {
|
||||||
match child_dir.to_dir() {
|
match child_dir.to_dir() {
|
||||||
Ok(d) => child_dirs.push(d),
|
Ok(d) => child_dirs.push(d),
|
||||||
Err(e) => writeln!(stderr(), "{}: {}", child_dir.path.display(), e)?,
|
Err(e) => writeln!(io::stderr(), "{}: {}", child_dir.path.display(), e)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ impl<'args> Exa<'args> {
|
|||||||
/// Prints the list of files using whichever view is selected.
|
/// Prints the list of files using whichever view is selected.
|
||||||
/// For various annoying logistical reasons, each one handles
|
/// For various annoying logistical reasons, each one handles
|
||||||
/// printing differently...
|
/// printing differently...
|
||||||
fn print_files(&mut self, dir: Option<&Dir>, files: Vec<File>) -> IOResult<()> {
|
fn print_files(&mut self, dir: Option<&Dir>, files: Vec<File>) -> io::Result<()> {
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
//! can be displayed, in order to make sure that every column is wide enough.
|
//! can be displayed, in order to make sure that every column is wide enough.
|
||||||
|
|
||||||
|
|
||||||
use std::io::{Write, Error as IOError, Result as IOResult};
|
use std::io::{self, Write};
|
||||||
use std::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::vec::IntoIter as VecIntoIter;
|
use std::vec::IntoIter as VecIntoIter;
|
||||||
@ -135,7 +135,7 @@ pub struct Render<'a> {
|
|||||||
struct Egg<'a> {
|
struct Egg<'a> {
|
||||||
table_row: Option<TableRow>,
|
table_row: Option<TableRow>,
|
||||||
xattrs: Vec<Attribute>,
|
xattrs: Vec<Attribute>,
|
||||||
errors: Vec<(IOError, Option<PathBuf>)>,
|
errors: Vec<(io::Error, Option<PathBuf>)>,
|
||||||
dir: Option<Dir>,
|
dir: Option<Dir>,
|
||||||
file: &'a File<'a>,
|
file: &'a File<'a>,
|
||||||
icon: Option<String>,
|
icon: Option<String>,
|
||||||
@ -149,7 +149,7 @@ impl<'a> AsRef<File<'a>> for Egg<'a> {
|
|||||||
|
|
||||||
|
|
||||||
impl<'a> Render<'a> {
|
impl<'a> Render<'a> {
|
||||||
pub fn render<W: Write>(self, mut git: Option<&'a GitCache>, w: &mut W) -> IOResult<()> {
|
pub fn render<W: Write>(self, mut git: Option<&'a GitCache>, w: &mut W) -> io::Result<()> {
|
||||||
let mut pool = Pool::new(num_cpus::get() as u32);
|
let mut pool = Pool::new(num_cpus::get() as u32);
|
||||||
let mut rows = Vec::new();
|
let mut rows = Vec::new();
|
||||||
|
|
||||||
@ -357,7 +357,7 @@ impl<'a> Render<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_error(&self, error: &IOError, tree: TreeParams, path: Option<PathBuf>) -> Row {
|
fn render_error(&self, error: &io::Error, tree: TreeParams, path: Option<PathBuf>) -> Row {
|
||||||
use crate::output::file_name::Colours;
|
use crate::output::file_name::Colours;
|
||||||
|
|
||||||
let error_message = match path {
|
let error_message = match path {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::io::{Write, Result as IOResult};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use term_grid as tg;
|
use term_grid as tg;
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ pub struct Render<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Render<'a> {
|
impl<'a> Render<'a> {
|
||||||
pub fn render<W: Write>(&self, w: &mut W) -> IOResult<()> {
|
pub fn render<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
||||||
let mut grid = tg::Grid::new(tg::GridOptions {
|
let mut grid = tg::Grid::new(tg::GridOptions {
|
||||||
direction: self.opts.direction(),
|
direction: self.opts.direction(),
|
||||||
filling: tg::Filling::Spaces(2),
|
filling: tg::Filling::Spaces(2),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! The grid-details view lists several details views side-by-side.
|
//! The grid-details view lists several details views side-by-side.
|
||||||
|
|
||||||
use std::io::{Write, Result as IOResult};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use ansi_term::{ANSIGenericString, ANSIStrings};
|
use ansi_term::{ANSIGenericString, ANSIStrings};
|
||||||
use term_grid as grid;
|
use term_grid as grid;
|
||||||
@ -119,7 +119,7 @@ impl<'a> Render<'a> {
|
|||||||
// This doesn’t take an IgnoreCache even though the details one does
|
// This doesn’t take an IgnoreCache even though the details one does
|
||||||
// because grid-details has no tree view.
|
// because grid-details has no tree view.
|
||||||
|
|
||||||
pub fn render<W: Write>(self, git: Option<&GitCache>, w: &mut W) -> IOResult<()> {
|
pub fn render<W: Write>(self, git: Option<&GitCache>, w: &mut W) -> io::Result<()> {
|
||||||
if let Some((grid, width)) = self.find_fitting_grid(git) {
|
if let Some((grid, width)) = self.find_fitting_grid(git) {
|
||||||
write!(w, "{}", grid.fit_into_columns(width))
|
write!(w, "{}", grid.fit_into_columns(width))
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::io::{Write, Result as IOResult};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use ansi_term::{ANSIStrings, ANSIGenericString};
|
use ansi_term::{ANSIStrings, ANSIGenericString};
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ pub struct Render<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Render<'a> {
|
impl<'a> Render<'a> {
|
||||||
pub fn render<W: Write>(&self, w: &mut W) -> IOResult<()> {
|
pub fn render<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
||||||
for file in &self.files {
|
for file in &self.files {
|
||||||
let name_cell = self.render_file(file).paint();
|
let name_cell = self.render_file(file).paint();
|
||||||
if self.opts.icons {
|
if self.opts.icons {
|
||||||
|
Loading…
Reference in New Issue
Block a user