diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index af403acc..670fe56f 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -24,70 +24,9 @@ use bat::{ style::{OutputComponent, OutputComponents, OutputWrap}, syntax_mapping::SyntaxMapping, util::transpose, + Config, PagingMode, }; -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum PagingMode { - Always, - QuitIfOneScreen, - Never, -} - -#[derive(Clone)] -pub struct Config<'a> { - /// List of files to print - pub files: Vec>, - - /// 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, - - /// Lines to highlight - pub highlight_lines: Vec, -} - fn is_truecolor_terminal() -> bool { env::var("COLORTERM") .map(|colorterm| colorterm == "truecolor" || colorterm == "24bit") diff --git a/src/bin/bat/controller.rs b/src/bin/bat/controller.rs index dea78c2b..dae0667b 100644 --- a/src/bin/bat/controller.rs +++ b/src/bin/bat/controller.rs @@ -2,7 +2,6 @@ use std::io::{self, Write}; use std::path::Path; use crate::{ - app::{Config, PagingMode}, output::OutputType, printer::{InteractivePrinter, Printer, SimplePrinter}, }; @@ -12,6 +11,7 @@ use bat::{ errors::*, inputfile::{InputFile, InputFileReader}, line_range::{LineRanges, RangeCheckResult}, + Config, PagingMode, }; pub struct Controller<'a> { diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 51855ca8..f8eb9805 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -21,17 +21,14 @@ use std::process; use ansi_term::Colour::Green; use ansi_term::Style; -use crate::{ - app::{App, Config}, - config::config_file, - controller::Controller, -}; +use crate::{app::App, config::config_file, controller::Controller}; use bat::{ assets::{cache_dir, clear_assets, config_dir, HighlightingAssets}, errors::*, inputfile::InputFile, style::{OutputComponent, OutputComponents}, + Config, }; fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> { diff --git a/src/bin/bat/output.rs b/src/bin/bat/output.rs index 79919630..58b9e416 100644 --- a/src/bin/bat/output.rs +++ b/src/bin/bat/output.rs @@ -6,8 +6,7 @@ use std::process::{Child, Command, Stdio}; use shell_words; -use crate::app::PagingMode; -use bat::errors::*; +use bat::{errors::*, PagingMode}; pub enum OutputType { Pager(Child), diff --git a/src/bin/bat/printer.rs b/src/bin/bat/printer.rs index 8ed21329..cf74d220 100644 --- a/src/bin/bat/printer.rs +++ b/src/bin/bat/printer.rs @@ -16,9 +16,8 @@ use content_inspector::ContentType; use encoding::all::{UTF_16BE, UTF_16LE}; use encoding::{DecoderTrap, Encoding}; -use crate::{ - app::Config, - decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration}, +use crate::decorations::{ + Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration, }; use bat::{ @@ -30,6 +29,7 @@ use bat::{ preprocessor::{expand_tabs, replace_nonprintable}, style::OutputWrap, terminal::{as_terminal_escaped, to_ansi_color}, + Config, }; pub trait Printer { diff --git a/src/lib.rs b/src/lib.rs index db8ff804..99e17f19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,4 +52,71 @@ pub mod errors { } }; } +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum PagingMode { + Always, + QuitIfOneScreen, + Never, +} + +use inputfile::InputFile; +use line_range::LineRanges; +use style::{OutputComponents, OutputWrap}; +use syntax_mapping::SyntaxMapping; + +#[derive(Clone)] +pub struct Config<'a> { + /// List of files to print + pub files: Vec>, + + /// 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, + + /// Lines to highlight + pub highlight_lines: Vec, } \ No newline at end of file