mirror of
https://github.com/Llewellynvdm/starship.git
synced 2025-01-16 03:32:25 +00:00
d93074d056
* docs(config): add color palette to docs * feat: add user-defined color palette * fix: update config schema * refactor: apply suggestions from code review Co-authored-by: David Knaack <davidkna@users.noreply.github.com> * fix: update new test * feat: add support for multiple palettes * docs(config): update docs for multiple color palettes * docs(config): fix formatting * test: test overriding a predefined color with itself * docs: mention palettes cannot reference themselves * refactor: warn when using a nonexistent palette * test: test retrieving a nonexistent color palette * fix: fix issues with palette log messages * fix: update config schema * fix: skip serializing palette if none * refactor: change nonexistent palette message to warning * fix: update config schema Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
69 lines
1.7 KiB
Rust
69 lines
1.7 KiB
Rust
use super::{Context, Module};
|
|
|
|
use crate::config::{parse_style_string, ModuleConfig};
|
|
use crate::configs::fill::FillConfig;
|
|
use crate::segment::Segment;
|
|
|
|
/// Creates a module that fills the any extra space on the line.
|
|
///
|
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|
let mut module = context.new_module("fill");
|
|
let config: FillConfig = FillConfig::try_load(module.config);
|
|
|
|
if config.disabled {
|
|
return None;
|
|
}
|
|
|
|
let style = parse_style_string(config.style, Some(context));
|
|
|
|
module.set_segments(vec![Segment::fill(style, config.symbol)]);
|
|
|
|
Some(module)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use crate::test::ModuleRenderer;
|
|
use nu_ansi_term::Color;
|
|
|
|
#[test]
|
|
fn basic() {
|
|
let actual = ModuleRenderer::new("fill")
|
|
.config(toml::toml! {
|
|
[fill]
|
|
style = "bold green"
|
|
symbol = "*-"
|
|
})
|
|
.collect();
|
|
let expected = Some(format!("{}", Color::Green.bold().paint("*-")));
|
|
|
|
assert_eq!(expected, actual);
|
|
}
|
|
|
|
#[test]
|
|
fn module_disabled() {
|
|
let actual = ModuleRenderer::new("fill")
|
|
.config(toml::toml! {
|
|
[fill]
|
|
disabled = true
|
|
})
|
|
.collect();
|
|
let expected = Option::<String>::None;
|
|
|
|
assert_eq!(expected, actual);
|
|
}
|
|
|
|
#[test]
|
|
fn module_enabled() {
|
|
let actual = ModuleRenderer::new("fill")
|
|
.config(toml::toml! {
|
|
[fill]
|
|
disabled = false
|
|
})
|
|
.collect();
|
|
let expected = Some(format!("{}", Color::Black.bold().paint(".")));
|
|
|
|
assert_eq!(expected, actual);
|
|
}
|
|
}
|