diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs
index 2adee7d8..7b4bb38d 100644
--- a/src/bin/bat/app.rs
+++ b/src/bin/bat/app.rs
@@ -19,7 +19,8 @@ use bat::{
errors::*,
input::Input,
line_range::{HighlightedLineRanges, LineRange, LineRanges},
- MappingTarget, StyleComponent, StyleComponents, SyntaxMapping, WrappingMode,
+ style::{StyleComponent, StyleComponents},
+ MappingTarget, SyntaxMapping, WrappingMode,
};
fn is_truecolor_terminal() -> bool {
diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs
index 16ada31a..03dee71e 100644
--- a/src/bin/bat/main.rs
+++ b/src/bin/bat/main.rs
@@ -26,8 +26,12 @@ use clap::crate_version;
use directories::PROJECT_DIRS;
use bat::{
- assets::HighlightingAssets, config::Config, controller::Controller, errors::*, input::Input,
- StyleComponent, StyleComponents,
+ assets::HighlightingAssets,
+ config::Config,
+ controller::Controller,
+ errors::*,
+ input::Input,
+ style::{StyleComponent, StyleComponents},
};
fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
diff --git a/src/lib.rs b/src/lib.rs
index bc697cb4..234bc1f1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,13 +32,12 @@ mod output;
mod preprocessor;
mod pretty_printer;
pub(crate) mod printer;
-pub(crate) mod style;
+pub mod style;
pub(crate) mod syntax_mapping;
mod terminal;
pub(crate) mod wrapping;
pub use line_range::LineRange;
pub use pretty_printer::PrettyPrinter;
-pub use style::{StyleComponent, StyleComponents};
pub use syntax_mapping::{MappingTarget, SyntaxMapping};
pub use wrapping::WrappingMode;
diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs
index 1dc621ea..188a48de 100644
--- a/src/pretty_printer.rs
+++ b/src/pretty_printer.rs
@@ -10,12 +10,22 @@ use crate::{
errors::Result,
input::Input,
line_range::{HighlightedLineRanges, LineRanges},
- LineRange, StyleComponent, StyleComponents, SyntaxMapping, WrappingMode,
+ style::{StyleComponent, StyleComponents},
+ LineRange, SyntaxMapping, WrappingMode,
};
#[cfg(feature = "paging")]
use crate::config::PagingMode;
+#[derive(Default)]
+struct ActiveStyleComponents {
+ header: bool,
+ vcs_modification_markers: bool,
+ grid: bool,
+ line_numbers: bool,
+ snip: bool,
+}
+
pub struct PrettyPrinter<'a> {
inputs: Vec>,
config: Config<'a>,
@@ -23,6 +33,7 @@ pub struct PrettyPrinter<'a> {
highlighted_lines: Vec,
term_width: Option,
+ active_style_components: ActiveStyleComponents,
}
impl<'a> PrettyPrinter<'a> {
@@ -39,6 +50,7 @@ impl<'a> PrettyPrinter<'a> {
highlighted_lines: vec![],
term_width: None,
+ active_style_components: ActiveStyleComponents::default(),
}
}
@@ -107,9 +119,33 @@ impl<'a> PrettyPrinter<'a> {
self
}
- /// Configure style elements like grid or line numbers (default: "full" style)
- pub fn style_components(&mut self, components: &[StyleComponent]) -> &mut Self {
- self.config.style_components = StyleComponents::new(components);
+ /// Whether to show a header with the file name
+ pub fn header(&mut self, yes: bool) -> &mut Self {
+ self.active_style_components.header = yes;
+ self
+ }
+
+ /// Whether to show line numbers
+ pub fn line_numbers(&mut self, yes: bool) -> &mut Self {
+ self.active_style_components.line_numbers = yes;
+ self
+ }
+
+ /// Whether to paint a grid, separating line numbers, git changes and the code
+ pub fn grid(&mut self, yes: bool) -> &mut Self {
+ self.active_style_components.grid = yes;
+ self
+ }
+
+ /// Whether to show modification markers for VCS changes
+ pub fn vcs_modification_markers(&mut self, yes: bool) -> &mut Self {
+ self.active_style_components.vcs_modification_markers = yes;
+ self
+ }
+
+ /// Whether to show "snip" markers between visible line ranges (default: no)
+ pub fn snip(&mut self, yes: bool) -> &mut Self {
+ self.active_style_components.snip = yes;
self
}
@@ -175,6 +211,24 @@ impl<'a> PrettyPrinter<'a> {
.term_width
.unwrap_or_else(|| Term::stdout().size().1 as usize);
+ let mut style_components = vec![];
+ if self.active_style_components.grid {
+ style_components.push(StyleComponent::Grid);
+ }
+ if self.active_style_components.header {
+ style_components.push(StyleComponent::Header);
+ }
+ if self.active_style_components.line_numbers {
+ style_components.push(StyleComponent::LineNumbers);
+ }
+ if self.active_style_components.snip {
+ style_components.push(StyleComponent::Snip);
+ }
+ if self.active_style_components.vcs_modification_markers {
+ style_components.push(StyleComponent::Changes);
+ }
+ self.config.style_components = StyleComponents::new(&style_components);
+
let mut inputs: Vec = vec![];
std::mem::swap(&mut inputs, &mut self.inputs);