mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-21 12:28:30 +00:00
Reduce public API
This commit is contained in:
parent
26c951fec4
commit
13e6b3fac7
@ -14,8 +14,11 @@ use clap::ArgMatches;
|
|||||||
use console::Term;
|
use console::Term;
|
||||||
|
|
||||||
use bat::{
|
use bat::{
|
||||||
assets::HighlightingAssets, config::Config, errors::*, input::Input, HighlightedLineRanges,
|
assets::HighlightingAssets,
|
||||||
LineRange, LineRanges, MappingTarget, PagingMode, StyleComponent, StyleComponents,
|
config::{Config, PagingMode},
|
||||||
|
errors::*,
|
||||||
|
input::Input,
|
||||||
|
HighlightedLineRanges, LineRange, LineRanges, MappingTarget, StyleComponent, StyleComponents,
|
||||||
SyntaxMapping, WrappingMode,
|
SyntaxMapping, WrappingMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,12 +4,12 @@ use crate::printer::{Colors, InteractivePrinter};
|
|||||||
use ansi_term::Style;
|
use ansi_term::Style;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DecorationText {
|
pub(crate) struct DecorationText {
|
||||||
pub width: usize,
|
pub width: usize,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Decoration {
|
pub(crate) trait Decoration {
|
||||||
fn generate(
|
fn generate(
|
||||||
&self,
|
&self,
|
||||||
line_number: usize,
|
line_number: usize,
|
||||||
@ -19,14 +19,14 @@ pub trait Decoration {
|
|||||||
fn width(&self) -> usize;
|
fn width(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LineNumberDecoration {
|
pub(crate) struct LineNumberDecoration {
|
||||||
color: Style,
|
color: Style,
|
||||||
cached_wrap: DecorationText,
|
cached_wrap: DecorationText,
|
||||||
cached_wrap_invalid_at: usize,
|
cached_wrap_invalid_at: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LineNumberDecoration {
|
impl LineNumberDecoration {
|
||||||
pub fn new(colors: &Colors) -> Self {
|
pub(crate) fn new(colors: &Colors) -> Self {
|
||||||
LineNumberDecoration {
|
LineNumberDecoration {
|
||||||
color: colors.line_number,
|
color: colors.line_number,
|
||||||
cached_wrap_invalid_at: 10000,
|
cached_wrap_invalid_at: 10000,
|
||||||
@ -70,7 +70,7 @@ impl Decoration for LineNumberDecoration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "git")]
|
#[cfg(feature = "git")]
|
||||||
pub struct LineChangesDecoration {
|
pub(crate) struct LineChangesDecoration {
|
||||||
cached_none: DecorationText,
|
cached_none: DecorationText,
|
||||||
cached_added: DecorationText,
|
cached_added: DecorationText,
|
||||||
cached_removed_above: DecorationText,
|
cached_removed_above: DecorationText,
|
||||||
@ -88,7 +88,7 @@ impl LineChangesDecoration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(colors: &Colors) -> Self {
|
pub(crate) fn new(colors: &Colors) -> Self {
|
||||||
LineChangesDecoration {
|
LineChangesDecoration {
|
||||||
cached_none: Self::generate_cached(Style::default(), " "),
|
cached_none: Self::generate_cached(Style::default(), " "),
|
||||||
cached_added: Self::generate_cached(colors.git_added, "+"),
|
cached_added: Self::generate_cached(colors.git_added, "+"),
|
||||||
@ -127,12 +127,12 @@ impl Decoration for LineChangesDecoration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GridBorderDecoration {
|
pub(crate) struct GridBorderDecoration {
|
||||||
cached: DecorationText,
|
cached: DecorationText,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GridBorderDecoration {
|
impl GridBorderDecoration {
|
||||||
pub fn new(colors: &Colors) -> Self {
|
pub(crate) fn new(colors: &Colors) -> Self {
|
||||||
GridBorderDecoration {
|
GridBorderDecoration {
|
||||||
cached: DecorationText {
|
cached: DecorationText {
|
||||||
text: colors.grid.paint("│").to_string(),
|
text: colors.grid.paint("│").to_string(),
|
||||||
|
26
src/input.rs
26
src/input.rs
@ -9,13 +9,13 @@ use crate::errors::*;
|
|||||||
const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs");
|
const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs");
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct InputDescription {
|
pub(crate) struct InputDescription {
|
||||||
pub full: String,
|
pub full: String,
|
||||||
pub prefix: String,
|
pub prefix: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum InputKind<'a> {
|
pub(crate) enum InputKind<'a> {
|
||||||
OrdinaryFile(OsString),
|
OrdinaryFile(OsString),
|
||||||
StdIn,
|
StdIn,
|
||||||
ThemePreviewFile,
|
ThemePreviewFile,
|
||||||
@ -23,26 +23,26 @@ pub enum InputKind<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct InputMetadata {
|
pub(crate) struct InputMetadata {
|
||||||
pub user_provided_name: Option<OsString>,
|
pub(crate) user_provided_name: Option<OsString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Input<'a> {
|
pub struct Input<'a> {
|
||||||
pub kind: InputKind<'a>,
|
pub(crate) kind: InputKind<'a>,
|
||||||
pub metadata: InputMetadata,
|
pub(crate) metadata: InputMetadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum OpenedInputKind {
|
pub(crate) enum OpenedInputKind {
|
||||||
OrdinaryFile(OsString),
|
OrdinaryFile(OsString),
|
||||||
StdIn,
|
StdIn,
|
||||||
ThemePreviewFile,
|
ThemePreviewFile,
|
||||||
CustomReader,
|
CustomReader,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct OpenedInput<'a> {
|
pub(crate) struct OpenedInput<'a> {
|
||||||
pub kind: OpenedInputKind,
|
pub(crate) kind: OpenedInputKind,
|
||||||
pub metadata: InputMetadata,
|
pub(crate) metadata: InputMetadata,
|
||||||
pub reader: InputReader<'a>,
|
pub(crate) reader: InputReader<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Input<'a> {
|
impl<'a> Input<'a> {
|
||||||
@ -86,7 +86,7 @@ impl<'a> Input<'a> {
|
|||||||
self.metadata.user_provided_name = provided_name.map(|n| n.to_owned());
|
self.metadata.user_provided_name = provided_name.map(|n| n.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open<R: BufRead + 'a>(self, stdin: R) -> Result<OpenedInput<'a>> {
|
pub(crate) fn open<R: BufRead + 'a>(self, stdin: R) -> Result<OpenedInput<'a>> {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
InputKind::StdIn => Ok(OpenedInput {
|
InputKind::StdIn => Ok(OpenedInput {
|
||||||
kind: OpenedInputKind::StdIn,
|
kind: OpenedInputKind::StdIn,
|
||||||
@ -154,7 +154,7 @@ impl<'a> OpenedInput<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InputReader<'a> {
|
pub(crate) struct InputReader<'a> {
|
||||||
inner: Box<dyn BufRead + 'a>,
|
inner: Box<dyn BufRead + 'a>,
|
||||||
pub(crate) first_line: Vec<u8>,
|
pub(crate) first_line: Vec<u8>,
|
||||||
pub(crate) content_type: Option<ContentType>,
|
pub(crate) content_type: Option<ContentType>,
|
||||||
|
28
src/lib.rs
28
src/lib.rs
@ -1,14 +1,15 @@
|
|||||||
/// `bat` is a library to print syntax highlighted content.
|
//! `bat` is a library to print syntax highlighted content.
|
||||||
///
|
//!
|
||||||
/// ```
|
//! ```
|
||||||
/// use bat::PrettyPrinter;
|
//! use bat::PrettyPrinter;
|
||||||
///
|
//!
|
||||||
/// PrettyPrinter::new()
|
//! PrettyPrinter::new()
|
||||||
/// .input_from_bytes(b"<span style=\"color: #ff00cc\">Hello world!</span>\n")
|
//! .input_from_bytes(b"<span style=\"color: #ff00cc\">Hello world!</span>\n")
|
||||||
/// .language("html")
|
//! .language("html")
|
||||||
/// .run()
|
//! .run()
|
||||||
/// .expect("no errors");
|
//! .expect("no errors");
|
||||||
/// ```
|
//! ```
|
||||||
|
|
||||||
pub mod assets;
|
pub mod assets;
|
||||||
pub mod assets_metadata;
|
pub mod assets_metadata;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
@ -21,7 +22,7 @@ mod less;
|
|||||||
pub(crate) mod line_range;
|
pub(crate) mod line_range;
|
||||||
mod output;
|
mod output;
|
||||||
mod preprocessor;
|
mod preprocessor;
|
||||||
pub mod pretty_printer;
|
mod pretty_printer;
|
||||||
pub(crate) mod printer;
|
pub(crate) mod printer;
|
||||||
pub(crate) mod style;
|
pub(crate) mod style;
|
||||||
pub(crate) mod syntax_mapping;
|
pub(crate) mod syntax_mapping;
|
||||||
@ -33,6 +34,3 @@ pub use pretty_printer::PrettyPrinter;
|
|||||||
pub use style::{StyleComponent, StyleComponents};
|
pub use style::{StyleComponent, StyleComponents};
|
||||||
pub use syntax_mapping::{MappingTarget, SyntaxMapping};
|
pub use syntax_mapping::{MappingTarget, SyntaxMapping};
|
||||||
pub use wrap::WrappingMode;
|
pub use wrap::WrappingMode;
|
||||||
|
|
||||||
#[cfg(feature = "paging")]
|
|
||||||
pub use config::PagingMode;
|
|
||||||
|
@ -32,7 +32,7 @@ use crate::preprocessor::{expand_tabs, replace_nonprintable};
|
|||||||
use crate::terminal::{as_terminal_escaped, to_ansi_color};
|
use crate::terminal::{as_terminal_escaped, to_ansi_color};
|
||||||
use crate::wrap::WrappingMode;
|
use crate::wrap::WrappingMode;
|
||||||
|
|
||||||
pub trait Printer {
|
pub(crate) trait Printer {
|
||||||
fn print_header(&mut self, handle: &mut dyn Write, input: &OpenedInput) -> Result<()>;
|
fn print_header(&mut self, handle: &mut dyn Write, input: &OpenedInput) -> Result<()>;
|
||||||
fn print_footer(&mut self, handle: &mut dyn Write, input: &OpenedInput) -> Result<()>;
|
fn print_footer(&mut self, handle: &mut dyn Write, input: &OpenedInput) -> Result<()>;
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ impl Printer for SimplePrinter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InteractivePrinter<'a> {
|
pub(crate) struct InteractivePrinter<'a> {
|
||||||
colors: Colors,
|
colors: Colors,
|
||||||
config: &'a Config<'a>,
|
config: &'a Config<'a>,
|
||||||
decorations: Vec<Box<dyn Decoration>>,
|
decorations: Vec<Box<dyn Decoration>>,
|
||||||
@ -97,7 +97,7 @@ pub struct InteractivePrinter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> InteractivePrinter<'a> {
|
impl<'a> InteractivePrinter<'a> {
|
||||||
pub fn new(
|
pub(crate) fn new(
|
||||||
config: &'a Config,
|
config: &'a Config,
|
||||||
assets: &'a HighlightingAssets,
|
assets: &'a HighlightingAssets,
|
||||||
input: &mut OpenedInput,
|
input: &mut OpenedInput,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user