Merge pull request #729 from NBonaparte/fix-prefix-suffix
fix(modules): Separate prefix/suffix tags, revert tag stack
This commit is contained in:
commit
5b7d7b8232
3 changed files with 34 additions and 65 deletions
|
@ -1,7 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stack>
|
|
||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "errors.hpp"
|
#include "errors.hpp"
|
||||||
|
|
||||||
|
@ -30,9 +28,8 @@ class parser {
|
||||||
void codeblock(string&& data, const bar_settings& bar);
|
void codeblock(string&& data, const bar_settings& bar);
|
||||||
size_t text(string&& data);
|
size_t text(string&& data);
|
||||||
|
|
||||||
unsigned int parse_color(std::stack<unsigned int>& color_stack, string& value, unsigned int fallback);
|
unsigned int parse_color(const string& s, unsigned int fallback = 0);
|
||||||
unsigned int parse_color_string(const string& s, unsigned int fallback = 0);
|
int parse_fontindex(const string& s);
|
||||||
int parse_fontindex(const string& value);
|
|
||||||
attribute parse_attr(const char attr);
|
attribute parse_attr(const char attr);
|
||||||
mousebtn parse_action_btn(const string& data);
|
mousebtn parse_action_btn(const string& data);
|
||||||
string parse_action_cmd(string&& data);
|
string parse_action_cmd(string&& data);
|
||||||
|
@ -41,12 +38,6 @@ class parser {
|
||||||
signal_emitter& m_sig;
|
signal_emitter& m_sig;
|
||||||
vector<int> m_actions;
|
vector<int> m_actions;
|
||||||
unique_ptr<parser> m_parser;
|
unique_ptr<parser> m_parser;
|
||||||
|
|
||||||
std::stack<unsigned int> m_fg;
|
|
||||||
std::stack<unsigned int> m_bg;
|
|
||||||
std::stack<unsigned int> m_ul;
|
|
||||||
std::stack<unsigned int> m_ol;
|
|
||||||
std::stack<int> m_fonts;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
|
|
@ -45,12 +45,6 @@ void parser::parse(const bar_settings& bar, string data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_fg = std::stack<unsigned int>();
|
|
||||||
m_bg = std::stack<unsigned int>();
|
|
||||||
m_ul = std::stack<unsigned int>();
|
|
||||||
m_ol = std::stack<unsigned int>();
|
|
||||||
m_fonts = std::stack<int>();
|
|
||||||
|
|
||||||
if (!m_actions.empty()) {
|
if (!m_actions.empty()) {
|
||||||
throw unclosed_actionblocks(to_string(m_actions.size()) + " unclosed action block(s)");
|
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) {
|
switch (tag) {
|
||||||
case 'B': {
|
case 'B':
|
||||||
m_sig.emit(change_background{parse_color(m_bg, value, bar.background)});
|
m_sig.emit(change_background{parse_color(value, bar.background)});
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case 'F': {
|
case 'F':
|
||||||
m_sig.emit(change_foreground{parse_color(m_fg, value, bar.foreground)});
|
m_sig.emit(change_foreground{parse_color(value, bar.foreground)});
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case 'T':
|
case 'T':
|
||||||
m_sig.emit(change_font{parse_fontindex(value)});
|
m_sig.emit(change_font{parse_fontindex(value)});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'U':
|
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)});
|
||||||
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;
|
break;
|
||||||
|
|
||||||
case 'u':
|
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;
|
break;
|
||||||
|
|
||||||
case 'o':
|
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;
|
break;
|
||||||
|
|
||||||
case 'R':
|
case 'R':
|
||||||
|
@ -184,24 +176,10 @@ size_t parser::text(string&& data) {
|
||||||
return data.size();
|
return data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine color using passed stack and input value
|
|
||||||
*/
|
|
||||||
unsigned int parser::parse_color(std::stack<unsigned int>& 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
|
* 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] != '-') {
|
if (!s.empty() && s[0] != '-') {
|
||||||
return color_util::parse(s, fallback);
|
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
|
* Process font index and convert it to the correct value
|
||||||
*/
|
*/
|
||||||
int parser::parse_fontindex(const string& value) {
|
int parser::parse_fontindex(const string& s) {
|
||||||
auto font_index = 0;
|
if (s.empty() || s[0] == '-') {
|
||||||
auto reset = value.empty() || value[0] == '-';
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (reset && !m_fonts.empty()) {
|
|
||||||
m_fonts.pop();
|
|
||||||
} else if (!reset) {
|
|
||||||
try {
|
try {
|
||||||
font_index = std::stoul(value, nullptr, 10);
|
return std::stoul(s, nullptr, 10);
|
||||||
m_fonts.push(font_index);
|
|
||||||
return font_index;
|
|
||||||
} catch (const std::invalid_argument& err) {
|
} catch (const std::invalid_argument& err) {
|
||||||
return font_index;
|
return 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_fonts.empty()) {
|
|
||||||
return m_fonts.top();
|
|
||||||
} else {
|
|
||||||
return font_index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ namespace modules {
|
||||||
builder->flush();
|
builder->flush();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset != 0) {
|
if (offset != 0) {
|
||||||
builder->offset(offset);
|
builder->offset(offset);
|
||||||
}
|
}
|
||||||
|
@ -37,11 +36,23 @@ namespace modules {
|
||||||
builder->space(padding);
|
builder->space(padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!output.empty()) {
|
|
||||||
builder->node(prefix);
|
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->append(move(output));
|
||||||
builder->node(suffix);
|
builder->node(suffix);
|
||||||
}
|
|
||||||
|
|
||||||
if (padding > 0) {
|
if (padding > 0) {
|
||||||
builder->space(padding);
|
builder->space(padding);
|
||||||
|
|
Loading…
Reference in a new issue