mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-31 02:01:05 +00:00
move Config struct to separate file
This commit is contained in:
parent
7e0115641d
commit
9b8ddb24d1
@ -3,7 +3,7 @@ use bat::{
|
|||||||
controller::Controller,
|
controller::Controller,
|
||||||
inputfile::InputFile,
|
inputfile::InputFile,
|
||||||
style::{OutputComponent, OutputComponents},
|
style::{OutputComponent, OutputComponents},
|
||||||
Config,
|
config::Config,
|
||||||
};
|
};
|
||||||
use console::Term;
|
use console::Term;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
@ -23,7 +23,7 @@ use bat::{
|
|||||||
line_range::{HighlightedLineRanges, LineRange, LineRanges},
|
line_range::{HighlightedLineRanges, LineRange, LineRanges},
|
||||||
style::{OutputComponent, OutputComponents, OutputWrap},
|
style::{OutputComponent, OutputComponents, OutputWrap},
|
||||||
syntax_mapping::SyntaxMapping,
|
syntax_mapping::SyntaxMapping,
|
||||||
Config, PagingMode,
|
config::{Config, PagingMode},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn is_truecolor_terminal() -> bool {
|
fn is_truecolor_terminal() -> bool {
|
||||||
|
@ -32,7 +32,7 @@ use bat::{
|
|||||||
errors::*,
|
errors::*,
|
||||||
inputfile::InputFile,
|
inputfile::InputFile,
|
||||||
style::{OutputComponent, OutputComponents},
|
style::{OutputComponent, OutputComponents},
|
||||||
Config,
|
config::Config,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
|
fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
|
||||||
|
92
src/config.rs
Normal file
92
src/config.rs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
use crate::inputfile::InputFile;
|
||||||
|
use crate::line_range::{HighlightedLineRanges, LineRanges};
|
||||||
|
use crate::style::{OutputComponents, OutputWrap};
|
||||||
|
use crate::syntax_mapping::SyntaxMapping;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
pub enum PagingMode {
|
||||||
|
Always,
|
||||||
|
QuitIfOneScreen,
|
||||||
|
Never,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PagingMode {
|
||||||
|
fn default() -> Self {
|
||||||
|
PagingMode::Never
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
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,
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
);
|
||||||
|
}
|
@ -7,7 +7,7 @@ use crate::inputfile::{InputFile, InputFileReader};
|
|||||||
use crate::line_range::{LineRanges, RangeCheckResult};
|
use crate::line_range::{LineRanges, RangeCheckResult};
|
||||||
use crate::output::OutputType;
|
use crate::output::OutputType;
|
||||||
use crate::printer::{InteractivePrinter, Printer, SimplePrinter};
|
use crate::printer::{InteractivePrinter, Printer, SimplePrinter};
|
||||||
use crate::{Config, PagingMode};
|
use crate::config::{Config, PagingMode};
|
||||||
|
|
||||||
pub struct Controller<'a> {
|
pub struct Controller<'a> {
|
||||||
config: &'a Config<'a>,
|
config: &'a Config<'a>,
|
||||||
|
94
src/lib.rs
94
src/lib.rs
@ -13,6 +13,7 @@ extern crate syntect;
|
|||||||
extern crate wild;
|
extern crate wild;
|
||||||
|
|
||||||
pub mod assets;
|
pub mod assets;
|
||||||
|
pub mod config;
|
||||||
pub mod controller;
|
pub mod controller;
|
||||||
mod decorations;
|
mod decorations;
|
||||||
mod diff;
|
mod diff;
|
||||||
@ -26,96 +27,3 @@ mod printer;
|
|||||||
pub mod style;
|
pub mod style;
|
||||||
pub mod syntax_mapping;
|
pub mod syntax_mapping;
|
||||||
mod terminal;
|
mod terminal;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
||||||
pub enum PagingMode {
|
|
||||||
Always,
|
|
||||||
QuitIfOneScreen,
|
|
||||||
Never,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for PagingMode {
|
|
||||||
fn default() -> Self {
|
|
||||||
PagingMode::Never
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use inputfile::InputFile;
|
|
||||||
use line_range::{HighlightedLineRanges, LineRanges};
|
|
||||||
use style::{OutputComponents, OutputWrap};
|
|
||||||
use syntax_mapping::SyntaxMapping;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
|
||||||
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,
|
|
||||||
|
|
||||||
/// 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;
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
Config::default().line_ranges.check(17),
|
|
||||||
RangeCheckResult::InRange
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn default_config_should_highlight_no_lines() {
|
|
||||||
use line_range::RangeCheckResult;
|
|
||||||
|
|
||||||
assert_ne!(
|
|
||||||
Config::default().highlighted_lines.0.check(17),
|
|
||||||
RangeCheckResult::InRange
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
@ -8,7 +8,7 @@ use shell_words;
|
|||||||
|
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::less::retrieve_less_version;
|
use crate::less::retrieve_less_version;
|
||||||
use crate::PagingMode;
|
use crate::config::PagingMode;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum OutputType {
|
pub enum OutputType {
|
||||||
|
@ -31,7 +31,7 @@ use crate::line_range::RangeCheckResult;
|
|||||||
use crate::preprocessor::{expand_tabs, replace_nonprintable};
|
use crate::preprocessor::{expand_tabs, replace_nonprintable};
|
||||||
use crate::style::OutputWrap;
|
use crate::style::OutputWrap;
|
||||||
use crate::terminal::{as_terminal_escaped, to_ansi_color};
|
use crate::terminal::{as_terminal_escaped, to_ansi_color};
|
||||||
use crate::Config;
|
use crate::config::Config;
|
||||||
|
|
||||||
pub trait Printer {
|
pub trait Printer {
|
||||||
fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()>;
|
fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user