Fix all compile errors in bin/bat

* Change `mod errors` in lib.rs to public

* Add `fn handle_error` in lib.rs errors module
This commit is contained in:
Fahmi Akbar Wildana 2019-10-06 09:10:03 +07:00 committed by David Peter
parent e981bd88c1
commit 23d80f9e84
7 changed files with 64 additions and 72 deletions

View File

@ -13,14 +13,16 @@ use console::Term;
#[cfg(windows)]
use ansi_term;
use crate::assets::BAT_THEME_DEFAULT;
use crate::config::{get_args_from_config_file, get_args_from_env_var};
use crate::errors::*;
use crate::inputfile::InputFile;
use crate::line_range::{LineRange, LineRanges};
use crate::style::{OutputComponent, OutputComponents, OutputWrap};
use crate::syntax_mapping::SyntaxMapping;
use crate::util::transpose;
use bat::{
assets::BAT_THEME_DEFAULT,
config::{get_args_from_config_file, get_args_from_env_var},
errors::*,
inputfile::InputFile,
line_range::{LineRange, LineRanges},
style::{OutputComponent, OutputComponents, OutputWrap},
syntax_mapping::SyntaxMapping,
util::transpose,
};
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum PagingMode {

View File

@ -1,13 +1,18 @@
use std::io::{self, Write};
use std::path::Path;
use crate::app::{Config, PagingMode};
use crate::assets::HighlightingAssets;
use crate::errors::*;
use crate::inputfile::{InputFile, InputFileReader};
use crate::line_range::{LineRanges, RangeCheckResult};
use crate::output::OutputType;
use crate::printer::{InteractivePrinter, Printer, SimplePrinter};
use crate::{
app::{Config, PagingMode},
output::OutputType,
printer::{InteractivePrinter, Printer, SimplePrinter},
};
use bat::{
assets::HighlightingAssets,
errors::*,
inputfile::{InputFile, InputFileReader},
line_range::{LineRanges, RangeCheckResult},
};
pub struct Controller<'a> {
config: &'a Config<'a>,

View File

@ -1,4 +1,4 @@
use crate::diff::LineChange;
use bat::diff::LineChange;
use crate::printer::{Colors, InteractivePrinter};
use ansi_term::Style;

View File

@ -22,22 +22,11 @@ extern crate syntect;
extern crate wild;
mod app;
mod assets;
mod clap_app;
mod config;
mod controller;
mod decorations;
mod diff;
mod dirs;
mod inputfile;
mod line_range;
mod output;
mod preprocessor;
mod printer;
mod style;
mod syntax_mapping;
mod terminal;
mod util;
use std::collections::HashSet;
use std::io;
@ -48,39 +37,18 @@ use std::process;
use ansi_term::Colour::Green;
use ansi_term::Style;
use crate::app::{App, Config};
use crate::assets::{cache_dir, clear_assets, config_dir, HighlightingAssets};
use crate::config::config_file;
use crate::controller::Controller;
use crate::inputfile::InputFile;
use crate::style::{OutputComponent, OutputComponents};
use crate::{
app::{App, Config},
controller::Controller,
};
mod errors {
error_chain! {
foreign_links {
Clap(::clap::Error);
Io(::std::io::Error);
SyntectError(::syntect::LoadingError);
ParseIntError(::std::num::ParseIntError);
}
}
pub fn handle_error(error: &Error) {
match error {
Error(ErrorKind::Io(ref io_error), _)
if io_error.kind() == super::io::ErrorKind::BrokenPipe =>
{
super::process::exit(0);
}
_ => {
use ansi_term::Colour::Red;
eprintln!("{}: {}", Red.paint("[bat error]"), error);
}
};
}
}
use crate::errors::*;
use bat::{
assets::{cache_dir, clear_assets, config_dir, HighlightingAssets},
config::config_file,
errors::*,
inputfile::InputFile,
style::{OutputComponent, OutputComponents},
};
fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
if matches.is_present("build") {

View File

@ -7,7 +7,7 @@ use std::process::{Child, Command, Stdio};
use shell_words;
use crate::app::PagingMode;
use crate::errors::*;
use bat::errors::*;
pub enum OutputType {
Pager(Child),

View File

@ -16,18 +16,21 @@ use content_inspector::ContentType;
use encoding::all::{UTF_16BE, UTF_16LE};
use encoding::{DecoderTrap, Encoding};
use crate::app::Config;
use crate::assets::HighlightingAssets;
use crate::decorations::{
Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration,
use crate::{
app::Config,
decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration},
};
use bat::{
assets::HighlightingAssets,
diff::get_git_diff,
diff::LineChanges,
errors::*,
inputfile::{InputFile, InputFileReader},
preprocessor::{expand_tabs, replace_nonprintable},
style::OutputWrap,
terminal::{as_terminal_escaped, to_ansi_color},
};
use crate::diff::get_git_diff;
use crate::diff::LineChanges;
use crate::errors::*;
use crate::inputfile::{InputFile, InputFileReader};
use crate::preprocessor::{expand_tabs, replace_nonprintable};
use crate::style::OutputWrap;
use crate::terminal::{as_terminal_escaped, to_ansi_color};
pub trait Printer {
fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()>;

View File

@ -30,7 +30,7 @@ pub mod syntax_mapping;
pub mod terminal;
pub mod util;
mod errors {
pub mod errors {
error_chain! {
foreign_links {
Clap(::clap::Error);
@ -39,4 +39,18 @@ mod errors {
ParseIntError(::std::num::ParseIntError);
}
}
pub fn handle_error(error: &Error) {
match error {
Error(ErrorKind::Io(ref io_error), _)
if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
{
::std::process::exit(0);
}
_ => {
use ansi_term::Colour::Red;
eprintln!("{}: {}", Red.paint("[bat error]"), error);
}
};
}
}