Reduce public API

This commit is contained in:
sharkdp 2020-04-22 18:30:06 +02:00 committed by David Peter
parent 26c951fec4
commit 13e6b3fac7
5 changed files with 42 additions and 41 deletions

View File

@ -14,8 +14,11 @@ use clap::ArgMatches;
use console::Term;
use bat::{
assets::HighlightingAssets, config::Config, errors::*, input::Input, HighlightedLineRanges,
LineRange, LineRanges, MappingTarget, PagingMode, StyleComponent, StyleComponents,
assets::HighlightingAssets,
config::{Config, PagingMode},
errors::*,
input::Input,
HighlightedLineRanges, LineRange, LineRanges, MappingTarget, StyleComponent, StyleComponents,
SyntaxMapping, WrappingMode,
};

View File

@ -4,12 +4,12 @@ use crate::printer::{Colors, InteractivePrinter};
use ansi_term::Style;
#[derive(Debug, Clone)]
pub struct DecorationText {
pub(crate) struct DecorationText {
pub width: usize,
pub text: String,
}
pub trait Decoration {
pub(crate) trait Decoration {
fn generate(
&self,
line_number: usize,
@ -19,14 +19,14 @@ pub trait Decoration {
fn width(&self) -> usize;
}
pub struct LineNumberDecoration {
pub(crate) struct LineNumberDecoration {
color: Style,
cached_wrap: DecorationText,
cached_wrap_invalid_at: usize,
}
impl LineNumberDecoration {
pub fn new(colors: &Colors) -> Self {
pub(crate) fn new(colors: &Colors) -> Self {
LineNumberDecoration {
color: colors.line_number,
cached_wrap_invalid_at: 10000,
@ -70,7 +70,7 @@ impl Decoration for LineNumberDecoration {
}
#[cfg(feature = "git")]
pub struct LineChangesDecoration {
pub(crate) struct LineChangesDecoration {
cached_none: DecorationText,
cached_added: 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 {
cached_none: Self::generate_cached(Style::default(), " "),
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,
}
impl GridBorderDecoration {
pub fn new(colors: &Colors) -> Self {
pub(crate) fn new(colors: &Colors) -> Self {
GridBorderDecoration {
cached: DecorationText {
text: colors.grid.paint("").to_string(),

View File

@ -9,13 +9,13 @@ use crate::errors::*;
const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs");
#[derive(Debug, Clone)]
pub struct InputDescription {
pub(crate) struct InputDescription {
pub full: String,
pub prefix: String,
pub name: String,
}
pub enum InputKind<'a> {
pub(crate) enum InputKind<'a> {
OrdinaryFile(OsString),
StdIn,
ThemePreviewFile,
@ -23,26 +23,26 @@ pub enum InputKind<'a> {
}
#[derive(Clone, Default)]
pub struct InputMetadata {
pub user_provided_name: Option<OsString>,
pub(crate) struct InputMetadata {
pub(crate) user_provided_name: Option<OsString>,
}
pub struct Input<'a> {
pub kind: InputKind<'a>,
pub metadata: InputMetadata,
pub(crate) kind: InputKind<'a>,
pub(crate) metadata: InputMetadata,
}
pub enum OpenedInputKind {
pub(crate) enum OpenedInputKind {
OrdinaryFile(OsString),
StdIn,
ThemePreviewFile,
CustomReader,
}
pub struct OpenedInput<'a> {
pub kind: OpenedInputKind,
pub metadata: InputMetadata,
pub reader: InputReader<'a>,
pub(crate) struct OpenedInput<'a> {
pub(crate) kind: OpenedInputKind,
pub(crate) metadata: InputMetadata,
pub(crate) reader: InputReader<'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());
}
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 {
InputKind::StdIn => Ok(OpenedInput {
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>,
pub(crate) first_line: Vec<u8>,
pub(crate) content_type: Option<ContentType>,

View File

@ -1,14 +1,15 @@
/// `bat` is a library to print syntax highlighted content.
///
/// ```
/// use bat::PrettyPrinter;
///
/// PrettyPrinter::new()
/// .input_from_bytes(b"<span style=\"color: #ff00cc\">Hello world!</span>\n")
/// .language("html")
/// .run()
/// .expect("no errors");
/// ```
//! `bat` is a library to print syntax highlighted content.
//!
//! ```
//! use bat::PrettyPrinter;
//!
//! PrettyPrinter::new()
//! .input_from_bytes(b"<span style=\"color: #ff00cc\">Hello world!</span>\n")
//! .language("html")
//! .run()
//! .expect("no errors");
//! ```
pub mod assets;
pub mod assets_metadata;
pub mod config;
@ -21,7 +22,7 @@ mod less;
pub(crate) mod line_range;
mod output;
mod preprocessor;
pub mod pretty_printer;
mod pretty_printer;
pub(crate) mod printer;
pub(crate) mod style;
pub(crate) mod syntax_mapping;
@ -33,6 +34,3 @@ pub use pretty_printer::PrettyPrinter;
pub use style::{StyleComponent, StyleComponents};
pub use syntax_mapping::{MappingTarget, SyntaxMapping};
pub use wrap::WrappingMode;
#[cfg(feature = "paging")]
pub use config::PagingMode;

View File

@ -32,7 +32,7 @@ use crate::preprocessor::{expand_tabs, replace_nonprintable};
use crate::terminal::{as_terminal_escaped, to_ansi_color};
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_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,
config: &'a Config<'a>,
decorations: Vec<Box<dyn Decoration>>,
@ -97,7 +97,7 @@ pub struct InteractivePrinter<'a> {
}
impl<'a> InteractivePrinter<'a> {
pub fn new(
pub(crate) fn new(
config: &'a Config,
assets: &'a HighlightingAssets,
input: &mut OpenedInput,