on master help sign in
Move Config,PagingMode from app.rs into lib.rs
commit26439b41d2b5a7d68f8e6fe22ccd1299bd7c5ccc authorFahmi Akbar Wildana <f.a.wildana@gmail.com> dateSun 6 Oct 2019, 08:44 (7 years ago) parenta2ee753
6 files changed+75−73
src/bin/bat/app.rs+1−62 src/bin/bat/controller.rs+1−1 src/bin/bat/main.rs+2−5 src/bin/bat/output.rs+1−2 src/bin/bat/printer.rs+3−3 src/lib.rs+67
src/bin/bat/app.rs+1−62
@@ -24,70 +24,9 @@ use bat::{
2424 style::{OutputComponent, OutputComponents, OutputWrap},
2525 syntax_mapping::SyntaxMapping,
2626 util::transpose,
27+ Config, PagingMode,
2728};
2829
29−#[derive(Debug, Clone, Copy, PartialEq)]
30−pub enum PagingMode {
31− Always,
32− QuitIfOneScreen,
33− Never,
34−}
35−
36−#[derive(Clone)]
37−pub struct Config<'a> {
38− /// List of files to print
39− pub files: Vec<InputFile<'a>>,
40−
41− /// The explicitly configured language, if any
42− pub language: Option<&'a str>,
43−
44− /// Whether or not to show/replace non-printable characters like space, tab and newline.
45− pub show_nonprintable: bool,
46−
47− /// The character width of the terminal
48− pub term_width: usize,
49−
50− /// The width of tab characters.
51− /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
52− pub tab_width: usize,
53−
54− /// Whether or not to simply loop through all input (`cat` mode)
55− pub loop_through: bool,
56−
57− /// Whether or not the output should be colorized
58− pub colored_output: bool,
59−
60− /// Whether or not the output terminal supports true color
61− pub true_color: bool,
62−
63− /// Style elements (grid, line numbers, ...)
64− pub output_components: OutputComponents,
65−
66− /// Text wrapping mode
67− pub output_wrap: OutputWrap,
68−
69− /// Pager or STDOUT
70− pub paging_mode: PagingMode,
71−
72− /// Specifies the lines that should be printed
73− pub line_ranges: LineRanges,
74−
75− /// The syntax highlighting theme
76− pub theme: String,
77−
78− /// File extension/name mappings
79− pub syntax_mapping: SyntaxMapping,
80−
81− /// Command to start the pager
82− pub pager: Option<&'a str>,
83−
84− /// Whether or not to use ANSI italics
85− pub use_italic_text: bool,
86−
87− /// Lines to highlight
88− pub highlight_lines: Vec<usize>,
89−}
90−
9130fn is_truecolor_terminal() -> bool {
9231 env::var("COLORTERM")
9332 .map(|colorterm| colorterm == "truecolor" || colorterm == "24bit")
src/bin/bat/controller.rs+1−1
@@ -2,7 +2,6 @@ use std::io::{self, Write};
22use std::path::Path;
33
44use crate::{
5− app::{Config, PagingMode},
65 output::OutputType,
76 printer::{InteractivePrinter, Printer, SimplePrinter},
87};
@@ -12,6 +11,7 @@ use bat::{
1211 errors::*,
1312 inputfile::{InputFile, InputFileReader},
1413 line_range::{LineRanges, RangeCheckResult},
14+ Config, PagingMode,
1515};
1616
1717pub struct Controller<'a> {
src/bin/bat/main.rs+2−5
@@ -21,17 +21,14 @@ use std::process;
2121use ansi_term::Colour::Green;
2222use ansi_term::Style;
2323
24−use crate::{
25− app::{App, Config},
26− config::config_file,
27− controller::Controller,
28−};
24+use crate::{app::App, config::config_file, controller::Controller};
2925
3026use bat::{
3127 assets::{cache_dir, clear_assets, config_dir, HighlightingAssets},
3228 errors::*,
3329 inputfile::InputFile,
3430 style::{OutputComponent, OutputComponents},
31+ Config,
3532};
3633
3734fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
src/bin/bat/output.rs+1−2
@@ -6,8 +6,7 @@ use std::process::{Child, Command, Stdio};
66
77use shell_words;
88
9−use crate::app::PagingMode;
10−use bat::errors::*;
9+use bat::{errors::*, PagingMode};
1110
1211pub enum OutputType {
1312 Pager(Child),
src/bin/bat/printer.rs+3−3
@@ -16,9 +16,8 @@ use content_inspector::ContentType;
1616use encoding::all::{UTF_16BE, UTF_16LE};
1717use encoding::{DecoderTrap, Encoding};
1818
19−use crate::{
20− app::Config,
21− decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration},
19+use crate::decorations::{
20+ Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration,
2221};
2322
2423use bat::{
@@ -30,6 +29,7 @@ use bat::{
3029 preprocessor::{expand_tabs, replace_nonprintable},
3130 style::OutputWrap,
3231 terminal::{as_terminal_escaped, to_ansi_color},
32+ Config,
3333};
3434
3535pub trait Printer {
src/lib.rs+67
@@ -52,4 +52,71 @@ pub mod errors {
5252 }
5353 };
5454 }
55+}
56+
57+#[derive(Debug, Clone, Copy, PartialEq)]
58+pub enum PagingMode {
59+ Always,
60+ QuitIfOneScreen,
61+ Never,
62+}
63+
64+use inputfile::InputFile;
65+use line_range::LineRanges;
66+use style::{OutputComponents, OutputWrap};
67+use syntax_mapping::SyntaxMapping;
68+
69+#[derive(Clone)]
70+pub struct Config<'a> {
71+ /// List of files to print
72+ pub files: Vec<InputFile<'a>>,
73+
74+ /// The explicitly configured language, if any
75+ pub language: Option<&'a str>,
76+
77+ /// Whether or not to show/replace non-printable characters like space, tab and newline.
78+ pub show_nonprintable: bool,
79+
80+ /// The character width of the terminal
81+ pub term_width: usize,
82+
83+ /// The width of tab characters.
84+ /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
85+ pub tab_width: usize,
86+
87+ /// Whether or not to simply loop through all input (`cat` mode)
88+ pub loop_through: bool,
89+
90+ /// Whether or not the output should be colorized
91+ pub colored_output: bool,
92+
93+ /// Whether or not the output terminal supports true color
94+ pub true_color: bool,
95+
96+ /// Style elements (grid, line numbers, ...)
97+ pub output_components: OutputComponents,
98+
99+ /// Text wrapping mode
100+ pub output_wrap: OutputWrap,
101+
102+ /// Pager or STDOUT
103+ pub paging_mode: PagingMode,
104+
105+ /// Specifies the lines that should be printed
106+ pub line_ranges: LineRanges,
107+
108+ /// The syntax highlighting theme
109+ pub theme: String,
110+
111+ /// File extension/name mappings
112+ pub syntax_mapping: SyntaxMapping,
113+
114+ /// Command to start the pager
115+ pub pager: Option<&'a str>,
116+
117+ /// Whether or not to use ANSI italics
118+ pub use_italic_text: bool,
119+
120+ /// Lines to highlight
121+ pub highlight_lines: Vec<usize>,
55122}