mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
ColTags: Reduced total work
- When there is only a single tag, there is no need to split, sort and word wrap.
This commit is contained in:
parent
0a0793b2ca
commit
fa035c3fde
1 changed files with 22 additions and 16 deletions
|
@ -50,7 +50,7 @@ ColumnTags::ColumnTags ()
|
||||||
_examples = {STRING_COLUMN_EXAMPLES_TAGS,
|
_examples = {STRING_COLUMN_EXAMPLES_TAGS,
|
||||||
context.config.get ("tag.indicator"),
|
context.config.get ("tag.indicator"),
|
||||||
"[2]"};
|
"[2]"};
|
||||||
_hyphenate = context.config.getBoolean ("hyphenate");
|
_hyphenate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -92,19 +92,23 @@ void ColumnTags::measure (Task& task, unsigned int& minimum, unsigned int& maxim
|
||||||
_style == "list")
|
_style == "list")
|
||||||
{
|
{
|
||||||
std::string tags = task.get (_name);
|
std::string tags = task.get (_name);
|
||||||
maximum = utf8_width (tags);
|
|
||||||
|
|
||||||
if (maximum)
|
// Find the widest tag.
|
||||||
|
if (tags.find (',') != std::string::npos)
|
||||||
{
|
{
|
||||||
std::vector <std::string> all;
|
std::vector <std::string> all;
|
||||||
split (all, tags, ',');
|
split (all, tags, ',');
|
||||||
for (auto& i : all)
|
for (const auto& tag : all)
|
||||||
{
|
{
|
||||||
unsigned int length = utf8_width (i);
|
auto length = utf8_width (tag);
|
||||||
if (length > minimum)
|
if (length > minimum)
|
||||||
minimum = length;
|
minimum = length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No need to split a single tag.
|
||||||
|
else
|
||||||
|
minimum = maximum = utf8_width (tags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
|
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
|
||||||
|
@ -124,19 +128,21 @@ void ColumnTags::render (
|
||||||
if (_style == "default" ||
|
if (_style == "default" ||
|
||||||
_style == "list")
|
_style == "list")
|
||||||
{
|
{
|
||||||
std::vector <std::string> allTags;
|
if (tags.find (',') != std::string::npos)
|
||||||
split (allTags, tags, ',');
|
|
||||||
if (allTags.size () > 1)
|
|
||||||
{
|
{
|
||||||
std::sort (allTags.begin (), allTags.end ());
|
std::vector <std::string> all;
|
||||||
join (tags, " ", allTags);
|
split (all, tags, ',');
|
||||||
|
std::sort (all.begin (), all.end ());
|
||||||
|
join (tags, " ", all);
|
||||||
|
|
||||||
|
all.clear ();
|
||||||
|
wrapText (all, tags, width, _hyphenate);
|
||||||
|
|
||||||
|
for (const auto& i : all)
|
||||||
|
renderStringLeft (lines, width, color, i);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
std::vector <std::string> all;
|
renderStringLeft (lines, width, color, tags);
|
||||||
wrapText (all, tags, width, _hyphenate);
|
|
||||||
|
|
||||||
for (auto& i : all)
|
|
||||||
renderStringLeft (lines, width, color, i);
|
|
||||||
}
|
}
|
||||||
else if (_style == "indicator")
|
else if (_style == "indicator")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue