Cleanup builder

Removes unused methods and fields
This commit is contained in:
patrick96 2022-03-14 18:39:34 +01:00 committed by Patrick Ziegler
parent 4a61d3157f
commit 325ef4c3b3
14 changed files with 47 additions and 113 deletions

View File

@ -21,11 +21,9 @@ class builder {
void reset(); void reset();
string flush(); string flush();
void append(const string& text);
void node(const string& str); void node(const string& str);
void node(const string& str, int font_index); void node(const string& str, int font_index);
void node(const label_t& label); void node(const label_t& label);
void node_repeat(const string& str, size_t n);
void node_repeat(const label_t& label, size_t n); void node_repeat(const label_t& label, size_t n);
void offset(extent_val pixels = ZERO_PX_EXTENT); void offset(extent_val pixels = ZERO_PX_EXTENT);
void spacing(spacing_val size); void spacing(spacing_val size);
@ -35,12 +33,6 @@ class builder {
void background_close(); void background_close();
void color(rgba color); void color(rgba color);
void color_close(); void color_close();
void line_color(const rgba& color);
void line_color_close();
void overline_color(rgba color);
void overline_color_close();
void underline_color(rgba color);
void underline_color_close();
void overline(const rgba& color = rgba{}); void overline(const rgba& color = rgba{});
void overline_close(); void overline_close();
void underline(const rgba& color = rgba{}); void underline(const rgba& color = rgba{});
@ -55,6 +47,13 @@ class builder {
static string get_spacing_format_string(const spacing_val& space); static string get_spacing_format_string(const spacing_val& space);
protected: protected:
void append(const string& text);
void overline_color(rgba color);
void overline_color_close();
void underline_color(rgba color);
void underline_color_close();
void tag_open(tags::syntaxtag tag, const string& value); void tag_open(tags::syntaxtag tag, const string& value);
void tag_open(tags::attribute attr); void tag_open(tags::attribute attr);
void tag_close(tags::syntaxtag tag); void tag_close(tags::syntaxtag tag);
@ -65,10 +64,7 @@ class builder {
string m_output; string m_output;
map<tags::syntaxtag, int> m_tags{}; map<tags::syntaxtag, int> m_tags{};
map<tags::syntaxtag, string> m_colors{};
map<tags::attribute, bool> m_attrs{}; map<tags::attribute, bool> m_attrs{};
int m_fontindex{0};
}; };
POLYBAR_NS_END POLYBAR_NS_END

View File

@ -271,7 +271,7 @@ namespace modules {
m_builder->spacing(format->spacing); m_builder->spacing(format->spacing);
} }
m_builder->append(tag_content); m_builder->node(tag_content);
has_tags = true; has_tags = true;
} }
@ -279,7 +279,7 @@ namespace modules {
} }
if (cursor < value.size()) { if (cursor < value.size()) {
m_builder->append(value.substr(cursor)); m_builder->node(value.substr(cursor));
} }
return format->decorate(&*m_builder, m_builder->flush()); return format->decorate(&*m_builder, m_builder->flush());

View File

