From 2f62a6fbadd72d78b68db1cd1209f7feb4d43858 Mon Sep 17 00:00:00 2001 From: patrick96 <p.ziegler96@gmail.com> Date: Mon, 19 Feb 2018 18:04:55 +0100 Subject: [PATCH] feat(memory): Add memory used/free ramp Closes #1037 --- include/modules/memory.hpp | 4 ++++ src/modules/memory.cpp | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index f4c46547..449cabd6 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -19,12 +19,16 @@ namespace modules { static constexpr const char* TAG_LABEL{"<label>"}; static constexpr const char* TAG_BAR_USED{"<bar-used>"}; static constexpr const char* TAG_BAR_FREE{"<bar-free>"}; + static constexpr const char* TAG_RAMP_USED{"<ramp-used>"}; + static constexpr const char* TAG_RAMP_FREE{"<ramp-free>"}; label_t m_label; progressbar_t m_bar_memused; progressbar_t m_bar_memfree; int m_perc_memused{0}; int m_perc_memfree{0}; + ramp_t m_ramp_memused; + ramp_t m_ramp_memfree; }; } diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index 915585ed..3da3ea2e 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -4,6 +4,7 @@ #include "drawtypes/label.hpp" #include "drawtypes/progressbar.hpp" +#include "drawtypes/ramp.hpp" #include "modules/memory.hpp" #include "utils/math.hpp" @@ -17,7 +18,7 @@ namespace modules { memory_module::memory_module(const bar_settings& bar, string name_) : timer_module<memory_module>(bar, move(name_)) { m_interval = m_conf.get<decltype(m_interval)>(name(), "interval", 1s); - m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_USED, TAG_BAR_FREE}); + m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_USED, TAG_BAR_FREE, TAG_RAMP_USED, TAG_RAMP_FREE}); if (m_formatter->has(TAG_BAR_USED)) { m_bar_memused = load_progressbar(m_bar, m_conf, name(), TAG_BAR_USED); @@ -25,6 +26,12 @@ namespace modules { if (m_formatter->has(TAG_BAR_FREE)) { m_bar_memfree = load_progressbar(m_bar, m_conf, name(), TAG_BAR_FREE); } + if(m_formatter->has(TAG_RAMP_USED)) { + m_ramp_memused = load_ramp(m_conf, name(), TAG_RAMP_USED); + } + if(m_formatter->has(TAG_RAMP_FREE)) { + m_ramp_memfree = load_ramp(m_conf, name(), TAG_RAMP_FREE); + } if (m_formatter->has(TAG_LABEL)) { m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%percentage_used%%"); } @@ -91,6 +98,10 @@ namespace modules { builder->node(m_bar_memfree->output(m_perc_memfree)); } else if (tag == TAG_LABEL) { builder->node(m_label); + } else if (tag == TAG_RAMP_FREE) { + builder->node(m_ramp_memfree->get_by_percentage(m_perc_memfree)); + } else if (tag == TAG_RAMP_USED) { + builder->node(m_ramp_memused->get_by_percentage(m_perc_memused)); } else { return false; }