diff --git a/examples/config.cmake b/examples/config.cmake index 515370e5..87293f70 100644 --- a/examples/config.cmake +++ b/examples/config.cmake @@ -65,7 +65,7 @@ tray-padding = 2 [module/xwindow] type = internal/xwindow -label = %title:0:30% +label = %title:0:30:...% [module/xkeyboard] type = internal/xkeyboard diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp index f352c1df..605de80f 100644 --- a/include/drawtypes/label.hpp +++ b/include/drawtypes/label.hpp @@ -11,10 +11,11 @@ POLYBAR_NS */ namespace drawtypes { - struct bounds { + struct token { string token; size_t min; size_t max; + string suffix{""}; }; class label; @@ -41,7 +42,7 @@ namespace drawtypes { explicit label(string text, int font) : m_font(font), m_text(text), m_tokenized(m_text) {} explicit label(string text, string foreground = "", string background = "", string underline = "", string overline = "", int font = 0, int padding = 0, int margin = 0, size_t maxlen = 0, bool ellipsis = true, - const vector& bound = {}) + vector&& tokens = {}) : m_foreground(foreground) , m_background(background) , m_underline(underline) @@ -53,7 +54,7 @@ namespace drawtypes { , m_ellipsis(ellipsis) , m_text(text) , m_tokenized(m_text) - , m_token_bounds(bound) {} + , m_tokens(forward>(tokens)) {} string get() const; operator bool(); @@ -66,7 +67,7 @@ namespace drawtypes { private: string m_text, m_tokenized; - const vector m_token_bounds; + const vector m_tokens; }; label_t load_label(const config& conf, const string& section, string name, bool required = true, string def = ""); diff --git a/include/utils/string.hpp b/include/utils/string.hpp index fcb58b91..72f7bc3b 100644 --- a/include/utils/string.hpp +++ b/include/utils/string.hpp @@ -16,12 +16,10 @@ namespace string_util { string upper(const string& s); string lower(const string& s); bool compare(const string& s1, const string& s2); - string replace( - const string& haystack, const string& needle, const string& reply, size_t start = 0, size_t end = string::npos); - string replace_all( - const string& haystack, const string& needle, const string& reply, size_t start = 0, size_t end = string::npos); - string replace_all_bounded(const string& haystack, string needle, string replacement, size_t min, size_t max, - size_t start = 0, size_t end = string::npos); + string replace(const string& haystack, const string& needle, const string& replacement, size_t start = 0, + size_t end = string::npos); + string replace_all(const string& haystack, const string& needle, const string& replacement, size_t start = 0, + size_t end = string::npos); string squeeze(const string& haystack, char needle); string strip(const string& haystack, char needle); string strip_trailing_newline(const string& haystack); diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp index b5edf264..70d218d8 100644 --- a/src/drawtypes/label.cpp +++ b/src/drawtypes/label.cpp @@ -14,8 +14,13 @@ namespace drawtypes { } label_t label::clone() { + vector tokens; + if (!m_tokens.empty()) { + std::back_insert_iterator back_it(tokens); + std::copy(m_tokens.begin(), m_tokens.end(), back_it); + } return make_shared