summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikodem Rabuliński <nikodemrabulinski@gmail.com>2019-10-06 03:46:14 +0200
committerKevin Song <chipbuster@users.noreply.github.com>2019-10-05 20:46:14 -0500
commit06ba22eb5c12c8cc0892261899ed140bbb51c99a (patch)
tree3137f7ccf6f74dc8a3b404d18f6ef7a2aa56d058
parent044e10de1b1b1821a8108574491f22b8daf48233 (diff)
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.
-rw-r--r--src/config.rs10
-rw-r--r--src/configs/aws.rs10
-rw-r--r--src/configs/battery.rs20
-rw-r--r--src/configs/character.rs15
-rw-r--r--src/configs/dotnet.rs10
-rw-r--r--src/configs/kubernetes.rs15
-rw-r--r--src/configs/rust.rs10
7 files changed, 26 insertions, 64 deletions
diff --git a/src/config.rs b/src/config.rs
index 6f5025179..dafbe1beb 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -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)
diff --git a/src/configs/aws.rs b/src/configs/aws.rs
index 96ed3cb5b..f362d0878 100644
--- a/src/configs/aws.rs
+++ b/src/configs/aws.rs
@@ -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,
}
diff --git a/src/configs/battery.rs b/src/configs/battery.rs
index e60b95e2f..d86227d79 100644
--- a/src/configs/battery.rs
+++ b/src/configs/battery.rs
@@ -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(),
}
}
}
diff --git a/src/configs/character.rs b/src/configs/character.rs
index 77a509cff..92f977ebb 100644
--- a/src/configs/character.rs
+++ b/src/configs/character.rs
@@ -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(),
diff --git a/src/configs/dotnet.rs b/src/configs/dotnet.rs
index 084798c6d..f6bb59e40 100644
--- a/src/configs/dotnet.rs
+++ b/src/configs/dotnet.rs
@@ -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,
diff --git a/src/configs/kubernetes.rs b/src/configs/kubernetes.rs
index 733919cd1..2d8e681be 100644
--- a/src/configs/kubernetes.rs
+++ b/src/configs/kubernetes.rs
@@ -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,
}
diff --git a/src/configs/rust.rs b/src/configs/rust.rs
index 2bd257588..911524ab5 100644
--- a/src/configs/rust.rs
+++ b/src/configs/rust.rs
@@ -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,
}