Improve upon the documentation

This commit is contained in:
Tau Gärtli 2024-04-16 14:43:33 +02:00
parent e72a95f3ab
commit 360f95be61
No known key found for this signature in database
2 changed files with 15 additions and 6 deletions

View File

@ -236,7 +236,9 @@ impl<'a> PrettyPrinter<'a> {
self
}
/// Specify the highlighting theme
/// Specify the highlighting theme.
/// You can use [`crate::theme::theme`] to pick a theme based on user preferences
/// and the terminal's background color.
pub fn theme(&mut self, theme: impl AsRef<str>) -> &mut Self {
self.config.theme = theme.as_ref().to_owned();
self

View File

@ -11,7 +11,7 @@ pub fn theme(options: ThemeOptions) -> String {
}
/// The default theme, suitable for the given color scheme.
/// Use [`theme`], if you want to automatically detect the color scheme from the terminal.
/// Use [`theme`] if you want to automatically detect the color scheme from the terminal.
pub const fn default_theme(color_scheme: ColorScheme) -> &'static str {
match color_scheme {
ColorScheme::Dark => "Monokai Extended",
@ -21,7 +21,7 @@ pub const fn default_theme(color_scheme: ColorScheme) -> &'static str {
/// Options for configuring the theme used for syntax highlighting.
/// Used together with [`theme`].
#[derive(Debug, Default)]
#[derive(Debug, Default, PartialEq, Eq)]
pub struct ThemeOptions {
/// Always use this theme regardless of the terminal's background color.
pub theme: Option<ThemeRequest>,
@ -34,7 +34,14 @@ pub struct ThemeOptions {
}
/// The name of a theme or the default theme.
#[derive(Debug)]
///
/// ```
/// # use bat::theme::ThemeRequest;
/// # use std::str::FromStr as _;
/// assert_eq!(ThemeRequest::Default, ThemeRequest::from_str("default").unwrap());
/// assert_eq!(ThemeRequest::Named("example".to_string()), ThemeRequest::from_str("example").unwrap());
/// ```
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum ThemeRequest {
Named(String),
Default,
@ -61,7 +68,7 @@ impl ThemeRequest {
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DetectColorScheme {
/// Only query the terminal for its colors when appropriate (i.e. when the the output is not redirected).
#[default]
@ -73,7 +80,7 @@ pub enum DetectColorScheme {
}
/// The color scheme used to pick a fitting theme. Defaults to [`ColorScheme::Dark`].
#[derive(Default, Copy, Clone)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ColorScheme {
#[default]
Dark,