fix(builder): Respect label-ellipsis option

This commit is contained in:
patrick96
2018-05-06 21:59:40 +02:00
parent 59e30221cc
commit 1725b71433
2 changed files with 16 additions and 2 deletions

View File

@ -559,8 +559,21 @@ string builder::foreground_hex() {
string builder::get_label_text(const label_t& label) {
string text{label->get()};
if (label->m_maxlen > 0 && string_util::char_len(text) > label->m_maxlen) {
text = string_util::utf8_truncate(std::move(text), label->m_maxlen) + "...";
size_t maxlen = label->m_maxlen;
if (maxlen > 0 && string_util::char_len(text) > maxlen ) {
if(label->m_ellipsis) {
if(maxlen < 3) {
throw application_error(sstream()
<< "Label has maxlen (" << maxlen
<< ") that is smaller than size of ellipsis(3)");
}
text = string_util::utf8_truncate(std::move(text), maxlen - 3) + "...";
}
else {
text = string_util::utf8_truncate(std::move(text), maxlen);
}
}
return text;

View File

@ -44,6 +44,7 @@ class GetLabelTextTest :
vector<pair<string, tuple<string, bool, int>>> get_label_text_list = {
{"...", make_tuple("abcd", true, 3)},
{"abc", make_tuple("abc", true, 3)},
{"abc", make_tuple("abcdefgh", false, 3)},
{"a...", make_tuple("abcdefgh", true, 4)},
{"abcd...", make_tuple("abcdefgh", true, 7)},