on master help sign in
move Config struct to separate file
commit9b8ddb24d1de32f82c8da1ff04967ee47a544533 authorsharkdp <davidpeter@web.de> dateSat 21 Mar 2020, 19:40 (7 years ago) parent7e01156
8 files changed+99−99
examples/simple.rs+1−1 src/bin/bat/app.rs+1−1 src/bin/bat/main.rs+1−1 src/config.rs+92 src/controller.rs+1−1 src/lib.rs+1−93 src/output.rs+1−1 src/printer.rs+1−1
examples/simple.rs+1−1
@@ -3,7 +3,7 @@ use bat::{
33 controller::Controller,
44 inputfile::InputFile,
55 style::{OutputComponent, OutputComponents},
6− Config,
6+ config::Config,
77};
88use console::Term;
99use std::process;
src/bin/bat/app.rs+1−1
@@ -23,7 +23,7 @@ use bat::{
2323 line_range::{HighlightedLineRanges, LineRange, LineRanges},
2424 style::{OutputComponent, OutputComponents, OutputWrap},
2525 syntax_mapping::SyntaxMapping,
26− Config, PagingMode,
26+ config::{Config, PagingMode},
2727};
2828
2929fn is_truecolor_terminal() -> bool {
src/bin/bat/main.rs+1−1
@@ -32,7 +32,7 @@ use bat::{
3232 errors::*,
3333 inputfile::InputFile,
3434 style::{OutputComponent, OutputComponents},
35− Config,
35+ config::Config,
3636};
3737
3838fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
src/config.rsnew file+92
@@ -0,0 +1,92 @@
1+use crate::inputfile::InputFile;
2+use crate::line_range::{HighlightedLineRanges, LineRanges};
3+use crate::style::{OutputComponents, OutputWrap};
4+use crate::syntax_mapping::SyntaxMapping;
5+
6+#[derive(Debug, Clone, Copy, PartialEq)]
7+pub enum PagingMode {
8+ Always,
9+ QuitIfOneScreen,
10+ Never,
11+}
12+
13+impl Default for PagingMode {
14+ fn default() -> Self {
15+ PagingMode::Never
16+ }
17+}
18+
19+#[derive(Debug, Clone, Default)]
20+pub struct Config<'a> {
21+ /// List of files to print
22+ pub files: Vec<InputFile<'a>>,
23+
24+ /// The explicitly configured language, if any
25+ pub language: Option<&'a str>,
26+
27+ /// Whether or not to show/replace non-printable characters like space, tab and newline.
28+ pub show_nonprintable: bool,
29+
30+ /// The character width of the terminal
31+ pub term_width: usize,
32+
33+ /// The width of tab characters.
34+ /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
35+ pub tab_width: usize,
36+
37+ /// Whether or not to simply loop through all input (`cat` mode)
38+ pub loop_through: bool,
39+
40+ /// Whether or not the output should be colorized
41+ pub colored_output: bool,
42+
43+ /// Whether or not the output terminal supports true color
44+ pub true_color: bool,
45+
46+ /// Style elements (grid, line numbers, ...)
47+ pub output_components: OutputComponents,
48+
49+ /// Text wrapping mode
50+ pub output_wrap: OutputWrap,
51+
52+ /// Pager or STDOUT
53+ pub paging_mode: PagingMode,
54+
55+ /// Specifies the lines that should be printed
56+ pub line_ranges: LineRanges,
57+
58+ /// The syntax highlighting theme
59+ pub theme: String,
60+
61+ /// File extension/name mappings
62+ pub syntax_mapping: SyntaxMapping,
63+
64+ /// Command to start the pager
65+ pub pager: Option<&'a str>,
66+
67+ /// Whether or not to use ANSI italics
68+ pub use_italic_text: bool,
69+
70+ /// Ranges of lines which should be highlighted with a special background color
71+ pub highlighted_lines: HighlightedLineRanges,
72+}
73+
74+#[test]
75+fn default_config_should_include_all_lines() {
76+ use crate::line_range::RangeCheckResult;
77+
78+ assert_eq!(
79+ Config::default().line_ranges.check(17),
80+ RangeCheckResult::InRange
81+ );
82+}
83+
84+#[test]
85+fn default_config_should_highlight_no_lines() {
86+ use crate::line_range::RangeCheckResult;
87+
88+ assert_ne!(
89+ Config::default().highlighted_lines.0.check(17),
90+ RangeCheckResult::InRange
91+ );
92+}
src/controller.rs+1−1
@@ -7,7 +7,7 @@ use crate::inputfile::{InputFile, InputFileReader};
77use crate::line_range::{LineRanges, RangeCheckResult};
88use crate::output::OutputType;
99use crate::printer::{InteractivePrinter, Printer, SimplePrinter};
10−use crate::{Config, PagingMode};
10+use crate::config::{Config, PagingMode};
1111
1212pub struct Controller<'a> {
1313 config: &'a Config<'a>,
src/lib.rs+1−93
@@ -13,6 +13,7 @@ extern crate syntect;
1313extern crate wild;
1414
1515pub mod assets;
16+pub mod config;
1617pub mod controller;
1718mod decorations;
1819mod diff;
@@ -26,96 +27,3 @@ mod printer;
2627pub mod style;
2728pub mod syntax_mapping;
2829mod terminal;
29−
30−#[derive(Debug, Clone, Copy, PartialEq)]
31−pub enum PagingMode {
32− Always,
33− QuitIfOneScreen,
34− Never,
35−}
36−
37−impl Default for PagingMode {
38− fn default() -> Self {
39− PagingMode::Never
40− }
41−}
42−
43−use inputfile::InputFile;
44−use line_range::{HighlightedLineRanges, LineRanges};
45−use style::{OutputComponents, OutputWrap};
46−use syntax_mapping::SyntaxMapping;
47−
48−#[derive(Debug, Clone, Default)]
49−pub struct Config<'a> {
50− /// List of files to print
51− pub files: Vec<InputFile<'a>>,
52−
53− /// The explicitly configured language, if any
54− pub language: Option<&'a str>,
55−
56− /// Whether or not to show/replace non-printable characters like space, tab and newline.
57− pub show_nonprintable: bool,
58−
59− /// The character width of the terminal
60− pub term_width: usize,
61−
62− /// The width of tab characters.
63− /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
64− pub tab_width: usize,
65−
66− /// Whether or not to simply loop through all input (`cat` mode)
67− pub loop_through: bool,
68−
69− /// Whether or not the output should be colorized
70− pub colored_output: bool,
71−
72− /// Whether or not the output terminal supports true color
73− pub true_color: bool,
74−
75− /// Style elements (grid, line numbers, ...)
76− pub output_components: OutputComponents,
77−
78− /// Text wrapping mode
79− pub output_wrap: OutputWrap,
80−
81− /// Pager or STDOUT
82− pub paging_mode: PagingMode,
83−
84− /// Specifies the lines that should be printed
85− pub line_ranges: LineRanges,
86−
87− /// The syntax highlighting theme
88− pub theme: String,
89−
90− /// File extension/name mappings
91− pub syntax_mapping: SyntaxMapping,
92−
93− /// Command to start the pager
94− pub pager: Option<&'a str>,
95−
96− /// Whether or not to use ANSI italics
97− pub use_italic_text: bool,
98−
99− /// Ranges of lines which should be highlighted with a special background color
100− pub highlighted_lines: HighlightedLineRanges,
101−}
102−
103−#[test]
104−fn default_config_should_include_all_lines() {
105− use line_range::RangeCheckResult;
106−
107− assert_eq!(
108− Config::default().line_ranges.check(17),
109− RangeCheckResult::InRange
110− );
111−}
112−
113−#[test]
114−fn default_config_should_highlight_no_lines() {
115− use line_range::RangeCheckResult;
116−
117− assert_ne!(
118− Config::default().highlighted_lines.0.check(17),
119− RangeCheckResult::InRange
120− );
121−}
src/output.rs+1−1
@@ -8,7 +8,7 @@ use shell_words;
88
99use crate::errors::*;
1010use crate::less::retrieve_less_version;
11−use crate::PagingMode;
11+use crate::config::PagingMode;
1212
1313#[derive(Debug)]
1414pub enum OutputType {
src/printer.rs+1−1
@@ -31,7 +31,7 @@ use crate::line_range::RangeCheckResult;
3131use crate::preprocessor::{expand_tabs, replace_nonprintable};
3232use crate::style::OutputWrap;
3333use crate::terminal::{as_terminal_escaped, to_ansi_color};
34−use crate::Config;
34+use crate::config::Config;
3535
3636pub trait Printer {
3737 fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()>;