mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-08 22:11:16 +01:00
Move error module to separate file
This commit is contained in:
parent
fedd32173e
commit
7e0115641d
24
src/errors.rs
Normal file
24
src/errors.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use error_chain::error_chain;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
41
src/lib.rs
41
src/lib.rs
@ -1,9 +1,6 @@
|
|||||||
// `error_chain!` can recurse deeply
|
// `error_chain!` can recurse deeply
|
||||||
#![recursion_limit = "1024"]
|
#![recursion_limit = "1024"]
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate error_chain;
|
|
||||||
|
|
||||||
extern crate ansi_term;
|
extern crate ansi_term;
|
||||||
extern crate atty;
|
extern crate atty;
|
||||||
extern crate console;
|
extern crate console;
|
||||||
@ -19,6 +16,7 @@ pub mod assets;
|
|||||||
pub mod controller;
|
pub mod controller;
|
||||||
mod decorations;
|
mod decorations;
|
||||||
mod diff;
|
mod diff;
|
||||||
|
pub mod errors;
|
||||||
pub mod inputfile;
|
pub mod inputfile;
|
||||||
mod less;
|
mod less;
|
||||||
pub mod line_range;
|
pub mod line_range;
|
||||||
@ -29,31 +27,6 @@ pub mod style;
|
|||||||
pub mod syntax_mapping;
|
pub mod syntax_mapping;
|
||||||
mod terminal;
|
mod terminal;
|
||||||
|
|
||||||
pub 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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum PagingMode {
|
pub enum PagingMode {
|
||||||
Always,
|
Always,
|
||||||
@ -68,7 +41,7 @@ impl Default for PagingMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use inputfile::InputFile;
|
use inputfile::InputFile;
|
||||||
use line_range::{LineRanges, HighlightedLineRanges};
|
use line_range::{HighlightedLineRanges, LineRanges};
|
||||||
use style::{OutputComponents, OutputWrap};
|
use style::{OutputComponents, OutputWrap};
|
||||||
use syntax_mapping::SyntaxMapping;
|
use syntax_mapping::SyntaxMapping;
|
||||||
|
|
||||||
@ -131,12 +104,18 @@ pub struct Config<'a> {
|
|||||||
fn default_config_should_include_all_lines() {
|
fn default_config_should_include_all_lines() {
|
||||||
use line_range::RangeCheckResult;
|
use line_range::RangeCheckResult;
|
||||||
|
|
||||||
assert_eq!(Config::default().line_ranges.check(17), RangeCheckResult::InRange);
|
assert_eq!(
|
||||||
|
Config::default().line_ranges.check(17),
|
||||||
|
RangeCheckResult::InRange
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_config_should_highlight_no_lines() {
|
fn default_config_should_highlight_no_lines() {
|
||||||
use line_range::RangeCheckResult;
|
use line_range::RangeCheckResult;
|
||||||
|
|
||||||
assert_ne!(Config::default().highlighted_lines.0.check(17), RangeCheckResult::InRange);
|
assert_ne!(
|
||||||
|
Config::default().highlighted_lines.0.check(17),
|
||||||
|
RangeCheckResult::InRange
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user