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();
string flush();
void append(const string& text);
void node(const string& str);
void node(const string& str, int font_index);
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 offset(extent_val pixels = ZERO_PX_EXTENT);
void spacing(spacing_val size);
@ -35,12 +33,6 @@ class builder {
void background_close();
void color(rgba color);
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_close();
void underline(const rgba& color = rgba{});
@ -55,6 +47,13 @@ class builder {
static string get_spacing_format_string(const spacing_val& space);
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::attribute attr);
void tag_close(tags::syntaxtag tag);
@ -65,10 +64,7 @@ class builder {
string m_output;
map<tags::syntaxtag, int> m_tags{};
map<tags::syntaxtag, string> m_colors{};
map<tags::attribute, bool> m_attrs{};
int m_fontindex{0};
};
POLYBAR_NS_END

View File

@ -271,7 +271,7 @@ namespace modules {
m_builder->spacing(format->spacing);
}
m_builder->append(tag_content);
m_builder->node(tag_content);
has_tags = true;
}
@ -279,7 +279,7 @@ namespace modules {
}
if (cursor < value.size()) {
m_builder->append(value.substr(cursor));
m_builder->node(value.substr(cursor));
}
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::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[attribute::NONE] = false;
m_attrs[attribute::UNDERLINE] = false;
m_attrs[attribute::OVERLINE] = false;
m_output.clear();
m_fontindex = 1;
}
/**
@ -52,33 +45,20 @@ void builder::reset() {
* This will also close any unclosed tags
*/
string builder::flush() {
if (m_tags[syntaxtag::B]) {
background_close();
}
if (m_tags[syntaxtag::F]) {
color_close();
}
if (m_tags[syntaxtag::T]) {
font_close();
}
if (m_tags[syntaxtag::o]) {
overline_color_close();
}
if (m_tags[syntaxtag::u]) {
underline_color_close();
}
if (m_attrs[attribute::UNDERLINE]) {
underline_close();
}
if (m_attrs[attribute::OVERLINE]) {
overline_close();
}
background_close();
color_close();
font_close();
overline_color_close();
underline_color_close();
underline_close();
overline_close();
while (m_tags[syntaxtag::A]) {
action_close();
}
string output{m_output};
string output{};
std::swap(m_output, output);
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
*/
@ -233,7 +201,6 @@ void builder::font(int index) {
if (index == 0) {
return;
}
m_fontindex = index;
tag_open(syntaxtag::T, to_string(index));
}
@ -241,7 +208,6 @@ void builder::font(int index) {
* Insert tag to reset the font index
*/
void builder::font_close() {
m_fontindex = 1;
tag_close(syntaxtag::T);
}
@ -252,7 +218,6 @@ void builder::background(rgba color) {
color = color.try_apply_alpha_to(m_bar.background);
auto hex = color_util::simplify_hex(color);
m_colors[syntaxtag::B] = hex;
tag_open(syntaxtag::B, hex);
}
@ -260,7 +225,6 @@ void builder::background(rgba color) {
* Insert tag to reset the background color
*/
void builder::background_close() {
m_colors[syntaxtag::B].clear();
tag_close(syntaxtag::B);
}
@ -271,7 +235,6 @@ void builder::color(rgba color) {
color = color.try_apply_alpha_to(m_bar.foreground);
auto hex = color_util::simplify_hex(color);
m_colors[syntaxtag::F] = hex;
tag_open(syntaxtag::F, hex);
}
@ -279,32 +242,14 @@ void builder::color(rgba color) {
* Insert tag to reset the foreground color
*/
void builder::color_close() {
m_colors[syntaxtag::F].clear();
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
*/
void builder::overline_color(rgba color) {
auto hex = color_util::simplify_hex(color);
m_colors[syntaxtag::o] = hex;
tag_open(syntaxtag::o, hex);
tag_open(attribute::OVERLINE);
}
@ -313,7 +258,6 @@ void builder::overline_color(rgba color) {
* Close underline color tag
*/
void builder::overline_color_close() {
m_colors[syntaxtag::o].clear();
tag_close(syntaxtag::o);
}
@ -322,7 +266,6 @@ void builder::overline_color_close() {
*/
void builder::underline_color(rgba color) {
auto hex = color_util::simplify_hex(color);
m_colors[syntaxtag::u] = hex;
tag_open(syntaxtag::u, hex);
tag_open(attribute::UNDERLINE);
}
@ -332,7 +275,6 @@ void builder::underline_color(rgba color) {
*/
void builder::underline_color_close() {
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) {
action(index, action_name);
node(label);
tag_close(syntaxtag::A);
action_close();
}
}
@ -531,13 +473,8 @@ void builder::tag_close(syntaxtag tag) {
case syntaxtag::o:
append("%{o-}");
break;
case syntaxtag::R:
case syntaxtag::P:
case syntaxtag::O:
case syntaxtag::l:
case syntaxtag::c:
case syntaxtag::r:
break;
default:
throw runtime_error("Cannot close syntaxtag: " + to_string(to_integral(tag)));
}
}

View File

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

View File

@ -98,7 +98,7 @@ namespace modules {
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();
@ -141,6 +141,6 @@ namespace modules {
name(), err.what());
}
}
} // namespace modules
} // namespace modules
POLYBAR_NS_END

View File

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

View File

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

View File

@ -128,7 +128,7 @@ namespace modules {
m_builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_DEC, "");
}
m_builder->append(output);
m_builder->node(output);
return m_builder->flush();
}
@ -159,6 +159,6 @@ namespace modules {
void pulseaudio_module::action_toggle() {
m_pulseaudio->toggle_mute();
}
} // namespace modules
} // namespace modules
POLYBAR_NS_END

View File

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

View File

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

View File

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

View File

@ -123,7 +123,7 @@ namespace modules {
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();
@ -164,6 +164,6 @@ namespace modules {
m_connection.change_output_property_checked(
m_output->output, m_output->backlight.atom, XCB_ATOM_INTEGER, 32, XCB_PROP_MODE_REPLACE, 1, values);
}
} // namespace modules
} // namespace modules
POLYBAR_NS_END

View File

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

View File

@ -18,7 +18,7 @@ namespace {
inline bool operator==(const position& a, const position& b) {
return a.x + a.y == b.x + b.y;
}
} // namespace
} // namespace
/**
* Defines a lexicographical order on position
@ -79,7 +79,8 @@ namespace modules {
if (vec.size() == 2) {
m_icons->add(vec[0], std::make_shared<label>(vec[1]));
} 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++;
@ -324,7 +325,7 @@ namespace modules {
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();
@ -417,6 +418,6 @@ namespace modules {
m_log.info("%s: Ignoring change to current desktop", name());
}
}
} // namespace modules
} // namespace modules
POLYBAR_NS_END