2019-10-06 03:49:33 +02:00
|
|
|
// `error_chain!` can recurse deeply
|
|
|
|
#![recursion_limit = "1024"]
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate error_chain;
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
|
|
|
extern crate ansi_term;
|
|
|
|
extern crate atty;
|
|
|
|
extern crate console;
|
|
|
|
extern crate content_inspector;
|
|
|
|
extern crate dirs as dirs_rs;
|
|
|
|
extern crate encoding;
|
|
|
|
extern crate git2;
|
|
|
|
extern crate shell_words;
|
|
|
|
extern crate syntect;
|
|
|
|
extern crate wild;
|
|
|
|
|
2019-10-06 04:18:08 +02:00
|
|
|
pub mod assets;
|
2019-10-06 03:44:14 +02:00
|
|
|
pub mod controller;
|
|
|
|
pub mod decorations;
|
2019-10-06 04:18:08 +02:00
|
|
|
pub mod diff;
|
|
|
|
pub mod dirs;
|
|
|
|
pub mod inputfile;
|
|
|
|
pub mod line_range;
|
2019-10-06 03:44:14 +02:00
|
|
|
pub mod output;
|
2019-10-06 04:18:08 +02:00
|
|
|
pub mod preprocessor;
|
2019-10-06 03:44:14 +02:00
|
|
|
pub mod printer;
|
2019-10-06 04:18:08 +02:00
|
|
|
pub mod style;
|
|
|
|
pub mod syntax_mapping;
|
|
|
|
pub mod terminal;
|
|
|
|
pub mod util;
|
2019-10-06 04:10:03 +02:00
|
|
|
|
2019-10-06 04:10:03 +02:00
|
|
|
pub mod errors {
|
2019-10-06 04:10:03 +02:00
|
|
|
error_chain! {
|
|
|
|
foreign_links {
|
|
|
|
Clap(::clap::Error);
|
|
|
|
Io(::std::io::Error);
|
|
|
|
SyntectError(::syntect::LoadingError);
|
|
|
|
ParseIntError(::std::num::ParseIntError);
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 04:10:03 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-10-06 03:44:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum PagingMode {
|
|
|
|
Always,
|
|
|
|
QuitIfOneScreen,
|
|
|
|
Never,
|
|
|
|
}
|
|
|
|
|
|
|
|
use inputfile::InputFile;
|
|
|
|
use line_range::LineRanges;
|
|
|
|
use style::{OutputComponents, OutputWrap};
|
|
|
|
use syntax_mapping::SyntaxMapping;
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Config<'a> {
|
|
|
|
/// List of files to print
|
|
|
|
pub files: Vec<InputFile<'a>>,
|
|
|
|
|
|
|
|
/// The explicitly configured language, if any
|
|
|
|
pub language: Option<&'a str>,
|
|
|
|
|
|
|
|
/// Whether or not to show/replace non-printable characters like space, tab and newline.
|
|
|
|
pub show_nonprintable: bool,
|
|
|
|
|
|
|
|
/// The character width of the terminal
|
|
|
|
pub term_width: usize,
|
|
|
|
|
|
|
|
/// The width of tab characters.
|
|
|
|
/// Currently, a value of 0 will cause tabs to be passed through without expanding them.
|
|
|
|
pub tab_width: usize,
|
|
|
|
|
|
|
|
/// Whether or not to simply loop through all input (`cat` mode)
|
|
|
|
pub loop_through: bool,
|
|
|
|
|
|
|
|
/// Whether or not the output should be colorized
|
|
|
|
pub colored_output: bool,
|
|
|
|
|
|
|
|
/// Whether or not the output terminal supports true color
|
|
|
|
pub true_color: bool,
|
|
|
|
|
|
|
|
/// Style elements (grid, line numbers, ...)
|
|
|
|
pub output_components: OutputComponents,
|
|
|
|
|
|
|
|
/// Text wrapping mode
|
|
|
|
pub output_wrap: OutputWrap,
|
|
|
|
|
|
|
|
/// Pager or STDOUT
|
|
|
|
pub paging_mode: PagingMode,
|
|
|
|
|
|
|
|
/// Specifies the lines that should be printed
|
|
|
|
pub line_ranges: LineRanges,
|
|
|
|
|
|
|
|
/// The syntax highlighting theme
|
|
|
|
pub theme: String,
|
|
|
|
|
|
|
|
/// File extension/name mappings
|
|
|
|
pub syntax_mapping: SyntaxMapping,
|
|
|
|
|
|
|
|
/// Command to start the pager
|
|
|
|
pub pager: Option<&'a str>,
|
|
|
|
|
|
|
|
/// Whether or not to use ANSI italics
|
|
|
|
pub use_italic_text: bool,
|
|
|
|
|
|
|
|
/// Lines to highlight
|
|
|
|
pub highlight_lines: Vec<usize>,
|
2019-10-06 03:44:14 +02:00
|
|
|
}
|