diff --git a/docs/config/README.md b/docs/config/README.md index 2e087ac6..318d75e7 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -574,13 +574,20 @@ can be done via `kubectl config set-context starship-cluster --namespace astronaut`. If the `$KUBECONFIG` env var is set the module will use that if not it will use the `~/.kube/config`. +::: tip + +This module is disabled by default. +To enable it, set `disabled` to `false` in your configuration file. + +::: + ### Options | Variable | Default | Description | | ---------- | ------------- | --------------------------------------------------- | | `symbol` | `"☸ "` | The symbol used before displaying the Cluster info. | | `style` | `"bold blue"` | The style for the module. | -| `disabled` | `false` | Disables the `kubernetes` module | +| `disabled` | `true` | Disables the `kubernetes` module | ### Example @@ -590,7 +597,7 @@ not it will use the `~/.kube/config`. [kubernetes] symbol = "⛵ " style = "dim green" -disabled = true +disabled = false ``` diff --git a/src/configs/kubernetes.rs b/src/configs/kubernetes.rs new file mode 100644 index 00000000..733919cd --- /dev/null +++ b/src/configs/kubernetes.rs @@ -0,0 +1,34 @@ +use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; + +use ansi_term::{Color, Style}; +use starship_module_config_derive::ModuleConfig; + +#[derive(Clone, ModuleConfig)] +pub struct KubernetesConfig<'a> { + pub symbol: SegmentConfig<'a>, + pub context: SegmentConfig<'a>, + pub namespace: SegmentConfig<'a>, + pub style: Style, + pub disabled: bool, +} + +impl<'a> RootModuleConfig<'a> for KubernetesConfig<'a> { + fn new() -> Self { + KubernetesConfig { + symbol: SegmentConfig { + value: "☸ ", + style: None, + }, + context: SegmentConfig { + value: "", + style: None, + }, + namespace: SegmentConfig { + value: "", + style: None, + }, + style: Color::Cyan.bold(), + disabled: true, + } + } +} diff --git a/src/configs/mod.rs b/src/configs/mod.rs index f557345e..213ec36a 100644 --- a/src/configs/mod.rs +++ b/src/configs/mod.rs @@ -2,6 +2,7 @@ pub mod aws; pub mod battery; pub mod character; pub mod dotnet; +pub mod kubernetes; pub mod rust; use crate::config::{ModuleConfig, RootModuleConfig}; diff --git a/src/modules/kubernetes.rs b/src/modules/kubernetes.rs index 5142c7dd..40de44a9 100644 --- a/src/modules/kubernetes.rs +++ b/src/modules/kubernetes.rs @@ -1,4 +1,3 @@ -use ansi_term::Color; use dirs; use yaml_rust::YamlLoader; @@ -6,9 +5,12 @@ use std::env; use std::path; use super::{Context, Module}; + +use crate::config::RootModuleConfig; +use crate::configs::kubernetes::KubernetesConfig; use crate::utils; -const KUBE_CHAR: &str = "☸ "; +const KUBERNETES_PREFIX: &str = "on "; fn get_kube_context(contents: &str) -> Option<(String, String)> { let yaml_docs = YamlLoader::load_from_str(&contents).ok()?; @@ -50,17 +52,18 @@ pub fn module<'a>(context: &'a Context) -> Option> { let (kube_ctx, kube_ns) = kube_cfg; let mut module = context.new_module("kubernetes"); + let config: KubernetesConfig = KubernetesConfig::try_load(module.config); - let module_style = module - .config_value_style("style") - .unwrap_or_else(|| Color::Cyan.bold()); - module.set_style(module_style); - module.get_prefix().set_value("on "); + module.set_style(config.style); + module.get_prefix().set_value(KUBERNETES_PREFIX); - module.new_segment("symbol", KUBE_CHAR); - module.new_segment("context", &kube_ctx); + module.create_segment("symbol", &config.symbol); + module.create_segment("context", &config.context.with_value(&kube_ctx)); if kube_ns != "" { - module.new_segment("namespace", &format!(" ({})", kube_ns)); + module.create_segment( + "namespace", + &config.namespace.with_value(&format!(" ({})", kube_ns)), + ); } Some(module) }