on master help sign in
Reduce public API
commit13e6b3fac7440a487f4c5952345f20ac681b571f authorsharkdp <davidpeter@web.de> dateWed 22 Apr 2020, 18:30 (7 years ago) parent26c951f
5 files changed+42−41
src/bin/bat/app.rs+5−2 src/decorations.rs+8−8 src/input.rs+13−13 src/lib.rs+13−15 src/printer.rs+3−3
src/bin/bat/app.rs+5−2
@@ -14,8 +14,11 @@ use clap::ArgMatches;
1414use console::Term;
1515
1616use bat::{
17− assets::HighlightingAssets, config::Config, errors::*, input::Input, HighlightedLineRanges,
18− LineRange, LineRanges, MappingTarget, PagingMode, StyleComponent, StyleComponents,
17+ assets::HighlightingAssets,
18+ config::{Config, PagingMode},
19+ errors::*,
20+ input::Input,
21+ HighlightedLineRanges, LineRange, LineRanges, MappingTarget, StyleComponent, StyleComponents,
1922 SyntaxMapping, WrappingMode,
2023};
2124
src/decorations.rs+8−8
@@ -4,12 +4,12 @@ use crate::printer::{Colors, InteractivePrinter};
44use ansi_term::Style;
55
66#[derive(Debug, Clone)]
7−pub struct DecorationText {
7+pub(crate) struct DecorationText {
88 pub width: usize,
99 pub text: String,
1010}
1111
12−pub trait Decoration {
12+pub(crate) trait Decoration {
1313 fn generate(
1414 &self,
1515 line_number: usize,
@@ -19,14 +19,14 @@ pub trait Decoration {
1919 fn width(&self) -> usize;
2020}
2121
22−pub struct LineNumberDecoration {
22+pub(crate) struct LineNumberDecoration {
2323 color: Style,
2424 cached_wrap: DecorationText,
2525 cached_wrap_invalid_at: usize,
2626}
2727
2828impl LineNumberDecoration {
29− pub fn new(colors: &Colors) -> Self {
29+ pub(crate) fn new(colors: &Colors) -> Self {
3030 LineNumberDecoration {
3131 color: colors.line_number,
3232 cached_wrap_invalid_at: 10000,
@@ -70,7 +70,7 @@ impl Decoration for LineNumberDecoration {
7070}
7171
7272#[cfg(feature = "git")]
73−pub struct LineChangesDecoration {
73+pub(crate) struct LineChangesDecoration {
7474 cached_none: DecorationText,
7575 cached_added: DecorationText,
7676 cached_removed_above: DecorationText,
@@ -88,7 +88,7 @@ impl LineChangesDecoration {
8888 }
8989 }
9090
91− pub fn new(colors: &Colors) -> Self {
91+ pub(crate) fn new(colors: &Colors) -> Self {
9292 LineChangesDecoration {
9393 cached_none: Self::generate_cached(Style::default(), " "),
9494 cached_added: Self::generate_cached(colors.git_added, "+"),
@@ -127,12 +127,12 @@ impl Decoration for LineChangesDecoration {
127127 }
128128}
129129
130−pub struct GridBorderDecoration {
130+pub(crate) struct GridBorderDecoration {
131131 cached: DecorationText,
132132}
133133
134134impl GridBorderDecoration {
135− pub fn new(colors: &Colors) -> Self {
135+ pub(crate) fn new(colors: &Colors) -> Self {
136136 GridBorderDecoration {
137137 cached: DecorationText {
138138 text: colors.grid.paint("│").to_string(),
src/input.rs+13−13
@@ -9,13 +9,13 @@ use crate::errors::*;
99const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs");
1010
1111#[derive(Debug, Clone)]
12−pub struct InputDescription {
12+pub(crate) struct InputDescription {
1313 pub full: String,
1414 pub prefix: String,
1515 pub name: String,
1616}
1717
18−pub enum InputKind<'a> {
18+pub(crate) enum InputKind<'a> {
1919 OrdinaryFile(OsString),
2020 StdIn,
2121 ThemePreviewFile,
@@ -23,26 +23,26 @@ pub enum InputKind<'a> {
2323}
2424
2525#[derive(Clone, Default)]
26−pub struct InputMetadata {
27− pub user_provided_name: Option<OsString>,
26+pub(crate) struct InputMetadata {
27+ pub(crate) user_provided_name: Option<OsString>,
2828}
2929
3030pub struct Input<'a> {
31− pub kind: InputKind<'a>,
32− pub metadata: InputMetadata,
31+ pub(crate) kind: InputKind<'a>,
32+ pub(crate) metadata: InputMetadata,
3333}
3434
35−pub enum OpenedInputKind {
35+pub(crate) enum OpenedInputKind {
3636 OrdinaryFile(OsString),
3737 StdIn,
3838 ThemePreviewFile,
3939 CustomReader,
4040}
4141
42−pub struct OpenedInput<'a> {
43− pub kind: OpenedInputKind,
44− pub metadata: InputMetadata,
45− pub reader: InputReader<'a>,
42+pub(crate) struct OpenedInput<'a> {
43+ pub(crate) kind: OpenedInputKind,
44+ pub(crate) metadata: InputMetadata,
45+ pub(crate) reader: InputReader<'a>,
4646}
4747
4848impl<'a> Input<'a> {
@@ -86,7 +86,7 @@ impl<'a> Input<'a> {
8686 self.metadata.user_provided_name = provided_name.map(|n| n.to_owned());
8787 }
8888
89− pub fn open<R: BufRead + 'a>(self, stdin: R) -> Result<OpenedInput<'a>> {
89+ pub(crate) fn open<R: BufRead + 'a>(self, stdin: R) -> Result<OpenedInput<'a>> {
9090 match self.kind {
9191 InputKind::StdIn => Ok(OpenedInput {
9292 kind: OpenedInputKind::StdIn,
@@ -154,7 +154,7 @@ impl<'a> OpenedInput<'a> {
154154 }
155155}
156156
157−pub struct InputReader<'a> {
157+pub(crate) struct InputReader<'a> {
158158 inner: Box<dyn BufRead + 'a>,
159159 pub(crate) first_line: Vec<u8>,
160160 pub(crate) content_type: Option<ContentType>,
src/lib.rs+13−15
@@ -1,14 +1,15 @@
1−/// `bat` is a library to print syntax highlighted content.
2−///
3−/// ```
4−/// use bat::PrettyPrinter;
5−///
6−/// PrettyPrinter::new()
7−/// .input_from_bytes(b"<span style=\"color: #ff00cc\">Hello world!</span>\n")
8−/// .language("html")
9−/// .run()
10−/// .expect("no errors");
11−/// ```
1+//! `bat` is a library to print syntax highlighted content.
2+//!
3+//! ```
4+//! use bat::PrettyPrinter;
5+//!
6+//! PrettyPrinter::new()
7+//! .input_from_bytes(b"<span style=\"color: #ff00cc\">Hello world!</span>\n")
8+//! .language("html")
9+//! .run()
10+//! .expect("no errors");
11+//! ```
12+
1213pub mod assets;
1314pub mod assets_metadata;
1415pub mod config;
@@ -21,7 +22,7 @@ mod less;
2122pub(crate) mod line_range;
2223mod output;
2324mod preprocessor;
24−pub mod pretty_printer;
25+mod pretty_printer;
2526pub(crate) mod printer;
2627pub(crate) mod style;
2728pub(crate) mod syntax_mapping;
@@ -33,6 +34,3 @@ pub use pretty_printer::PrettyPrinter;
3334pub use style::{StyleComponent, StyleComponents};
3435pub use syntax_mapping::{MappingTarget, SyntaxMapping};
3536pub use wrap::WrappingMode;
36−
37−#[cfg(feature = "paging")]
38−pub use config::PagingMode;
src/printer.rs+3−3
@@ -32,7 +32,7 @@ use crate::preprocessor::{expand_tabs, replace_nonprintable};
3232use crate::terminal::{as_terminal_escaped, to_ansi_color};
3333use crate::wrap::WrappingMode;
3434
35−pub trait Printer {
35+pub(crate) trait Printer {
3636 fn print_header(&mut self, handle: &mut dyn Write, input: &OpenedInput) -> Result<()>;
3737 fn print_footer(&mut self, handle: &mut dyn Write, input: &OpenedInput) -> Result<()>;
3838
@@ -82,7 +82,7 @@ impl Printer for SimplePrinter {
8282 }
8383}
8484
85−pub struct InteractivePrinter<'a> {
85+pub(crate) struct InteractivePrinter<'a> {
8686 colors: Colors,
8787 config: &'a Config<'a>,
8888 decorations: Vec<Box<dyn Decoration>>,
@@ -97,7 +97,7 @@ pub struct InteractivePrinter<'a> {
9797}
9898
9999impl<'a> InteractivePrinter<'a> {
100− pub fn new(
100+ pub(crate) fn new(
101101 config: &'a Config,
102102 assets: &'a HighlightingAssets,
103103 input: &mut OpenedInput,