refactor: Implement Default for SegmentConfig (#495)
Implements the Default trait for SegmentConfig to clean up construction of empty segments. Also adds a segment::new() function to ease construction of simple segments.
This commit is contained in:
parent
044e10de1b
commit
06ba22eb5c
|
@ -219,6 +219,10 @@ impl<'a> ModuleConfig<'a> for SegmentConfig<'a> {
|
|||
}
|
||||
|
||||
impl<'a> SegmentConfig<'a> {
|
||||
pub fn new(value: &'static str) -> Self {
|
||||
Self { value, style: None }
|
||||
}
|
||||
|
||||
/// Mutably set value
|
||||
pub fn set_value(&mut self, value: &'a str) {
|
||||
self.value = value;
|
||||
|
@ -246,6 +250,12 @@ impl<'a> SegmentConfig<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for SegmentConfig<'static> {
|
||||
fn default() -> Self {
|
||||
Self::new("")
|
||||
}
|
||||
}
|
||||
|
||||
/** Parse a style string which represents an ansi style. Valid tokens in the style
|
||||
string include the following:
|
||||
- 'fg:<color>' (specifies that the color read should be a foreground color)
|
||||
|
|
|
@ -14,14 +14,8 @@ pub struct AwsConfig<'a> {
|
|||
impl<'a> RootModuleConfig<'a> for AwsConfig<'a> {
|
||||
fn new() -> Self {
|
||||
AwsConfig {
|
||||
symbol: SegmentConfig {
|
||||
value: "☁️ ",
|
||||
style: None,
|
||||
},
|
||||
profile: SegmentConfig {
|
||||
value: "",
|
||||
style: None,
|
||||
},
|
||||
symbol: SegmentConfig::new("☁️ "),
|
||||
profile: SegmentConfig::default(),
|
||||
style: Color::Yellow.bold(),
|
||||
disabled: false,
|
||||
}
|
||||
|
|
|
@ -18,18 +18,9 @@ pub struct BatteryConfig<'a> {
|
|||
impl<'a> RootModuleConfig<'a> for BatteryConfig<'a> {
|
||||
fn new() -> Self {
|
||||
BatteryConfig {
|
||||
full_symbol: SegmentConfig {
|
||||
value: "•",
|
||||
style: None,
|
||||
},
|
||||
charging_symbol: SegmentConfig {
|
||||
value: "↑",
|
||||
style: None,
|
||||
},
|
||||
discharging_symbol: SegmentConfig {
|
||||
value: "↓",
|
||||
style: None,
|
||||
},
|
||||
full_symbol: SegmentConfig::new("•"),
|
||||
charging_symbol: SegmentConfig::new("↑"),
|
||||
discharging_symbol: SegmentConfig::new("↓"),
|
||||
unknown_symbol: None,
|
||||
empty_symbol: None,
|
||||
display: vec![BatteryDisplayConfig {
|
||||
|
@ -37,10 +28,7 @@ impl<'a> RootModuleConfig<'a> for BatteryConfig<'a> {
|
|||
style: Color::Red.bold(),
|
||||
}],
|
||||
disabled: false,
|
||||
percentage: SegmentConfig {
|
||||
value: "",
|
||||
style: None,
|
||||
},
|
||||
percentage: SegmentConfig::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,18 +17,9 @@ pub struct CharacterConfig<'a> {
|
|||
impl<'a> RootModuleConfig<'a> for CharacterConfig<'a> {
|
||||
fn new() -> Self {
|
||||
CharacterConfig {
|
||||
symbol: SegmentConfig {
|
||||
value: "❯",
|
||||
style: None,
|
||||
},
|
||||
error_symbol: SegmentConfig {
|
||||
value: "✖",
|
||||
style: None,
|
||||
},
|
||||
vicmd_symbol: SegmentConfig {
|
||||
value: "❮",
|
||||
style: None,
|
||||
},
|
||||
symbol: SegmentConfig::new("❯"),
|
||||
error_symbol: SegmentConfig::new("✖"),
|
||||
vicmd_symbol: SegmentConfig::new("❮"),
|
||||
use_symbol_for_status: false,
|
||||
style_success: Color::Green.bold(),
|
||||
style_failure: Color::Red.bold(),
|
||||
|
|
|
@ -15,14 +15,8 @@ pub struct DotnetConfig<'a> {
|
|||
impl<'a> RootModuleConfig<'a> for DotnetConfig<'a> {
|
||||
fn new() -> Self {
|
||||
DotnetConfig {
|
||||
symbol: SegmentConfig {
|
||||
value: "•NET ",
|
||||
style: None,
|
||||
},
|
||||
version: SegmentConfig {
|
||||
value: "",
|
||||
style: None,
|
||||
},
|
||||
symbol: SegmentConfig::new("•NET "),
|
||||
version: SegmentConfig::default(),
|
||||
style: Color::Blue.bold(),
|
||||
heuristic: true,
|
||||
disabled: false,
|
||||
|
|
|
@ -15,18 +15,9 @@ pub struct KubernetesConfig<'a> {
|
|||
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,
|
||||
},
|
||||
symbol: SegmentConfig::new("☸ "),
|
||||
context: SegmentConfig::default(),
|
||||
namespace: SegmentConfig::default(),
|
||||
style: Color::Cyan.bold(),
|
||||
disabled: true,
|
||||
}
|
||||
|
|
|
@ -14,14 +14,8 @@ pub struct RustConfig<'a> {
|
|||
impl<'a> RootModuleConfig<'a> for RustConfig<'a> {
|
||||
fn new() -> Self {
|
||||
RustConfig {
|
||||
symbol: SegmentConfig {
|
||||
value: "🦀 ",
|
||||
style: None,
|
||||
},
|
||||
version: SegmentConfig {
|
||||
value: "",
|
||||
style: None,
|
||||
},
|
||||
symbol: SegmentConfig::new("🦀 "),
|
||||
version: SegmentConfig::default(),
|
||||
style: Color::Red.bold(),
|
||||
disabled: false,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue