on 6739230 help sign in
bat/src/lib.rs
132 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;
23mod decorations;
24mod diff;
25pub mod dirs;
26pub mod inputfile;
27mod less;
28pub mod line_range;
29mod output;
30mod preprocessor;
31mod printer;
32pub mod style;
33pub mod syntax_mapping;
34mod terminal;
36pub mod errors {
37 error_chain! {
38 foreign_links {
39 Clap(::clap::Error);
40 Io(::std::io::Error);
41 SyntectError(::syntect::LoadingError);
42 ParseIntError(::std::num::ParseIntError);
43 }
44 }
46 pub fn handle_error(error: &Error) {
47 match error {
48 Error(ErrorKind::Io(ref io_error), _)
49 if io_error.kind() == ::std::io::ErrorKind::BrokenPipe =>
50 {
51 ::std::process::exit(0);
52 }
53 _ => {
54 use ansi_term::Colour::Red;
55 eprintln!("{}: {}", Red.paint("[bat error]"), error);
56 }
57 };
58 }
61#[derive(Debug, Clone, Copy, PartialEq)]
62pub enum PagingMode {
63 Always,
64 QuitIfOneScreen,
65 Never,
68impl Default for PagingMode {
69 fn default() -> Self {
70 PagingMode::Never
71 }
74use inputfile::InputFile;
75use line_range::LineRanges;
76use style::{OutputComponents, OutputWrap};
77use syntax_mapping::SyntaxMapping;
79#[derive(Debug, Clone, Default)]
80pub struct Config<'a> {
81 /// List of files to print
82 pub files: Vec<InputFile<'a>>,
84 /// The explicitly configured language, if any
85 pub language: Option<&'a str>,
87 /// Whether or not to show/replace non-printable characters like space, tab and newline.
88 pub show_nonprintable: bool,
90 /// The character width of the terminal
91 pub term_width: usize,
93 /// The width of tab characters.
94 /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
95 pub tab_width: usize,
97 /// Whether or not to simply loop through all input (`cat` mode)
98 pub loop_through: bool,
100 /// Whether or not the output should be colorized
101 pub colored_output: bool,
103 /// Whether or not the output terminal supports true color
104 pub true_color: bool,
106 /// Style elements (grid, line numbers, ...)
107 pub output_components: OutputComponents,
109 /// Text wrapping mode
110 pub output_wrap: OutputWrap,
112 /// Pager or STDOUT
113 pub paging_mode: PagingMode,
115 /// Specifies the lines that should be printed
116 pub line_ranges: LineRanges,
118 /// The syntax highlighting theme
119 pub theme: String,
121 /// File extension/name mappings
122 pub syntax_mapping: SyntaxMapping,
124 /// Command to start the pager
125 pub pager: Option<&'a str>,
127 /// Whether or not to use ANSI italics
128 pub use_italic_text: bool,
130 /// Lines to highlight
131 pub highlight_lines: LineRanges,