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.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> { 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> { 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> { 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) }