blob: bf9558efcce20a5ed92e6c3c03864ce6d9ef70af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
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);
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);
}
}
|