GothenburgBitFactory / GothenburgBitFactory/taskwarrior
[Patch] Reset width calculation on newlines
- Dominant language
- C++
- Stars
- 6.1k
- Forks
- 423
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 11
Description
This is a naive patch I have applied to my v2.5.1 installation with regard to width calculation.
Without it a column with the content '12345\n67890' would have a width of 10, with it of 5.
I usually have long descriptions and this works around the "The report has a minimum width of ... and does not fit in the available width of ...." issue.
```
diff -Nur task-2.5.1+dfsg/src/text.cpp patched/src/text.cpp
--- task-2.5.1+dfsg/src/text.cpp 2016-02-25 08:37:00.000000000 +0000
+++ patched/src/text.cpp 2020-04-04 11:22:28.986081411 +0000
@@ -180,7 +180,7 @@
while ((character = utf8_next_char (input, i)))
{
- if (character == ' ')
+ if (character == ' ' || character == '\n')
{
if (length > longest)
longest = length;
diff -Nur task-2.5.1+dfsg/src/utf8.cpp patched/src/utf8.cpp
--- task-2.5.1+dfsg/src/utf8.cpp 2016-02-25 08:37:00.000000000 +0000
+++ patched/src/utf8.cpp 2020-04-04 11:18:08.366305683 +0000
@@ -187,10 +187,16 @@
unsigned int utf8_width (const std::string& str)
{
unsigned int length = 0;
+ unsigned int max = 0;
std::string::size_type i = 0;
unsigned int c;
while ((c = utf8_next_char (str, i)))
{
+ if (c == '\n') {
+ max = max > length ? max : length;
+ length = 0;
+ continue;
+ }
// Control characters, and more especially newline characters, make
// mk_wcwidth() return -1. Ignore that, thereby "adding zero" to length.
// Since control characters are not displayed in reports, this is a valid
@@ -200,7 +206,7 @@
length += l;
}
- return length;
+ return max > length ? max : length;
}
////////////////////////////////////////////////////////////////////////////////
```
Contributor guide
Assessment
This issue has not been assessed yet.