summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatias Kotlik <mdkotlik@gmail.com>2019-11-12 19:57:46 -0600
committerMatan Kushner <hello@matchai.me>2019-11-13 10:57:46 +0900
commit135dddbb4fa2ded2d0d5fa75225b03048b5db99c (patch)
tree7962fff631bba6e1051145e1804e0c448c6ea12c
parent512ed75ef2a13f51d8f6c576e2dfb70e3812d2a9 (diff)
feat: Add separator config to the memory module (#603)
-rw-r--r--docs/config/README.md2
-rw-r--r--src/configs/memory_usage.rs8
-rw-r--r--src/modules/memory_usage.rs34
3 files changed, 23 insertions, 21 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index 6a73d5b57..1df820677 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -713,6 +713,7 @@ To enable it, set `disabled` to `false` in your configuration file.
| `show_swap` | `true` | Display swap usage if total swap is non-zero. |
| `threshold` | `75` | Hide the memory usage unless it exceeds this percentage. |
| `symbol` | `"🐏 "` | The symbol used before displaying the memory usage. |
+| `separator` | `" | "` | The symbol or text that will seperate the ram and swap usage. |
| `style` | `"bold dimmed white"` | The style for the module. |
| `disabled` | `true` | Disables the `memory_usage` module. |
@@ -726,6 +727,7 @@ show_percentage = true
show_swap = true
threshold = -1
symbol = " "
+separator = "/"
style = "bold dimmed green"
```
diff --git a/src/configs/memory_usage.rs b/src/configs/memory_usage.rs
index 8b2b87982..bd4ec03c3 100644
--- a/src/configs/memory_usage.rs
+++ b/src/configs/memory_usage.rs
@@ -9,7 +9,9 @@ pub struct MemoryConfig<'a> {
pub show_swap: bool,
pub threshold: i64,
pub symbol: SegmentConfig<'a>,
- pub display: SegmentConfig<'a>,
+ pub separator: SegmentConfig<'a>,
+ pub ram: SegmentConfig<'a>,
+ pub swap: SegmentConfig<'a>,
pub style: Style,
pub disabled: bool,
}
@@ -20,8 +22,10 @@ impl<'a> RootModuleConfig<'a> for MemoryConfig<'a> {
show_percentage: false,
show_swap: true,
threshold: 75,
- display: SegmentConfig::default(),
symbol: SegmentConfig::new("🐏 "),
+ separator: SegmentConfig::new(" | "),
+ ram: SegmentConfig::default(),
+ swap: SegmentConfig::default(),
style: Color::White.bold().dimmed(),
disabled: true,
}
diff --git a/src/modules/memory_usage.rs b/src/modules/memory_usage.rs
index 73324d83f..5331a5140 100644
--- a/src/modules/memory_usage.rs
+++ b/src/modules/memory_usage.rs
@@ -31,6 +31,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}
module.set_style(config.style);
+ module.create_segment("symbol", &config.symbol);
let system = sysinfo::System::new_with_specifics(RefreshKind::new().with_system());
@@ -47,7 +48,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let show_percentage = config.show_percentage;
- let mut display = if show_percentage {
+ let ram = if show_percentage {
format!("{:.0}{}", percent_mem_used, percent_sign)
} else {
format!(
@@ -56,6 +57,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
format_kib(total_memory_kib)
)
};
+ module.create_segment("ram", &config.ram.with_value(&ram));
// swap only shown if enabled and there is swap on the system
let total_swap_kib = system.get_total_swap();
@@ -63,25 +65,19 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let used_swap_kib = system.get_used_swap();
let percent_swap_used = (used_swap_kib as f64 / total_swap_kib as f64) * 100.;
- display = format!(
- "{} | {}",
- display,
- if show_percentage {
- format!("{:.0}{}", percent_swap_used, percent_sign)
- } else {
- format!(
- "{}/{}",
- format_kib(used_swap_kib),
- format_kib(total_swap_kib)
- )
- }
- );
+ let swap = if show_percentage {
+ format!("{:.0}{}", percent_swap_used, percent_sign)
+ } else {
+ format!(
+ "{}/{}",
+ format_kib(used_swap_kib),
+ format_kib(total_swap_kib)
+ )
+ };
+
+ module.create_segment("separator", &config.separator);
+ module.create_segment("swap", &config.swap.with_value(&swap));
}
- module.create_segment("symbol", &config.symbol);
- module.create_segment("memory_usage", &config.display.with_value(&display));
-
- module.get_prefix().set_value("");
-
Some(module)
}