2020-03-21 21:03:57 +01:00
|
|
|
pub use crate::line_range::{HighlightedLineRanges, LineRange, LineRanges};
|
|
|
|
pub use crate::style::{StyleComponent, StyleComponents};
|
2020-03-22 09:55:13 +01:00
|
|
|
pub use crate::syntax_mapping::{MappingTarget, SyntaxMapping};
|
2020-04-21 20:06:09 +02:00
|
|
|
pub use crate::wrap::WrappingMode;
|
2020-03-21 19:40:13 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
2020-03-30 22:18:41 +02:00
|
|
|
#[cfg(feature = "paging")]
|
2020-03-21 19:40:13 +01:00
|
|
|
pub enum PagingMode {
|
|
|
|
Always,
|
|
|
|
QuitIfOneScreen,
|
|
|
|
Never,
|
|
|
|
}
|
|
|
|
|
2020-03-30 22:18:41 +02:00
|
|
|
#[cfg(feature = "paging")]
|
2020-03-21 19:40:13 +01:00
|
|
|
impl Default for PagingMode {
|
|
|
|
fn default() -> Self {
|
|
|
|
PagingMode::Never
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
|
|
pub struct Config<'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, ...)
|
2020-03-21 20:54:16 +01:00
|
|
|
pub style_components: StyleComponents,
|
2020-03-21 19:40:13 +01:00
|
|
|
|
2020-04-21 20:06:09 +02:00
|
|
|
/// If and how text should be wrapped
|
|
|
|
pub wrapping_mode: WrappingMode,
|
2020-03-21 19:40:13 +01:00
|
|
|
|
|
|
|
/// Pager or STDOUT
|
2020-03-30 22:18:41 +02:00
|
|
|
#[cfg(feature = "paging")]
|
2020-03-21 19:40:13 +01:00
|
|
|
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
|
2020-03-22 09:55:13 +01:00
|
|
|
pub syntax_mapping: SyntaxMapping<'a>,
|
2020-03-21 19:40:13 +01:00
|
|
|
|
|
|
|
/// Command to start the pager
|
|
|
|
pub pager: Option<&'a str>,
|
|
|
|
|
|
|
|
/// Whether or not to use ANSI italics
|
|
|
|
pub use_italic_text: bool,
|
|
|
|
|
|
|
|
/// 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 crate::line_range::RangeCheckResult;
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
Config::default().line_ranges.check(17),
|
|
|
|
RangeCheckResult::InRange
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_config_should_highlight_no_lines() {
|
|
|
|
use crate::line_range::RangeCheckResult;
|
|
|
|
|
|
|
|
assert_ne!(
|
|
|
|
Config::default().highlighted_lines.0.check(17),
|
|
|
|
RangeCheckResult::InRange
|
|
|
|
);
|
|
|
|
}
|