on master help sign in
Fix all compile errors in bin/bat ➕

* Change `mod errors` in lib.rs to public * Add `fn handle_error` in lib.rs errors module

commit23d80f9e8473dacb45556dd24234dc0fa3341b31 authorFahmi Akbar Wildana <f.a.wildana@gmail.com> dateSun 6 Oct 2019, 09:10 (7 years ago) parente981bd8
7 files changed+65−73
src/bin/bat/app.rs+10−8 src/bin/bat/controller.rs+12−7 src/bin/bat/decorations.rs+1−1 src/bin/bat/main.rs+12−44 src/bin/bat/output.rs+1−1 src/bin/bat/printer.rs+14−11 src/lib.rs+15−1
src/bin/bat/app.rs+10−8
@@ -13,14 +13,16 @@ use console::Term;
1313#[cfg(windows)]
1414use ansi_term;
1515
16−use crate::assets::BAT_THEME_DEFAULT;
17−use crate::config::{get_args_from_config_file, get_args_from_env_var};
18−use crate::errors::*;
19−use crate::inputfile::InputFile;
20−use crate::line_range::{LineRange, LineRanges};
21−use crate::style::{OutputComponent, OutputComponents, OutputWrap};
22−use crate::syntax_mapping::SyntaxMapping;
23−use crate::util::transpose;
16+use bat::{
17+ assets::BAT_THEME_DEFAULT,
18+ config::{get_args_from_config_file, get_args_from_env_var},
19+ errors::*,
20+ inputfile::InputFile,
21+ line_range::{LineRange, LineRanges},
22+ style::{OutputComponent, OutputComponents, OutputWrap},
23+ syntax_mapping::SyntaxMapping,
24+ util::transpose,
25+};
2426
2527#[derive(Debug, Clone, Copy, PartialEq)]
2628pub enum PagingMode {
src/bin/bat/controller.rs+12−7
@@ -1,13 +1,18 @@
11use std::io::{self, Write};
22use std::path::Path;
33
4−use crate::app::{Config, PagingMode};
5−use crate::assets::HighlightingAssets;
6−use crate::errors::*;
7−use crate::inputfile::{InputFile, InputFileReader};
8−use crate::line_range::{LineRanges, RangeCheckResult};
9−use crate::output::OutputType;
10−use crate::printer::{InteractivePrinter, Printer, SimplePrinter};
4+use crate::{
5+ app::{Config, PagingMode},
6+ output::OutputType,
7+ printer::{InteractivePrinter, Printer, SimplePrinter},
8+};
9+
10+use bat::{
11+ assets::HighlightingAssets,
12+ errors::*,
13+ inputfile::{InputFile, InputFileReader},
14+ line_range::{LineRanges, RangeCheckResult},
15+};
1116
1217pub struct Controller<'a> {
1318 config: &'a Config<'a>,
src/bin/bat/decorations.rs+1−1
@@ -1,4 +1,4 @@
1−use crate::diff::LineChange;
1+use bat::diff::LineChange;
22use crate::printer::{Colors, InteractivePrinter};
33use ansi_term::Style;
44
src/bin/bat/main.rs+12−44
@@ -22,22 +22,11 @@ extern crate syntect;
2222extern crate wild;
2323
2424mod app;
25−mod assets;
2625mod clap_app;
27−mod config;
2826mod controller;
2927mod decorations;
30−mod diff;
31−mod dirs;
32−mod inputfile;
33−mod line_range;
3428mod output;
35−mod preprocessor;
3629mod printer;
37−mod style;
38−mod syntax_mapping;
39−mod terminal;
40−mod util;
4130
4231use std::collections::HashSet;
4332use std::io;
@@ -48,39 +37,18 @@ use std::process;
4837use ansi_term::Colour::Green;
4938use ansi_term::Style;
5039
51−use crate::app::{App, Config};
52−use crate::assets::{cache_dir, clear_assets, config_dir, HighlightingAssets};
53−use crate::config::config_file;
54−use crate::controller::Controller;
55−use crate::inputfile::InputFile;
56−use crate::style::{OutputComponent, OutputComponents};
57−
58−mod errors {
59− error_chain! {
60− foreign_links {
61− Clap(::clap::Error);
62− Io(::std::io::Error);
63− SyntectError(::syntect::LoadingError);
64− ParseIntError(::std::num::ParseIntError);
65− }
66− }
67−
68− pub fn handle_error(error: &Error) {
69− match error {
70− Error(ErrorKind::Io(ref io_error), _)
71− if io_error.kind() == super::io::ErrorKind::BrokenPipe =>
72− {
73− super::process::exit(0);
74− }
75− _ => {
76− use ansi_term::Colour::Red;
77− eprintln!("{}: {}", Red.paint("[bat error]"), error);
78− }
79− };
80− }
81−}
82−
83−use crate::errors::*;
40+use crate::{
41+ app::{App, Config},
42+ controller::Controller,
43+};
44+
45+use bat::{
46+ assets::{cache_dir, clear_assets, config_dir, HighlightingAssets},
47+ config::config_file,
48+ errors::*,
49+ inputfile::InputFile,
50+ style::{OutputComponent, OutputComponents},
51+};
8452
8553fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
8654 if matches.is_present("build") {
src/bin/bat/output.rs+1−1
@@ -7,7 +7,7 @@ use std::process::{Child, Command, Stdio};
77use shell_words;
88
99use crate::app::PagingMode;
10−use crate::errors::*;
10+use bat::errors::*;
1111
1212pub enum OutputType {
1313 Pager(Child),
src/bin/bat/printer.rs+14−11
@@ -16,18 +16,21 @@ use content_inspector::ContentType;
1616use encoding::all::{UTF_16BE, UTF_16LE};
1717use encoding::{DecoderTrap, Encoding};
1818
19−use crate::app::Config;
20−use crate::assets::HighlightingAssets;
21−use crate::decorations::{
22− Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration,
19+use crate::{
20+ app::Config,
21+ decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration},
22+};
23+
24+use bat::{
25+ assets::HighlightingAssets,
26+ diff::get_git_diff,
27+ diff::LineChanges,
28+ errors::*,
29+ inputfile::{InputFile, InputFileReader},
30+ preprocessor::{expand_tabs, replace_nonprintable},
31+ style::OutputWrap,
32+ terminal::{as_terminal_escaped, to_ansi_color},
2333};
24−use crate::diff::get_git_diff;
25−use crate::diff::LineChanges;
26−use crate::errors::*;
27−use crate::inputfile::{InputFile, InputFileReader};
28−use crate::preprocessor::{expand_tabs, replace_nonprintable};
29−use crate::style::OutputWrap;
30−use crate::terminal::{as_terminal_escaped, to_ansi_color};
3134
3235pub trait Printer {
3336 fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()>;
src/lib.rs+15−1
@@ -30,7 +30,7 @@ pub mod syntax_mapping;
3030pub mod terminal;
3131pub mod util;
3232
33−mod errors {
33+pub mod errors {
3434 error_chain! {
3535 foreign_links {
3636 Clap(::clap::Error);
@@ -39,4 +39,18 @@ mod errors {
3939 ParseIntError(::std::num::ParseIntError);
4040 }
4141 }
42+
43+ pub fn handle_error(error: &Error) {
44+ match error {
45+ Error(ErrorKind::Io(ref io_error), _)
46+ if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
47+ {
48+ ::std::process::exit(0);
49+ }
50+ _ => {
51+ use ansi_term::Colour::Red;
52+ eprintln!("{}: {}", Red.paint("[bat error]"), error);
53+ }
54+ };
55+ }
4256}