aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/atuin_client/theme.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/turtle/src/atuin_client/theme.rs')
-rw-r--r--crates/turtle/src/atuin_client/theme.rs52
1 files changed, 26 insertions, 26 deletions
diff --git a/crates/turtle/src/atuin_client/theme.rs b/crates/turtle/src/atuin_client/theme.rs
index 1d9c0b9e..21bbe07c 100644
--- a/crates/turtle/src/atuin_client/theme.rs
+++ b/crates/turtle/src/atuin_client/theme.rs
@@ -21,7 +21,7 @@ static DEFAULT_MAX_DEPTH: u8 = 10;
Serialize, Deserialize, Copy, Clone, Hash, Debug, Eq, PartialEq, strum_macros::Display,
)]
#[strum(serialize_all = "camel_case")]
-pub enum Meaning {
+pub(crate) enum Meaning {
AlertInfo,
AlertWarn,
AlertError,
@@ -34,31 +34,31 @@ pub enum Meaning {
}
#[derive(Clone, Debug, Deserialize, Serialize)]
-pub struct ThemeConfig {
+pub(crate) struct ThemeConfig {
// Definition of the theme
- pub theme: ThemeDefinitionConfigBlock,
+ pub(crate) theme: ThemeDefinitionConfigBlock,
// Colors
- pub colors: HashMap<Meaning, String>,
+ pub(crate) colors: HashMap<Meaning, String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
-pub struct ThemeDefinitionConfigBlock {
+pub(crate) struct ThemeDefinitionConfigBlock {
/// Name of theme ("default" for base)
- pub name: String,
+ pub(crate) name: String,
/// Whether any theme should be treated as a parent _if available_
- pub parent: Option<String>,
+ pub(crate) parent: Option<String>,
}
use crossterm::style::{Attribute, Attributes, Color, ContentStyle};
// For now, a theme is loaded as a mapping of meanings to colors, but it may be desirable to
// expand that in the future to general styles, so we populate a Meaning->ContentStyle hashmap.
-pub struct Theme {
- pub name: String,
- pub parent: Option<String>,
- pub styles: HashMap<Meaning, ContentStyle>,
+pub(crate) struct Theme {
+ pub(crate) name: String,
+ pub(crate) parent: Option<String>,
+ pub(crate) styles: HashMap<Meaning, ContentStyle>,
}
// Themes have a number of convenience functions for the most commonly used meanings.
@@ -66,29 +66,29 @@ pub struct Theme {
// theme-related boilerplate minimal, the convenience functions give a color.
impl Theme {
// This is the base "default" color, for general text
- pub fn get_base(&self) -> ContentStyle {
+ pub(crate) fn get_base(&self) -> ContentStyle {
self.styles[&Meaning::Base]
}
- pub fn get_info(&self) -> ContentStyle {
+ pub(crate) fn get_info(&self) -> ContentStyle {
self.get_alert(log::Level::Info)
}
- pub fn get_warning(&self) -> ContentStyle {
+ pub(crate) fn get_warning(&self) -> ContentStyle {
self.get_alert(log::Level::Warn)
}
- pub fn get_error(&self) -> ContentStyle {
+ pub(crate) fn get_error(&self) -> ContentStyle {
self.get_alert(log::Level::Error)
}
// The alert meanings may be chosen by the Level enum, rather than the methods above
// or the full Meaning enum, to simplify programmatic selection of a log-level.
- pub fn get_alert(&self, severity: log::Level) -> ContentStyle {
+ pub(crate) fn get_alert(&self, severity: log::Level) -> ContentStyle {
self.styles[ALERT_TYPES.get(&severity).unwrap()]
}
- pub fn new(
+ pub(crate) fn new(
name: String,
parent: Option<String>,
styles: HashMap<Meaning, ContentStyle>,
@@ -100,7 +100,7 @@ impl Theme {
}
}
- pub fn closest_meaning<'a>(&self, meaning: &'a Meaning) -> &'a Meaning {
+ pub(crate) fn closest_meaning<'a>(&self, meaning: &'a Meaning) -> &'a Meaning {
if self.styles.contains_key(meaning) {
meaning
} else if MEANING_FALLBACKS.contains_key(meaning) {
@@ -111,7 +111,7 @@ impl Theme {
}
// General access - if you have a meaning, this will give you a (crossterm) style
- pub fn as_style(&self, meaning: Meaning) -> ContentStyle {
+ pub(crate) fn as_style(&self, meaning: Meaning) -> ContentStyle {
self.styles[self.closest_meaning(&meaning)]
}
@@ -120,7 +120,7 @@ impl Theme {
// but we do not have this on in general, as it could print unfiltered text to the terminal
// from a theme TOML file. However, it will always return a theme, falling back to
// defaults on error, so that a TOML file does not break loading
- pub fn from_foreground_colors(
+ pub(crate) fn from_foreground_colors(
name: String,
parent: Option<&Theme>,
foreground_colors: HashMap<Meaning, String>,
@@ -206,7 +206,7 @@ fn from_string(name: &str) -> Result<Color, String> {
}
}
-pub struct StyleFactory {}
+pub(crate) struct StyleFactory {}
impl StyleFactory {
fn from_fg_string(name: &str) -> Result<ContentStyle, String> {
@@ -360,7 +360,7 @@ static BUILTIN_THEMES: LazyLock<HashMap<&'static str, Theme>> = LazyLock::new(||
});
// To avoid themes being repeatedly loaded, we store them in a theme manager
-pub struct ThemeManager {
+pub(crate) struct ThemeManager {
loaded_themes: HashMap<String, Theme>,
debug: bool,
override_theme_dir: Option<String>,
@@ -368,7 +368,7 @@ pub struct ThemeManager {
// Theme-loading logic
impl ThemeManager {
- pub fn new(debug: Option<bool>, theme_dir: Option<String>) -> Self {
+ pub(crate) fn new(debug: Option<bool>, theme_dir: Option<String>) -> Self {
Self {
loaded_themes: HashMap::new(),
debug: debug.unwrap_or(false),
@@ -381,7 +381,7 @@ impl ThemeManager {
// Try to load a theme from a `{name}.toml` file in the theme directory. If an override is set
// for the theme dir (via ATUIN_THEME_DIR env) we should load the theme from there
- pub fn load_theme_from_file(
+ pub(crate) fn load_theme_from_file(
&mut self,
name: &str,
max_depth: u8,
@@ -421,7 +421,7 @@ impl ThemeManager {
self.load_theme_from_config(name, config, max_depth)
}
- pub fn load_theme_from_config(
+ pub(crate) fn load_theme_from_config(
&mut self,
name: &str,
config: Config,
@@ -475,7 +475,7 @@ impl ThemeManager {
// Check if the requested theme is loaded and, if not, then attempt to get it
// from the builtins or, if not there, from file
- pub fn load_theme(&mut self, name: &str, max_depth: Option<u8>) -> &Theme {
+ pub(crate) fn load_theme(&mut self, name: &str, max_depth: Option<u8>) -> &Theme {
if self.loaded_themes.contains_key(name) {
return self.loaded_themes.get(name).unwrap();
}