2019-11-30 19:28:41 -05:00
|
|
|
#include "components/builder.hpp"
|
|
|
|
|
2016-11-25 07:55:15 -05:00
|
|
|
#include <utility>
|
|
|
|
|
2016-11-19 09:49:03 -05:00
|
|
|
#include "drawtypes/label.hpp"
|
2020-11-22 17:05:45 -05:00
|
|
|
#include "utils/actions.hpp"
|
2016-12-26 11:06:28 -05:00
|
|
|
#include "utils/color.hpp"
|
2016-11-02 15:22:45 -04:00
|
|
|
#include "utils/string.hpp"
|
2016-12-26 11:06:28 -05:00
|
|
|
#include "utils/time.hpp"
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2020-12-17 14:37:28 -05:00
|
|
|
using namespace tags;
|
|
|
|
|
2016-12-30 22:32:11 -05:00
|
|
|
builder::builder(const bar_settings& bar) : m_bar(bar) {
|
2019-01-12 08:51:54 -05:00
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void builder::reset() {
|
2018-12-28 11:10:52 -05:00
|
|
|
/* Add all values as keys so that we never have to check if a key exists in
|
|
|
|
* the map
|
|
|
|
*/
|
2019-01-12 08:51:54 -05:00
|
|
|
m_tags.clear();
|
2016-12-26 22:03:46 -05:00
|
|
|
m_tags[syntaxtag::A] = 0;
|
|
|
|
m_tags[syntaxtag::B] = 0;
|
|
|
|
m_tags[syntaxtag::F] = 0;
|
|
|
|
m_tags[syntaxtag::T] = 0;
|
2019-01-12 08:51:54 -05:00
|
|
|
m_tags[syntaxtag::R] = 0;
|
2016-12-26 22:03:46 -05:00
|
|
|
m_tags[syntaxtag::o] = 0;
|
|
|
|
m_tags[syntaxtag::u] = 0;
|
2019-01-12 08:51:54 -05:00
|
|
|
m_tags[syntaxtag::P] = 0;
|
2016-12-26 11:06:28 -05:00
|
|
|
|
2019-01-12 08:51:54 -05:00
|
|
|
m_colors.clear();
|
2016-12-26 11:06:28 -05:00
|
|
|
m_colors[syntaxtag::B] = string();
|
|
|
|
m_colors[syntaxtag::F] = string();
|
|
|
|
m_colors[syntaxtag::o] = string();
|
|
|
|
m_colors[syntaxtag::u] = string();
|
2018-12-28 11:10:52 -05:00
|
|
|
|
2019-01-12 08:51:54 -05:00
|
|
|
m_attrs.clear();
|
2018-12-28 11:10:52 -05:00
|
|
|
m_attrs[attribute::NONE] = false;
|
|
|
|
m_attrs[attribute::UNDERLINE] = false;
|
|
|
|
m_attrs[attribute::OVERLINE] = false;
|
2019-01-12 08:51:54 -05:00
|
|
|
|
|
|
|
m_output.clear();
|
|
|
|
m_fontindex = 1;
|
2016-12-26 04:37:14 -05:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Flush contents of the builder and return built string
|
|
|
|
*
|
|
|
|
* This will also close any unclosed tags
|
|
|
|
*/
|
2016-11-02 15:22:45 -04:00
|
|
|
string builder::flush() {
|
2016-11-25 07:55:15 -05:00
|
|
|
if (m_tags[syntaxtag::B]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
background_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
|
|
|
if (m_tags[syntaxtag::F]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
color_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
|
|
|
if (m_tags[syntaxtag::T]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
font_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
|
|
|
if (m_tags[syntaxtag::o]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
overline_color_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
|
|
|
if (m_tags[syntaxtag::u]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
underline_color_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2018-12-28 11:10:52 -05:00
|
|
|
if (m_attrs[attribute::UNDERLINE]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
underline_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2018-12-28 11:10:52 -05:00
|
|
|
if (m_attrs[attribute::OVERLINE]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
overline_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-24 22:10:26 -05:00
|
|
|
while (m_tags[syntaxtag::A]) {
|
2020-05-24 12:35:12 -04:00
|
|
|
action_close();
|
2016-11-24 22:10:26 -05:00
|
|
|
}
|
|
|
|
|
2016-12-26 22:03:46 -05:00
|
|
|
string output{m_output};
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2019-01-12 08:51:54 -05:00
|
|
|
reset();
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2018-12-25 20:17:22 -05:00
|
|
|
return output;
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert raw text string
|
|
|
|
*/
|
2016-12-26 11:06:28 -05:00
|
|
|
void builder::append(string text) {
|
|
|
|
m_output.reserve(text.size());
|
|
|
|
m_output += move(text);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert text node
|
|
|
|
*
|
|
|
|
* This will also parse raw syntax tags
|
|
|
|
*/
|
2019-12-11 15:38:21 -05:00
|
|
|
void builder::node(string str) {
|
2017-01-13 05:22:23 -05:00
|
|
|
if (str.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-02 12:59:34 -05:00
|
|
|
append(move(str));
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert text node with specific font index
|
|
|
|
*
|
2018-11-04 10:08:54 -05:00
|
|
|
* \see builder::node
|
2016-11-24 13:24:47 -05:00
|
|
|
*/
|
2019-12-11 15:38:21 -05:00
|
|
|
void builder::node(string str, int font_index) {
|
2016-11-02 15:22:45 -04:00
|
|
|
font(font_index);
|
2019-12-11 15:38:21 -05:00
|
|
|
node(move(str));
|
2016-11-02 15:22:45 -04:00
|
|
|
font_close();
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tags for given label
|
|
|
|
*/
|
2019-12-11 15:38:21 -05:00
|
|
|
void builder::node(const label_t& label) {
|
2016-11-25 07:55:15 -05:00
|
|
|
if (!label || !*label) {
|
2016-11-02 15:22:45 -04:00
|
|
|
return;
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2019-11-30 19:28:41 -05:00
|
|
|
auto text = label->get();
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-04 05:57:33 -05:00
|
|
|
if (label->m_margin.left > 0) {
|
|
|
|
space(label->m_margin.left);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2019-10-27 17:41:18 -04:00
|
|
|
if (label->m_overline.has_color()) {
|
2016-11-02 15:22:45 -04:00
|
|
|
overline(label->m_overline);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2019-10-27 17:41:18 -04:00
|
|
|
if (label->m_underline.has_color()) {
|
2016-11-02 15:22:45 -04:00
|
|
|
underline(label->m_underline);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2019-10-27 17:41:18 -04:00
|
|
|
if (label->m_background.has_color()) {
|
2016-11-24 13:24:47 -05:00
|
|
|
background(label->m_background);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2019-10-27 17:41:18 -04:00
|
|
|
if (label->m_foreground.has_color()) {
|
2016-11-24 13:24:47 -05:00
|
|
|
color(label->m_foreground);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-04 05:57:33 -05:00
|
|
|
if (label->m_padding.left > 0) {
|
|
|
|
space(label->m_padding.left);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2019-12-11 15:38:21 -05:00
|
|
|
node(text, label->m_font);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-04 05:57:33 -05:00
|
|
|
if (label->m_padding.right > 0) {
|
|
|
|
space(label->m_padding.right);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2019-10-27 17:41:18 -04:00
|
|
|
if (label->m_background.has_color()) {
|
2016-11-24 13:24:47 -05:00
|
|
|
background_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2019-10-27 17:41:18 -04:00
|
|
|
if (label->m_foreground.has_color()) {
|
2016-11-24 13:24:47 -05:00
|
|
|
color_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2019-10-27 17:41:18 -04:00
|
|
|
if (label->m_underline.has_color()) {
|
2016-11-24 13:24:47 -05:00
|
|
|
underline_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2019-10-27 17:41:18 -04:00
|
|
|
if (label->m_overline.has_color()) {
|
2016-11-24 13:24:47 -05:00
|
|
|
overline_close();
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-04 05:57:33 -05:00
|
|
|
if (label->m_margin.right > 0) {
|
|
|
|
space(label->m_margin.right);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-30 16:17:52 -05:00
|
|
|
/**
|
|
|
|
* Repeat text string n times
|
|
|
|
*/
|
2019-12-11 15:38:21 -05:00
|
|
|
void builder::node_repeat(const string& str, size_t n) {
|
2016-11-30 16:17:52 -05:00
|
|
|
string text;
|
2016-12-26 11:06:28 -05:00
|
|
|
text.reserve(str.size() * n);
|
2016-11-30 16:17:52 -05:00
|
|
|
while (n--) {
|
|
|
|
text += str;
|
|
|
|
}
|
2019-12-11 15:38:21 -05:00
|
|
|
node(text);
|
2016-11-30 16:17:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Repeat label contents n times
|
|
|
|
*/
|
2019-12-11 15:38:21 -05:00
|
|
|
void builder::node_repeat(const label_t& label, size_t n) {
|
2016-11-30 16:17:52 -05:00
|
|
|
string text;
|
2016-12-26 11:06:28 -05:00
|
|
|
string label_text{label->get()};
|
|
|
|
text.reserve(label_text.size() * n);
|
2016-11-30 16:17:52 -05:00
|
|
|
while (n--) {
|
2016-12-26 11:06:28 -05:00
|
|
|
text += label_text;
|
2016-11-30 16:17:52 -05:00
|
|
|
}
|
|
|
|
label_t tmp{new label_t::element_type{text}};
|
|
|
|
tmp->replace_defined_values(label);
|
2019-12-11 15:38:21 -05:00
|
|
|
node(tmp);
|
2016-11-30 16:17:52 -05:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag that will offset the contents by given pixels
|
|
|
|
*/
|
2016-11-02 15:22:45 -04:00
|
|
|
void builder::offset(int pixels) {
|
2016-11-25 07:55:15 -05:00
|
|
|
if (pixels == 0) {
|
2016-11-24 13:24:47 -05:00
|
|
|
return;
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_open(syntaxtag::O, to_string(pixels));
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert spaces
|
|
|
|
*/
|
2016-12-26 11:06:28 -05:00
|
|
|
void builder::space(size_t width) {
|
2017-01-10 19:42:55 -05:00
|
|
|
if (width) {
|
|
|
|
m_output.append(width, ' ');
|
|
|
|
} else {
|
|
|
|
space();
|
|
|
|
}
|
2016-12-26 11:06:28 -05:00
|
|
|
}
|
|
|
|
void builder::space() {
|
|
|
|
m_output.append(m_bar.spacing, ' ');
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Remove trailing space
|
|
|
|
*/
|
2016-12-26 11:06:28 -05:00
|
|
|
void builder::remove_trailing_space(size_t len) {
|
2016-12-30 22:32:11 -05:00
|
|
|
if (len == 0_z || len > m_output.size()) {
|
2016-11-02 15:22:45 -04:00
|
|
|
return;
|
2016-12-30 14:34:13 -05:00
|
|
|
} else if (m_output.substr(m_output.size() - len) == string(len, ' ')) {
|
2016-12-26 11:06:28 -05:00
|
|
|
m_output.erase(m_output.size() - len);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
2016-12-26 11:06:28 -05:00
|
|
|
void builder::remove_trailing_space() {
|
|
|
|
remove_trailing_space(m_bar.spacing);
|
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to alter the current font index
|
|
|
|
*/
|
2016-11-02 15:22:45 -04:00
|
|
|
void builder::font(int index) {
|
2016-11-30 16:17:52 -05:00
|
|
|
if (index == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
m_fontindex = index;
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_open(syntaxtag::T, to_string(index));
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to reset the font index
|
|
|
|
*/
|
|
|
|
void builder::font_close() {
|
2016-11-02 15:22:45 -04:00
|
|
|
m_fontindex = 1;
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_close(syntaxtag::T);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to alter the current background color
|
|
|
|
*/
|
2019-10-27 17:41:18 -04:00
|
|
|
void builder::background(rgba color) {
|
2020-12-01 08:49:41 -05:00
|
|
|
color = color.try_apply_alpha_to(m_bar.background);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2019-10-27 17:41:18 -04:00
|
|
|
auto hex = color_util::simplify_hex(color);
|
|
|
|
m_colors[syntaxtag::B] = hex;
|
|
|
|
tag_open(syntaxtag::B, hex);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to reset the background color
|
|
|
|
*/
|
|
|
|
void builder::background_close() {
|
2016-12-26 11:06:28 -05:00
|
|
|
m_colors[syntaxtag::B].clear();
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_close(syntaxtag::B);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to alter the current foreground color
|
|
|
|
*/
|
2019-10-27 17:41:18 -04:00
|
|
|
void builder::color(rgba color) {
|
2020-12-01 08:49:41 -05:00
|
|
|
color = color.try_apply_alpha_to(m_bar.foreground);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2019-10-27 17:41:18 -04:00
|
|
|
auto hex = color_util::simplify_hex(color);
|
|
|
|
m_colors[syntaxtag::F] = hex;
|
|
|
|
tag_open(syntaxtag::F, hex);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to reset the foreground color
|
|
|
|
*/
|
|
|
|
void builder::color_close() {
|
2016-12-26 11:06:28 -05:00
|
|
|
m_colors[syntaxtag::F].clear();
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_close(syntaxtag::F);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to alter the current overline/underline color
|
|
|
|
*/
|
2019-10-27 17:41:18 -04:00
|
|
|
void builder::line_color(const rgba& color) {
|
2016-11-24 13:24:47 -05:00
|
|
|
overline_color(color);
|
|
|
|
underline_color(color);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Close overline/underline color tag
|
|
|
|
*/
|
|
|
|
void builder::line_color_close() {
|
|
|
|
overline_color_close();
|
|
|
|
underline_color_close();
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to alter the current overline color
|
|
|
|
*/
|
2019-10-27 17:41:18 -04:00
|
|
|
void builder::overline_color(rgba color) {
|
|
|
|
auto hex = color_util::simplify_hex(color);
|
|
|
|
m_colors[syntaxtag::o] = hex;
|
|
|
|
tag_open(syntaxtag::o, hex);
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_open(attribute::OVERLINE);
|
2016-11-21 10:14:40 -05:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Close underline color tag
|
|
|
|
*/
|
|
|
|
void builder::overline_color_close() {
|
2016-12-26 11:06:28 -05:00
|
|
|
m_colors[syntaxtag::o].clear();
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_close(syntaxtag::o);
|
2016-11-21 10:14:40 -05:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to alter the current underline color
|
|
|
|
*/
|
2019-10-27 17:41:18 -04:00
|
|
|
void builder::underline_color(rgba color) {
|
|
|
|
auto hex = color_util::simplify_hex(color);
|
|
|
|
m_colors[syntaxtag::u] = hex;
|
|
|
|
tag_open(syntaxtag::u, hex);
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_open(attribute::UNDERLINE);
|
2016-11-21 10:14:40 -05:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Close underline color tag
|
|
|
|
*/
|
|
|
|
void builder::underline_color_close() {
|
|
|
|
tag_close(syntaxtag::u);
|
2016-12-26 11:06:28 -05:00
|
|
|
m_colors[syntaxtag::u].clear();
|
2016-11-21 10:14:40 -05:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to enable the overline attribute
|
|
|
|
*/
|
2019-10-27 17:41:18 -04:00
|
|
|
void builder::overline(const rgba& color) {
|
|
|
|
if (color.has_color()) {
|
2016-11-21 10:14:40 -05:00
|
|
|
overline_color(color);
|
2016-11-25 07:55:15 -05:00
|
|
|
} else {
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_open(attribute::OVERLINE);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Close overline attribute tag
|
|
|
|
*/
|
|
|
|
void builder::overline_close() {
|
|
|
|
tag_close(attribute::OVERLINE);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert tag to enable the underline attribute
|
|
|
|
*/
|
2019-10-27 17:41:18 -04:00
|
|
|
void builder::underline(const rgba& color) {
|
|
|
|
if (color.has_color()) {
|
2016-11-21 10:14:40 -05:00
|
|
|
underline_color(color);
|
2016-11-25 07:55:15 -05:00
|
|
|
} else {
|
2016-11-24 13:24:47 -05:00
|
|
|
tag_open(attribute::UNDERLINE);
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Close underline attribute tag
|
|
|
|
*/
|
|
|
|
void builder::underline_close() {
|
|
|
|
tag_close(attribute::UNDERLINE);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2019-01-12 08:51:54 -05:00
|
|
|
/**
|
|
|
|
* Add a polybar control tag
|
|
|
|
*/
|
|
|
|
void builder::control(controltag tag) {
|
|
|
|
string str;
|
|
|
|
switch (tag) {
|
|
|
|
case controltag::R:
|
|
|
|
str = "R";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-06 13:35:07 -04:00
|
|
|
if (!str.empty()) {
|
2019-01-12 08:51:54 -05:00
|
|
|
tag_open(syntaxtag::P, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
2020-05-24 12:35:12 -04:00
|
|
|
* Open action tag with the given action string
|
|
|
|
*
|
|
|
|
* The action string is escaped, if needed.
|
2016-11-24 13:24:47 -05:00
|
|
|
*/
|
2020-05-24 12:35:12 -04:00
|
|
|
void builder::action(mousebtn index, string action) {
|
2019-12-18 04:27:39 -05:00
|
|
|
if (!action.empty()) {
|
2018-10-10 10:46:40 -04:00
|
|
|
action = string_util::replace_all(action, ":", "\\:");
|
2017-01-13 05:22:23 -05:00
|
|
|
tag_open(syntaxtag::A, to_string(static_cast<int>(index)) + ":" + action + ":");
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2017-01-13 05:22:23 -05:00
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2020-05-06 19:26:14 -04:00
|
|
|
/**
|
2020-11-22 17:05:45 -05:00
|
|
|
* Open action tag for the action of the given module
|
2020-05-06 19:26:14 -04:00
|
|
|
*/
|
2020-11-22 17:05:45 -05:00
|
|
|
void builder::action(mousebtn btn, const modules::module_interface& module, string action_name, string data) {
|
|
|
|
action(btn, actions_util::get_action_string(module, action_name, data));
|
2020-05-06 19:26:14 -04:00
|
|
|
}
|
|
|
|
|
2017-01-13 05:22:23 -05:00
|
|
|
/**
|
2020-05-24 12:35:12 -04:00
|
|
|
* Wrap label in action tag
|
2017-01-13 05:22:23 -05:00
|
|
|
*/
|
2020-05-24 12:35:12 -04:00
|
|
|
void builder::action(mousebtn index, string action_name, const label_t& label) {
|
2017-03-21 11:03:34 -04:00
|
|
|
if (label && *label) {
|
2020-05-24 12:35:12 -04:00
|
|
|
action(index, action_name);
|
2017-01-13 05:22:23 -05:00
|
|
|
node(label);
|
|
|
|
tag_close(syntaxtag::A);
|
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2020-05-06 19:26:14 -04:00
|
|
|
/**
|
2020-05-24 12:35:12 -04:00
|
|
|
* Wrap label in module action tag
|
2020-05-06 19:26:14 -04:00
|
|
|
*/
|
2020-11-22 17:05:45 -05:00
|
|
|
void builder::action(
|
|
|
|
mousebtn btn, const modules::module_interface& module, string action_name, string data, const label_t& label) {
|
|
|
|
action(btn, actions_util::get_action_string(module, action_name, data), label);
|
2020-05-06 19:26:14 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Close command tag
|
|
|
|
*/
|
2020-05-24 12:35:12 -04:00
|
|
|
void builder::action_close() {
|
2019-12-18 04:27:39 -05:00
|
|
|
tag_close(syntaxtag::A);
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:24:47 -05:00
|
|
|
/**
|
|
|
|
* Insert directive to change value of given tag
|
|
|
|
*/
|
2016-11-25 07:55:15 -05:00
|
|
|
void builder::tag_open(syntaxtag tag, const string& value) {
|
2016-11-24 22:10:26 -05:00
|
|
|
m_tags[tag]++;
|
2016-11-24 13:24:47 -05:00
|
|
|
|
|
|
|
switch (tag) {
|
|
|
|
case syntaxtag::A:
|
|
|
|
append("%{A" + value + "}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::F:
|
|
|
|
append("%{F" + value + "}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::B:
|
|
|
|
append("%{B" + value + "}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::T:
|
|
|
|
append("%{T" + value + "}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::u:
|
|
|
|
append("%{u" + value + "}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::o:
|
|
|
|
append("%{o" + value + "}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::R:
|
|
|
|
append("%{R}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::O:
|
|
|
|
append("%{O" + value + "}");
|
|
|
|
break;
|
2019-01-12 08:51:54 -05:00
|
|
|
case syntaxtag::P:
|
|
|
|
append("%{P" + value + "}");
|
|
|
|
break;
|
2020-12-17 14:37:28 -05:00
|
|
|
case syntaxtag::l:
|
|
|
|
append("%{l}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::c:
|
|
|
|
append("%{c}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::r:
|
|
|
|
append("%{r}");
|
|
|
|
break;
|
2016-11-24 13:24:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert directive to use given attribute unless already set
|
|
|
|
*/
|
|
|
|
void builder::tag_open(attribute attr) {
|
2018-12-28 11:10:52 -05:00
|
|
|
if (m_attrs[attr]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
return;
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-24 13:24:47 -05:00
|
|
|
|
2018-12-28 11:10:52 -05:00
|
|
|
m_attrs[attr] = true;
|
2016-11-24 13:24:47 -05:00
|
|
|
|
|
|
|
switch (attr) {
|
|
|
|
case attribute::NONE:
|
|
|
|
break;
|
|
|
|
case attribute::UNDERLINE:
|
|
|
|
append("%{+u}");
|
|
|
|
break;
|
|
|
|
case attribute::OVERLINE:
|
|
|
|
append("%{+o}");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert directive to reset given tag if it's open and closable
|
|
|
|
*/
|
|
|
|
void builder::tag_close(syntaxtag tag) {
|
2018-12-28 11:10:52 -05:00
|
|
|
if (!m_tags[tag]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
return;
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-24 13:24:47 -05:00
|
|
|
|
|
|
|
m_tags[tag]--;
|
|
|
|
|
|
|
|
switch (tag) {
|
|
|
|
case syntaxtag::A:
|
|
|
|
append("%{A}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::F:
|
|
|
|
append("%{F-}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::B:
|
|
|
|
append("%{B-}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::T:
|
|
|
|
append("%{T-}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::u:
|
|
|
|
append("%{u-}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::o:
|
|
|
|
append("%{o-}");
|
|
|
|
break;
|
|
|
|
case syntaxtag::R:
|
2019-01-12 08:51:54 -05:00
|
|
|
case syntaxtag::P:
|
2016-11-24 13:24:47 -05:00
|
|
|
case syntaxtag::O:
|
2020-12-17 14:37:28 -05:00
|
|
|
case syntaxtag::l:
|
|
|
|
case syntaxtag::c:
|
|
|
|
case syntaxtag::r:
|
2016-11-24 13:24:47 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert directive to remove given attribute if set
|
|
|
|
*/
|
|
|
|
void builder::tag_close(attribute attr) {
|
2018-12-28 11:10:52 -05:00
|
|
|
if (!m_attrs[attr]) {
|
2016-11-24 13:24:47 -05:00
|
|
|
return;
|
2016-11-25 07:55:15 -05:00
|
|
|
}
|
2016-11-24 13:24:47 -05:00
|
|
|
|
2018-12-28 11:10:52 -05:00
|
|
|
m_attrs[attr] = false;
|
2016-11-24 13:24:47 -05:00
|
|
|
|
|
|
|
switch (attr) {
|
|
|
|
case attribute::NONE:
|
|
|
|
break;
|
|
|
|
case attribute::UNDERLINE:
|
|
|
|
append("%{-u}");
|
|
|
|
break;
|
|
|
|
case attribute::OVERLINE:
|
|
|
|
append("%{-o}");
|
|
|
|
break;
|
|
|
|
}
|
2016-11-02 15:22:45 -04:00
|
|
|
}
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|