1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-04-14 23:00:37 +01:00

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)] #[cfg(windows)]
use ansi_term; use ansi_term;
use crate::assets::BAT_THEME_DEFAULT; use bat::{
use crate::config::{get_args_from_config_file, get_args_from_env_var}; assets::BAT_THEME_DEFAULT,
use crate::errors::*; config::{get_args_from_config_file, get_args_from_env_var},
use crate::inputfile::InputFile; errors::*,
use crate::line_range::{LineRange, LineRanges}; inputfile::InputFile,
use crate::style::{OutputComponent, OutputComponents, OutputWrap}; line_range::{LineRange, LineRanges},
use crate::syntax_mapping::SyntaxMapping; style::{OutputComponent, OutputComponents, OutputWrap},
use crate::util::transpose; syntax_mapping::SyntaxMapping,
util::transpose,
};
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum PagingMode { pub enum PagingMode {

View File

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

View File

@ -22,22 +22,11 @@ extern crate syntect;
extern crate wild; extern crate wild;
mod app; mod app;
mod assets;
mod clap_app; mod clap_app;
mod config;
mod controller; mod controller;
mod decorations; mod decorations;
mod diff;
mod dirs;
mod inputfile;
mod line_range;
mod output; mod output;
mod preprocessor;
mod printer; mod printer;
mod style;
mod syntax_mapping;
mod terminal;
mod util;
use std::collections::HashSet; use std::collections::HashSet;
use std::io; use std::io;
@ -48,39 +37,18 @@ use std::process;
use ansi_term::Colour::Green; use ansi_term::Colour::Green;
use ansi_term::Style; use ansi_term::Style;
use crate::app::{App, Config}; use crate::{
use crate::assets::{cache_dir, clear_assets, config_dir, HighlightingAssets}; app::{App, Config},
use crate::config::config_file; controller::Controller,
use crate::controller::Controller; };
use crate::inputfile::InputFile;
use crate::style::{OutputComponent, OutputComponents};
mod errors { use bat::{
error_chain! { assets::{cache_dir, clear_assets, config_dir, HighlightingAssets},
foreign_links { config::config_file,
Clap(::clap::Error); errors::*,
Io(::std::io::Error); inputfile::InputFile,
SyntectError(::syntect::LoadingError); style::{OutputComponent, OutputComponents},
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::*;
fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> { fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
if matches.is_present("build") { if matches.is_present("build") {

View File

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

View File

@ -16,18 +16,21 @@ use content_inspector::ContentType;
use encoding::all::{UTF_16BE, UTF_16LE}; use encoding::all::{UTF_16BE, UTF_16LE};
use encoding::{DecoderTrap, Encoding}; use encoding::{DecoderTrap, Encoding};
use crate::app::Config; use crate::{
use crate::assets::HighlightingAssets; app::Config,
use crate::decorations::{ decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration},
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 { pub trait Printer {
fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()>; 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 terminal;
pub mod util; pub mod util;
mod errors { pub mod errors {
error_chain! { error_chain! {
foreign_links { foreign_links {
Clap(::clap::Error); Clap(::clap::Error);
@ -39,4 +39,18 @@ mod errors {
ParseIntError(::std::num::ParseIntError); 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);
}
};
}
} }