@ -31,19 +31,12 @@ void builder::reset() {
m_tags[syntaxtag::u] = 0; m_tags[syntaxtag::u] = 0;
m_tags[syntaxtag::P] = 0; m_tags[syntaxtag::P] = 0;
m_colors.clear();
m_colors[syntaxtag::B] = string();
m_colors[syntaxtag::F] = string();
m_colors[syntaxtag::o] = string();
m_colors[syntaxtag::u] = string();
m_attrs.clear(); m_attrs.clear();
m_attrs[attribute::NONE] = false; m_attrs[attribute::NONE] = false;
m_attrs[attribute::UNDERLINE] = false; m_attrs[attribute::UNDERLINE] = false;
m_attrs[attribute::OVERLINE] = false; m_attrs[attribute::OVERLINE] = false;
m_output.clear(); m_output.clear();
m_fontindex = 1;
} }
/** /**
@ -52,33 +45,20 @@ void builder::reset() {
* This will also close any unclosed tags * This will also close any unclosed tags
*/ */
string builder::flush() { string builder::flush() {
if (m_tags[syntaxtag::B]) {
background_close(); background_close();
}
if (m_tags[syntaxtag::F]) {
color_close(); color_close();
}
if (m_tags[syntaxtag::T]) {
font_close(); font_close();
}
if (m_tags[syntaxtag::o]) {
overline_color_close(); overline_color_close();
}
if (m_tags[syntaxtag::u]) {
underline_color_close(); underline_color_close();
}
if (m_attrs[attribute::UNDERLINE]) {
underline_close(); underline_close();
}
if (m_attrs[attribute::OVERLINE]) {
overline_close(); overline_close();
}
while (m_tags[syntaxtag::A]) { while (m_tags[syntaxtag::A]) {
action_close(); action_close();
} }
string output{m_output}; string output{};
std::swap(m_output, output);
reset(); reset();
@ -174,18 +154,6 @@ void builder::node(const label_t& label) {
} }
} }
/**
* Repeat text string n times
*/
void builder::node_repeat(const string& str, size_t n) {
string text;
text.reserve(str.size() * n);
while (n--) {
text += str;
}
node(text);
}
/** /**
* Repeat label contents n times * Repeat label contents n times
*/ */
@ -233,7 +201,6 @@ void builder::font(int index) {
if (index == 0) { if (index == 0) {
return; return;
} }
m_fontindex = index;
tag_open(syntaxtag::T, to_string(index)); tag_open(syntaxtag::T, to_string(index));
} }
@ -241,7 +208,6 @@ void builder::font(int index) {
* Insert tag to reset the font index * Insert tag to reset the font index
*/ */
void builder::font_close() { void builder::font_close() {
m_fontindex = 1;
tag_close(syntaxtag::T); tag_close(syntaxtag::T);
} }
@ -252,7 +218,6 @@ void builder::background(rgba color) {
color = color.try_apply_alpha_to(m_bar.background); color = color.try_apply_alpha_to(m_bar.background);
auto hex = color_util::simplify_hex(color); auto hex = color_util::simplify_hex(color);
m_colors[syntaxtag::B] = hex;
tag_open(syntaxtag::B, hex); tag_open(syntaxtag::B, hex);
} }
@ -260,7 +225,6 @@ void builder::background(rgba color) {
* Insert tag to reset the background color * Insert tag to reset the background color
*/ */
void builder::background_close() { void builder::background_close() {
m_colors[syntaxtag::B].clear();
tag_close(syntaxtag::B); tag_close(syntaxtag::B);
} }
@ -271,7 +235,6 @@ void builder::color(rgba color) {
color = color.try_apply_alpha_to(m_bar.foreground); color = color.try_apply_alpha_to(m_bar.foreground);
auto hex = color_util::simplify_hex(color); auto hex = color_util::simplify_hex(color);
m_colors[syntaxtag::F] = hex;
tag_open(syntaxtag::F, hex); tag_open(syntaxtag::F, hex);
} }
@ -279,32 +242,14 @@ void builder::color(rgba color) {
* Insert tag to reset the foreground color * Insert tag to reset the foreground color
*/ */
void builder::color_close() { void builder::color_close() {
m_colors[syntaxtag::F].clear();
tag_close(syntaxtag::F); tag_close(syntaxtag::F);
} }
/**
* Insert tag to alter the current overline/underline color
*/
void builder::line_color(const rgba& color) {
overline_color(color);
underline_color(color);
}
/**
* Close overline/underline color tag
*/
void builder::line_color_close() {
overline_color_close();
underline_color_close();
}
/** /**
* Insert tag to alter the current overline color * Insert tag to alter the current overline color
*/ */
void builder::overline_color(rgba color) { void builder::overline_color(rgba color) {
auto hex = color_util::simplify_hex(color); auto hex = color_util::simplify_hex(color);
m_colors[syntaxtag::o] = hex;
tag_open(syntaxtag::o, hex); tag_open(syntaxtag::o, hex);
tag_open(attribute::OVERLINE); tag_open(attribute::OVERLINE);
} }
@ -313,7 +258,6 @@ void builder::overline_color(rgba color) {
* Close underline color tag * Close underline color tag
*/ */
void builder::overline_color_close() { void builder::overline_color_close() {
m_colors[syntaxtag::o].clear();
tag_close(syntaxtag::o); tag_close(syntaxtag::o);
} }
@ -322,7 +266,6 @@ void builder::overline_color_close() {
*/ */
void builder::underline_color(rgba color) { void builder::underline_color(rgba color) {
auto hex = color_util::simplify_hex(color); auto hex = color_util::simplify_hex(color);
m_colors[syntaxtag::u] = hex;
tag_open(syntaxtag::u, hex); tag_open(syntaxtag::u, hex);
tag_open(attribute::UNDERLINE); tag_open(attribute::UNDERLINE);
} }
@ -332,7 +275,6 @@ void builder::underline_color(rgba color) {
*/ */
void builder::underline_color_close() { void builder::underline_color_close() {
tag_close(syntaxtag::u); tag_close(syntaxtag::u);
m_colors[syntaxtag::u].clear();
} }
/** /**
@ -415,7 +357,7 @@ void builder::action(mousebtn index, string action_name, const label_t& label) {
if (label && *label) { if (label && *label) {
action(index, action_name); action(index, action_name);
node(label); node(label);
tag_close(syntaxtag::A); action_close();
} }
} }
@ -531,13 +473,8 @@ void builder::tag_close(syntaxtag tag) {
case syntaxtag::o: case syntaxtag::o:
append("%{o-}"); append("%{o-}");
break; break;
case syntaxtag::R: default:
case syntaxtag::P: throw runtime_error("Cannot close syntaxtag: " + to_string(to_integral(tag)));
case syntaxtag::O:
case syntaxtag::l:
case syntaxtag::c:
case syntaxtag::r:
break;
} }
} }

View File

@ -212,7 +212,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, ""); m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
} }
m_builder->append(output); m_builder->node(output);
return m_builder->flush(); return m_builder->flush();
} }

View File

@ -98,7 +98,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, ""); m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
} }
m_builder->append(std::move(output)); m_builder->node(output);
m_builder->action_close(); m_builder->action_close();
m_builder->action_close(); m_builder->action_close();

View File

@ -99,7 +99,7 @@ namespace modules {
} }
} }
m_builder->append(output); m_builder->node(output);
return m_builder->flush(); return m_builder->flush();
} }

View File

@ -55,7 +55,7 @@ namespace modules {
builder->overline(ol); builder->overline(ol);
} }
builder->append(move(output)); builder->node(output);
builder->node(suffix); builder->node(suffix);
if (padding) { if (padding) {

View File

@ -128,7 +128,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, ""); m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
} }
m_builder->append(output); m_builder->node(output);
return m_builder->flush(); return m_builder->flush();
} }

View File

@ -120,7 +120,7 @@ namespace modules {
} }
} }
m_builder->append(output); m_builder->node(output);
return m_builder->flush(); return m_builder->flush();
} }

View File

@ -45,7 +45,7 @@ namespace modules {
if (tag == TAG_LABEL_TOGGLE) { if (tag == TAG_LABEL_TOGGLE) {
builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, "", m_label); builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, "", m_label);
} else if (tag == TAG_TRAY_CLIENTS && !m_hidden) { } else if (tag == TAG_TRAY_CLIENTS && !m_hidden) {
builder->append(TRAY_PLACEHOLDER); builder->node(TRAY_PLACEHOLDER);
} else { } else {
return false; return false;
} }

View File

@ -47,7 +47,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, scroll_down); m_builder->action(mousebtn::SCROLL_DOWN, scroll_down);
} }
m_builder->append(output); m_builder->node(output);
return m_builder->flush(); return m_builder->flush();
} }

View File

@ -123,7 +123,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, ""); m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
} }
m_builder->append(output); m_builder->node(output);
m_builder->action_close(); m_builder->action_close();
m_builder->action_close(); m_builder->action_close();

View File

@ -167,10 +167,10 @@ namespace modules {
if (m_keyboard && m_keyboard->size() > 1) { if (m_keyboard && m_keyboard->size() > 1) {
m_builder->action(mousebtn::LEFT, *this, EVENT_SWITCH, ""); m_builder->action(mousebtn::LEFT, *this, EVENT_SWITCH, "");
m_builder->append(output); m_builder->node(output);
m_builder->action_close(); m_builder->action_close();
} else { } else {
m_builder->append(output); m_builder->node(output);
} }
return m_builder->flush(); return m_builder->flush();

View File

@ -79,7 +79,8 @@ namespace modules {
if (vec.size() == 2) { if (vec.size() == 2) {
m_icons->add(vec[0], std::make_shared<label>(vec[1])); m_icons->add(vec[0], std::make_shared<label>(vec[1]));
} else { } else {
m_log.err("%s: Ignoring icon-%d because it has %s semicolons", name(), i, vec.size() > 2? "too many" : "too few"); m_log.err(
"%s: Ignoring icon-%d because it has %s semicolons", name(), i, vec.size() > 2 ? "too many" : "too few");
} }
i++; i++;
@ -324,7 +325,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_UP, *this, m_revscroll ? EVENT_PREV : EVENT_NEXT, ""); m_builder->action(mousebtn::SCROLL_UP, *this, m_revscroll ? EVENT_PREV : EVENT_NEXT, "");
} }
m_builder->append(output); m_builder->node(output);
m_builder->action_close(); m_builder->action_close();
m_builder->action_close(); m_builder->action_close();