mirror of
https://github.com/sharkdp/bat.git
synced 2024-12-23 23:08:54 +01:00
Move Config,PagingMode from app.rs into lib.rs
This commit is contained in:
parent
a2ee753b25
commit
26439b41d2
@ -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<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,
|
||||
|
||||
/// Lines to highlight
|
||||
pub highlight_lines: Vec<usize>,
|
||||
}
|
||||
|
||||
fn is_truecolor_terminal() -> bool {
|
||||
env::var("COLORTERM")
|
||||
.map(|colorterm| colorterm == "truecolor" || colorterm == "24bit")
|
||||
|
@ -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> {
|
||||
|
@ -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<()> {
|
||||
|
@ -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),
|
||||
|
@ -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 {
|
||||
|
67
src/lib.rs
67
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<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,
|
||||
|
||||
/// Lines to highlight
|
||||
pub highlight_lines: Vec<usize>,
|
||||
}
|
Loading…
Reference in New Issue
Block a user