mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Text: Justification auto-truncates
This commit is contained in:
parent
029f3af578
commit
f1785c6da9
1 changed files with 16 additions and 1 deletions
17
src/text.cpp
17
src/text.cpp
|
@ -630,6 +630,14 @@ std::string leftJustify (const int input, const int width)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string leftJustify (const std::string& input, const int width)
|
||||
{
|
||||
auto len = utf8_text_width (input);
|
||||
|
||||
if (len == width)
|
||||
return input;
|
||||
|
||||
if (len > width)
|
||||
return input.substr (0, width);
|
||||
|
||||
return input + std::string (width - utf8_text_width (input), ' ');
|
||||
}
|
||||
|
||||
|
@ -652,7 +660,14 @@ std::string rightJustify (const int input, const int width)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string rightJustify (const std::string& input, const int width)
|
||||
{
|
||||
unsigned int len = utf8_text_width (input);
|
||||
auto len = utf8_text_width (input);
|
||||
|
||||
if (len == width)
|
||||
return input;
|
||||
|
||||
if (len > width)
|
||||
return input.substr (0, width);
|
||||
|
||||
return (((unsigned int) width > len)
|
||||
? std::string (width - len, ' ')
|
||||
: "")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue