summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2020-04-22 18:30:06 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2020-04-22 23:55:28 +0200
commit13e6b3fac7440a487f4c5952345f20ac681b571f (patch)
tree777a93d624d8f4d81c4542765645f938244ff167
parent26c951fec485e21e2f28f6704590b55c16f00257 (diff)
Reduce public API
-rw-r--r--src/bin/bat/app.rs7
-rw-r--r--src/decorations.rs16
-rw-r--r--src/input.rs26
-rw-r--r--src/lib.rs28
-rw-r--r--src/printer.rs6
5 files changed, 42 insertions, 41 deletions
diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs
index 3ed47c07..a290b7f0 100644
--- a/src/bin/bat/app.rs
+++ b/src/bin/bat/app.rs
@@ -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,
};
diff --git a/src/decorations.rs b/src/decorations.rs
index 1b44d05a..2647b0f8 100644
--- a/src/decorations.rs
+++ b/src/decorations.rs
@@ -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(),
diff --git a/src/input.rs b/src/input.rs
index 2f981c55..95b4eff3 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -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>,
diff --git a/src/lib.rs b/src/lib.rs
index f3bda196..8997564b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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;
diff --git a/src/printer.rs b/src/printer.rs
index 324f0a39..baa3e995 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -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,