2019-10-06 08:49:33 +07:00
|
|
|
// `error_chain!` can recurse deeply
|
|
|
|
#![recursion_limit = "1024"]
|
|
|
|
|
|
|
|
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 09:18:08 +07:00
|
|
|
pub mod assets;
|
2019-10-06 08:44:14 +07:00
|
|
|
pub mod controller;
|
2019-10-20 22:09:58 +02:00
|
|
|
mod decorations;
|
|
|
|
mod diff;
|
2020-03-21 19:35:04 +01:00
|
|
|
pub mod errors;
|
2019-10-06 09:18:08 +07:00
|
|
|
pub mod inputfile;
|
2019-12-23 09:54:18 +01:00
|
|
|
mod less;
|
2019-10-06 09:18:08 +07:00
|
|
|
pub mod line_range;
|
2019-10-29 19:46:04 +01:00
|
|
|
mod output;
|
2019-10-20 22:09:58 +02:00
|
|
|
mod preprocessor;
|
2019-10-29 19:46:04 +01:00
|
|
|
mod printer;
|
2019-10-06 09:18:08 +07:00
|
|
|
pub mod style;
|
|
|
|
pub mod syntax_mapping;
|
2019-10-20 22:09:58 +02:00
|
|
|
mod terminal;
|
2019-10-06 09:10:03 +07:00
|
|
|
|
2019-10-06 08:44:14 +07:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum PagingMode {
|
|
|
|
Always,
|
|
|
|
QuitIfOneScreen,
|
|
|
|
Never,
|
|
|
|
}
|
|
|
|
|
2019-10-15 08:18:26 +07:00
|
|
|
impl Default for PagingMode {
|
|
|
|
fn default() -> Self {
|
2019-10-15 12:17:37 +07:00
|
|
|
PagingMode::Never
|
2019-10-15 08:18:26 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 08:44:14 +07:00
|
|
|
use inputfile::InputFile;
|
2020-03-21 19:35:04 +01:00
|
|
|
use line_range::{HighlightedLineRanges, LineRanges};
|
2019-10-06 08:44:14 +07:00
|
|
|
use style::{OutputComponents, OutputWrap};
|
|
|
|
use syntax_mapping::SyntaxMapping;
|
|
|
|
|
2019-10-15 08:25:53 +07:00
|
|
|
#[derive(Debug, Clone, Default)]
|
2019-10-06 08:44:14 +07:00
|
|
|
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,
|
|
|
|
|
2020-03-21 17:22:17 +01:00
|
|
|
/// Ranges of lines which should be highlighted with a special background color
|
|
|
|
pub highlighted_lines: HighlightedLineRanges,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_config_should_include_all_lines() {
|
|
|
|
use line_range::RangeCheckResult;
|
|
|
|
|
2020-03-21 19:35:04 +01:00
|
|
|
assert_eq!(
|
|
|
|
Config::default().line_ranges.check(17),
|
|
|
|
RangeCheckResult::InRange
|
|
|
|
);
|
2020-03-21 17:22:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_config_should_highlight_no_lines() {
|
|
|
|
use line_range::RangeCheckResult;
|
|
|
|
|
2020-03-21 19:35:04 +01:00
|
|
|
assert_ne!(
|
|
|
|
Config::default().highlighted_lines.0.check(17),
|
|
|
|
RangeCheckResult::InRange
|
|
|
|
);
|
2019-10-06 08:44:14 +07:00
|
|
|
}
|