From f3bddc5af479f14810c0ee709f180e55fbd3912a Mon Sep 17 00:00:00 2001 From: NBonaparte Date: Wed, 6 Sep 2017 19:30:30 -0700 Subject: [PATCH 1/4] fix(modules): Separate prefix and suffix from output --- src/modules/meta/base.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/meta/base.cpp b/src/modules/meta/base.cpp index 62a6a82e..615ebd77 100644 --- a/src/modules/meta/base.cpp +++ b/src/modules/meta/base.cpp @@ -14,6 +14,7 @@ namespace modules { builder->flush(); return ""; } + builder->node(prefix); if (offset != 0) { builder->offset(offset); @@ -38,9 +39,7 @@ namespace modules { } if (!output.empty()) { - builder->node(prefix); builder->append(move(output)); - builder->node(suffix); } if (padding > 0) { @@ -61,6 +60,7 @@ namespace modules { if (margin > 0) { builder->space(margin); } + builder->node(suffix); return builder->flush(); } From 3ce06585ab5d606c0c03d37ab7f8be3145fd98e6 Mon Sep 17 00:00:00 2001 From: NBonaparte Date: Wed, 6 Sep 2017 20:06:13 -0700 Subject: [PATCH 2/4] fix(parser): Revert tag stacks --- include/components/parser.hpp | 13 ++----- src/components/parser.cpp | 65 +++++++++-------------------------- 2 files changed, 18 insertions(+), 60 deletions(-) diff --git a/include/components/parser.hpp b/include/components/parser.hpp index 5f113a69..8aeba5c0 100644 --- a/include/components/parser.hpp +++ b/include/components/parser.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include "common.hpp" #include "errors.hpp" @@ -30,9 +28,8 @@ class parser { void codeblock(string&& data, const bar_settings& bar); size_t text(string&& data); - unsigned int parse_color(std::stack& color_stack, string& value, unsigned int fallback); - unsigned int parse_color_string(const string& s, unsigned int fallback = 0); - int parse_fontindex(const string& value); + unsigned int parse_color(const string& s, unsigned int fallback = 0); + int parse_fontindex(const string& s); attribute parse_attr(const char attr); mousebtn parse_action_btn(const string& data); string parse_action_cmd(string&& data); @@ -41,12 +38,6 @@ class parser { signal_emitter& m_sig; vector m_actions; unique_ptr m_parser; - - std::stack m_fg; - std::stack m_bg; - std::stack m_ul; - std::stack m_ol; - std::stack m_fonts; }; POLYBAR_NS_END diff --git a/src/components/parser.cpp b/src/components/parser.cpp index 423127d4..a7e3cbf3 100644 --- a/src/components/parser.cpp +++ b/src/components/parser.cpp @@ -45,12 +45,6 @@ void parser::parse(const bar_settings& bar, string data) { } } - m_fg = std::stack(); - m_bg = std::stack(); - m_ul = std::stack(); - m_ol = std::stack(); - m_fonts = std::stack(); - if (!m_actions.empty()) { throw unclosed_actionblocks(to_string(m_actions.size()) + " unclosed action block(s)"); } @@ -82,31 +76,29 @@ void parser::codeblock(string&& data, const bar_settings& bar) { } switch (tag) { - case 'B': { - m_sig.emit(change_background{parse_color(m_bg, value, bar.background)}); + case 'B': + m_sig.emit(change_background{parse_color(value, bar.background)}); break; - } - case 'F': { - m_sig.emit(change_foreground{parse_color(m_fg, value, bar.foreground)}); + case 'F': + m_sig.emit(change_foreground{parse_color(value, bar.foreground)}); break; - } case 'T': m_sig.emit(change_font{parse_fontindex(value)}); break; case 'U': - m_sig.emit(change_underline{parse_color(m_ul, value, bar.underline.color)}); - m_sig.emit(change_overline{parse_color(m_ol, value, bar.overline.color)}); + m_sig.emit(change_underline{parse_color(value, bar.underline.color)}); + m_sig.emit(change_overline{parse_color(value, bar.overline.color)}); break; case 'u': - m_sig.emit(change_underline{parse_color(m_ul, value, bar.underline.color)}); + m_sig.emit(change_underline{parse_color(value, bar.underline.color)}); break; case 'o': - m_sig.emit(change_overline{parse_color(m_ol, value, bar.overline.color)}); + m_sig.emit(change_overline{parse_color(value, bar.overline.color)}); break; case 'R': @@ -184,24 +176,10 @@ size_t parser::text(string&& data) { return data.size(); } -/** - * Determine color using passed stack and input value - */ -unsigned int parser::parse_color(std::stack& color_stack, string& value, unsigned int fallback) { - if (!color_stack.empty() && !value.empty() && value[0] == '-') { - color_stack.pop(); - } - auto parsed_value = parse_color_string(value, !color_stack.empty() ? color_stack.top() : fallback); - if (!value.empty() && value[0] != '-' && (color_stack.empty() || (parsed_value != color_stack.top()))) { - color_stack.push(parsed_value); - } - return parsed_value; -} - /** * Process color hex string and convert it to the correct value */ -unsigned int parser::parse_color_string(const string& s, unsigned int fallback) { +unsigned int parser::parse_color(const string& s, unsigned int fallback) { if (!s.empty() && s[0] != '-') { return color_util::parse(s, fallback); } @@ -211,26 +189,15 @@ unsigned int parser::parse_color_string(const string& s, unsigned int fallback) /** * Process font index and convert it to the correct value */ -int parser::parse_fontindex(const string& value) { - auto font_index = 0; - auto reset = value.empty() || value[0] == '-'; - - if (reset && !m_fonts.empty()) { - m_fonts.pop(); - } else if (!reset) { - try { - font_index = std::stoul(value, nullptr, 10); - m_fonts.push(font_index); - return font_index; - } catch (const std::invalid_argument& err) { - return font_index; - } +int parser::parse_fontindex(const string& s) { + if (s.empty() || s[0] == '-') { + return 0; } - if (!m_fonts.empty()) { - return m_fonts.top(); - } else { - return font_index; + try { + return std::stoul(s, nullptr, 10); + } catch (const std::invalid_argument& err) { + return 0; } } From 9da06c0ec2ee75db1e775ed004e84a804fb7217e Mon Sep 17 00:00:00 2001 From: NBonaparte Date: Wed, 6 Sep 2017 20:14:11 -0700 Subject: [PATCH 3/4] fix(modules): Remove redundant if statement --- src/modules/meta/base.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/modules/meta/base.cpp b/src/modules/meta/base.cpp index 615ebd77..c5db650c 100644 --- a/src/modules/meta/base.cpp +++ b/src/modules/meta/base.cpp @@ -38,9 +38,7 @@ namespace modules { builder->space(padding); } - if (!output.empty()) { - builder->append(move(output)); - } + builder->append(move(output)); if (padding > 0) { builder->space(padding); From 89fccde76596838c503ba5612055004ab05660fd Mon Sep 17 00:00:00 2001 From: NBonaparte Date: Fri, 22 Sep 2017 23:40:31 -0700 Subject: [PATCH 4/4] fix(modules): Apply format settings to pre/suffix --- src/modules/meta/base.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/modules/meta/base.cpp b/src/modules/meta/base.cpp index c5db650c..b8d5d9fe 100644 --- a/src/modules/meta/base.cpp +++ b/src/modules/meta/base.cpp @@ -14,8 +14,6 @@ namespace modules { builder->flush(); return ""; } - builder->node(prefix); - if (offset != 0) { builder->offset(offset); } @@ -38,7 +36,23 @@ namespace modules { builder->space(padding); } + builder->node(prefix); + + if (!bg.empty()) { + builder->background(bg); + } + if (!fg.empty()) { + builder->color(fg); + } + if (!ul.empty()) { + builder->underline(ul); + } + if (!ol.empty()) { + builder->overline(ol); + } + builder->append(move(output)); + builder->node(suffix); if (padding > 0) { builder->space(padding); @@ -58,7 +72,6 @@ namespace modules { if (margin > 0) { builder->space(margin); } - builder->node(suffix); return builder->flush(); }