on 3334f74 help sign in
bat/src/lib.rs
131 lines 3.1 kB history raw
1// `error_chain!` can recurse deeply
2#![recursion_limit = "1024"]
4#[macro_use]
5extern crate error_chain;
7#[macro_use]
8extern crate lazy_static;
10extern crate ansi_term;
11extern crate atty;
12extern crate console;
13extern crate content_inspector;
14extern crate dirs as dirs_rs;
15extern crate encoding;
16extern crate git2;
17extern crate shell_words;
18extern crate syntect;
19extern crate wild;
21pub mod assets;
22pub mod controller;
23pub mod decorations;
24pub mod diff;
25pub mod dirs;
26pub mod inputfile;
27pub mod line_range;
28pub mod output;
29pub mod preprocessor;
30pub mod printer;
31pub mod style;
32pub mod syntax_mapping;
33pub mod terminal;
35pub mod errors {
36 error_chain! {
37 foreign_links {
38 Clap(::clap::Error);
39 Io(::std::io::Error);
40 SyntectError(::syntect::LoadingError);
41 ParseIntError(::std::num::ParseIntError);
42 }
43 }
45 pub fn handle_error(error: &Error) {
46 match error {
47 Error(ErrorKind::Io(ref io_error), _)
48 if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
49 {
50 ::std::process::exit(0);
51 }
52 _ => {
53 use ansi_term::Colour::Red;
54 eprintln!("{}: {}", Red.paint("[bat error]"), error);
55 }
56 };
57 }
60#[derive(Debug, Clone, Copy, PartialEq)]
61pub enum PagingMode {
62 Always,
63 QuitIfOneScreen,
64 Never,
67impl Default for PagingMode {
68 fn default() -> Self {
69 PagingMode::Never
70 }
73use inputfile::InputFile;
74use line_range::LineRanges;
75use style::{OutputComponents, OutputWrap};
76use syntax_mapping::SyntaxMapping;
78#[derive(Debug, Clone, Default)]
79pub struct Config<'a> {
80 /// List of files to print
81 pub files: Vec<InputFile<'a>>,
83 /// The explicitly configured language, if any
84 pub language: Option<&'a str>,
86 /// Whether or not to show/replace non-printable characters like space, tab and newline.
87 pub show_nonprintable: bool,
89 /// The character width of the terminal
90 pub term_width: usize,
92 /// The width of tab characters.
93 /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
94 pub tab_width: usize,
96 /// Whether or not to simply loop through all input (`cat` mode)
97 pub loop_through: bool,
99 /// Whether or not the output should be colorized
100 pub colored_output: bool,
102 /// Whether or not the output terminal supports true color
103 pub true_color: bool,
105 /// Style elements (grid, line numbers, ...)
106 pub output_components: OutputComponents,
108 /// Text wrapping mode
109 pub output_wrap: OutputWrap,
111 /// Pager or STDOUT
112 pub paging_mode: PagingMode,
114 /// Specifies the lines that should be printed
115 pub line_ranges: LineRanges,
117 /// The syntax highlighting theme
118 pub theme: String,
120 /// File extension/name mappings
121 pub syntax_mapping: SyntaxMapping,
123 /// Command to start the pager
124 pub pager: Option<&'a str>,
126 /// Whether or not to use ANSI italics
127 pub use_italic_text: bool,
129 /// Lines to highlight
130 pub highlight_lines: Vec<usize>,