From 6498615f5fb047bef7d84072747676a74fa89c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tau=20G=C3=A4rtli?= Date: Tue, 16 Apr 2024 14:43:33 +0200 Subject: [PATCH] Improve upon the documentation --- src/pretty_printer.rs | 4 +++- src/theme.rs | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs index eb123ea3..51c9af80 100644 --- a/src/pretty_printer.rs +++ b/src/pretty_printer.rs @@ -245,7 +245,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) -> &mut Self { self.config.theme = theme.as_ref().to_owned(); self diff --git a/src/theme.rs b/src/theme.rs index b60184fb..54db307b 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -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, @@ -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,