mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-05-31 07:30:52 +00:00
6b444e05c6
* feat(kubernetes): Add styling based on current context Add an ability to customize the configuration of the kubernetes module style, based on the current context. A new variable is added to the config section, called environments, which is a list of possible customizations. Each such customization is an object with a context_pattern regex, which matches context name, and an optional style and icon that will override the global configuration, if the currently used context matched the context_pattern. Based on multiple attempts to add per-context styling and symbols to the kubernetes module. - https://github.com/starship/starship/pull/1568 by @lht https://github.com/lht -> base - https://github.com/starship/starship/pull/614 by @nomaed https://github.com/nomaed -> naming, symbol, some tests Rebased and combined by @jankatins Contains the following squasched commits - Rename to contexts and move aliases into contexts - Move deprecated functions to a submodule - Cleanup: ignore None-valued KubeCtxComponents - Add regex func + clean up matching-context search - Placate paper clip Closes: https://github.com/starship/starship/issues/570 Co-authored-by: =?UTF-8?q?Boris=20Aranovic=CC=8C?= <nomaed@gmail.com> Co-authored-by: Jan Katins <jasc@gmx.net> Co-authored-by: Kevin Song <chips@ksong.dev> * refactor(kubernetes): Remove options and use clearer names * test(kubernetes): Handle duplicated contexts right * refactor(kubernetes): Cleaner user matching * fix(kubernetes): Only show warning in case of problems * feat(kubernetes): Add back alias replacements * refactor(kubernetes): Cleanup rust usage --------- Co-authored-by: Haitao Li <lihaitao@gmail.com> Co-authored-by: =?UTF-8?q?Boris=20Aranovic=CC=8C?= <nomaed@gmail.com> Co-authored-by: Kevin Song <chips@ksong.dev> Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
56 lines
1.5 KiB
Rust
56 lines
1.5 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Clone, Deserialize, Serialize)]
|
|
#[cfg_attr(
|
|
feature = "config-schema",
|
|
derive(schemars::JsonSchema),
|
|
schemars(deny_unknown_fields)
|
|
)]
|
|
#[serde(default)]
|
|
pub struct KubernetesConfig<'a> {
|
|
pub symbol: &'a str,
|
|
pub format: &'a str,
|
|
pub style: &'a str,
|
|
pub disabled: bool,
|
|
pub context_aliases: HashMap<String, &'a str>,
|
|
pub user_aliases: HashMap<String, &'a str>,
|
|
pub detect_extensions: Vec<&'a str>,
|
|
pub detect_files: Vec<&'a str>,
|
|
pub detect_folders: Vec<&'a str>,
|
|
pub contexts: Vec<KubernetesContextConfig<'a>>,
|
|
}
|
|
|
|
impl<'a> Default for KubernetesConfig<'a> {
|
|
fn default() -> Self {
|
|
KubernetesConfig {
|
|
symbol: "☸ ",
|
|
format: "[$symbol$context( \\($namespace\\))]($style) in ",
|
|
style: "cyan bold",
|
|
disabled: true,
|
|
context_aliases: HashMap::new(),
|
|
user_aliases: HashMap::new(),
|
|
detect_extensions: vec![],
|
|
detect_files: vec![],
|
|
detect_folders: vec![],
|
|
contexts: vec![],
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Deserialize, Serialize, Default)]
|
|
#[cfg_attr(
|
|
feature = "config-schema",
|
|
derive(schemars::JsonSchema),
|
|
schemars(deny_unknown_fields)
|
|
)]
|
|
#[serde(default)]
|
|
pub struct KubernetesContextConfig<'a> {
|
|
pub context_pattern: &'a str,
|
|
pub user_pattern: Option<&'a str>,
|
|
pub symbol: Option<&'a str>,
|
|
pub style: Option<&'a str>,
|
|
pub context_alias: Option<&'a str>,
|
|
pub user_alias: Option<&'a str>,
|
|
}
|