From cfd33168af2a64f5ae9de22abf3994420ee222ea 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=20lib.rs=20?= =?UTF-8?q?=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move {controller,output,printer,decorations}.rs into src/bin/ * Add `mod errors` from main.rs --- src/{ => bin}/controller.rs | 0 src/{ => bin}/decorations.rs | 0 src/{ => bin}/output.rs | 0 src/{ => bin}/printer.rs | 0 src/lib.rs | 31 ++++++++++++++++++++++++++----- 5 files changed, 26 insertions(+), 5 deletions(-) rename src/{ => bin}/controller.rs (100%) rename src/{ => bin}/decorations.rs (100%) rename src/{ => bin}/output.rs (100%) rename src/{ => bin}/printer.rs (100%) diff --git a/src/controller.rs b/src/bin/controller.rs similarity index 100% rename from src/controller.rs rename to src/bin/controller.rs diff --git a/src/decorations.rs b/src/bin/decorations.rs similarity index 100% rename from src/decorations.rs rename to src/bin/decorations.rs diff --git a/src/output.rs b/src/bin/output.rs similarity index 100% rename from src/output.rs rename to src/bin/output.rs diff --git a/src/printer.rs b/src/bin/printer.rs similarity index 100% rename from src/printer.rs rename to src/bin/printer.rs diff --git a/src/lib.rs b/src/lib.rs index f8359055..9ee612fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,16 +23,37 @@ extern crate wild; mod assets; 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; \ No newline at end of file +mod util; + +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() == ::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