From 23d80f9e8473dacb45556dd24234dc0fa3341b31 Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Sun, 6 Oct 2019 09:10:03 +0700 Subject: [PATCH] =?UTF-8?q?Fix=20all=20compile=20errors=20in=20bin/bat=20?= =?UTF-8?q?=E2=9E=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change `mod errors` in lib.rs to public * Add `fn handle_error` in lib.rs errors module --- src/bin/bat/app.rs | 18 +++++++------ src/bin/bat/controller.rs | 19 +++++++++----- src/bin/bat/decorations.rs | 2 +- src/bin/bat/main.rs | 54 ++++++++------------------------------ src/bin/bat/output.rs | 2 +- src/bin/bat/printer.rs | 25 ++++++++++-------- src/lib.rs | 16 ++++++++++- 7 files changed, 64 insertions(+), 72 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 47af9e9c..d067e681 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -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 { diff --git a/src/bin/bat/controller.rs b/src/bin/bat/controller.rs index b67d03c5..dea78c2b 100644 --- a/src/bin/bat/controller.rs +++ b/src/bin/bat/controller.rs @@ -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>, diff --git a/src/bin/bat/decorations.rs b/src/bin/bat/decorations.rs index 7654c617..3ffbed64 100644 --- a/src/bin/bat/decorations.rs +++ b/src/bin/bat/decorations.rs @@ -1,4 +1,4 @@ -use crate::diff::LineChange; +use bat::diff::LineChange; use crate::printer::{Colors, InteractivePrinter}; use ansi_term::Style; diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 9d222bd7..83ee3b4e 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -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") { diff --git a/src/bin/bat/output.rs b/src/bin/bat/output.rs index e0b567a6..79919630 100644 --- a/src/bin/bat/output.rs +++ b/src/bin/bat/output.rs @@ -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), diff --git a/src/bin/bat/printer.rs b/src/bin/bat/printer.rs index 8da7af93..8ed21329 100644 --- a/src/bin/bat/printer.rs +++ b/src/bin/bat/printer.rs @@ -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<()>; diff --git a/src/lib.rs b/src/lib.rs index 1e97f693..0a1cb369 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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); + } + }; + } } \ No newline at end of file