- Fixed bug #1218 so that description columns minimum width is calculated
  correctly.
This commit is contained in:
Paul Beckingham
2013-04-01 18:07:25 -04:00
parent d14a9cacec
commit d895c4a249
6 changed files with 81 additions and 63 deletions

View File

@@ -109,6 +109,8 @@ Bugs
Heusler). Heusler).
+ Fixed bug #1210 so that widths are taken from localized strings instead of + Fixed bug #1210 so that widths are taken from localized strings instead of
hardcoded. hardcoded.
+ Fixed bug #1218 so that description columns minimum width is calculated
correctly.
+ Improved hyphenation by splitting on commas (even if no whitespace after). + Improved hyphenation by splitting on commas (even if no whitespace after).
Leads to better output of, for example, 'task show', where comma-separated Leads to better output of, for example, 'task show', where comma-separated
lists are common. lists are common.

View File

@@ -27,11 +27,13 @@
#define L10N // Localization complete. #define L10N // Localization complete.
#include <numeric>
#include <ViewTask.h> #include <ViewTask.h>
#include <Context.h> #include <Context.h>
#include <Timer.h> #include <Timer.h>
#include <text.h> #include <text.h>
#include <utf8.h> #include <utf8.h>
#include <i18n.h>
#include <main.h> #include <main.h>
extern Context context; extern Context context;
@@ -153,41 +155,56 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
ideal.push_back (global_ideal); ideal.push_back (global_ideal);
} }
if (!print_empty_columns && global_min != 0) if (! print_empty_columns && global_min != 0)
{ {
nonempty_columns.push_back(*i); nonempty_columns.push_back (*i);
} }
} }
if (!print_empty_columns) if (! print_empty_columns)
_columns = nonempty_columns; _columns = nonempty_columns;
// Sum the minimal widths. int all_extra = _left_margin
int sum_minimal = 0; + (2 * _extra_padding)
std::vector <int>::iterator c; + ((_columns.size () - 1) * _intra_padding);
for (c = minimal.begin (); c != minimal.end (); ++c)
sum_minimal += *c; // Sum the widths.
int sum_minimal = std::accumulate (minimal.begin (), minimal.end (), 0);
int sum_ideal = std::accumulate (ideal.begin (), ideal.end (), 0);
// Sum the ideal widths.
int sum_ideal = 0;
for (c = ideal.begin (); c != ideal.end (); ++c)
sum_ideal += *c;
// Calculate final column widths. // Calculate final column widths.
int overage = _width int overage = _width - sum_minimal - all_extra;
- _left_margin context.debug (format ("ViewTask::render min={1} ideal={2} overage={3}",
- (2 * _extra_padding) sum_minimal + all_extra,
- ((_columns.size () - 1) * _intra_padding); sum_ideal + all_extra,
overage));
std::vector <int> widths; std::vector <int> widths;
if (_width == 0 || sum_ideal <= overage)
// Ideal case. Everything fits.
if (_width == 0 || sum_ideal + all_extra <= _width)
{
widths = ideal; widths = ideal;
else if (sum_minimal > overage || overage < 0) }
// Not enough for minimum.
else if (overage < 0)
{
context.error (format (STRING_VIEW_TOO_SMALL, sum_minimal + all_extra, _width));
widths = minimal; widths = minimal;
}
// Perfect minimal width.
else if (overage == 0)
{
widths = minimal;
}
// Extra space to share.
else if (overage > 0) else if (overage > 0)
{ {
widths = minimal; widths = minimal;
overage -= sum_minimal;
// Spread 'overage' among columns where width[i] < ideal[i] // Spread 'overage' among columns where width[i] < ideal[i]
bool needed = true; bool needed = true;

View File

@@ -52,7 +52,11 @@ ColumnDescription::ColumnDescription ()
_styles.push_back ("truncated"); _styles.push_back ("truncated");
_styles.push_back ("count"); _styles.push_back ("count");
std::string t = Date ().toString (context.config.get ("dateformat")); _dateformat = context.config.get ("dateformat.annotation");
if (_dateformat == "")
_dateformat = context.config.get ("dateformat");
std::string t = Date ().toString (_dateformat);
std::string d = STRING_COLUMN_EXAMPLES_DESC; std::string d = STRING_COLUMN_EXAMPLES_DESC;
std::string a1 = STRING_COLUMN_EXAMPLES_ANNO1; std::string a1 = STRING_COLUMN_EXAMPLES_ANNO1;
std::string a2 = STRING_COLUMN_EXAMPLES_ANNO2; std::string a2 = STRING_COLUMN_EXAMPLES_ANNO2;
@@ -74,6 +78,8 @@ ColumnDescription::ColumnDescription ()
_examples.push_back (d + " [4]"); _examples.push_back (d + " [4]");
_hyphenate = context.config.getBoolean ("hyphenate"); _hyphenate = context.config.getBoolean ("hyphenate");
_indent = context.config.getInteger ("indent.annotation");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -99,24 +105,24 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
if (_style == "default" || if (_style == "default" ||
_style == "combined") _style == "combined")
{ {
int indent = context.config.getInteger ("indent.annotation"); minimum = longestWord (description);
std::string format = context.config.get ("dateformat.annotation");
if (format == "")
format = context.config.get ("dateformat");
int min_desc = longestWord (description);
int min_anno = indent + Date::length (format);
minimum = std::max (min_desc, min_anno);
maximum = utf8_width (description); maximum = utf8_width (description);
std::map <std::string, std::string> annos; if (task.annotation_count)
task.getAnnotations (annos);
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++)
{ {
unsigned int len = min_anno + 1 + utf8_width (i->second); int min_anno = _indent + Date::length (_dateformat);
if (len > maximum) if (min_anno > minimum)
maximum = len; minimum = min_anno;
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++)
{
unsigned int len = min_anno + 1 + utf8_width (i->second);
if (len > maximum)
maximum = len;
}
} }
} }
@@ -130,20 +136,18 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
// The text <date> <anno> ... // The text <date> <anno> ...
else if (_style == "oneline") else if (_style == "oneline")
{ {
std::string format = context.config.get ("dateformat.annotation"); minimum = longestWord (description);
if (format == "")
format = context.config.get ("dateformat");
int min_desc = longestWord (description);
int min_anno = Date::length (format);
minimum = std::max (min_desc, min_anno);
maximum = utf8_width (description); maximum = utf8_width (description);
std::map <std::string, std::string> annos; if (task.annotation_count)
task.getAnnotations (annos); {
std::map <std::string, std::string>::iterator i; int min_anno = Date::length (_dateformat);
for (i = annos.begin (); i != annos.end (); i++) std::map <std::string, std::string> annos;
maximum += utf8_width (i->second) + minimum + 1; task.getAnnotations (annos);
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++)
maximum += min_anno + 1 + utf8_width (i->second);
}
} }
// The te... // The te...
@@ -156,11 +160,8 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
// The text [2] // The text [2]
else if (_style == "count") else if (_style == "count")
{ {
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
// <description> + ' ' + '[' + <count> + ']' // <description> + ' ' + '[' + <count> + ']'
maximum = utf8_width (description) + 3 + utf8_width (format ((int)annos.size ())); maximum = utf8_width (description) + 1 + 1 + format (task.annotation_count).length () + 1;
minimum = longestWord (description); minimum = longestWord (description);
} }
@@ -183,21 +184,15 @@ void ColumnDescription::render (
if (_style == "default" || if (_style == "default" ||
_style == "combined") _style == "combined")
{ {
int indent = context.config.getInteger ("indent.annotation");
std::map <std::string, std::string> annos; std::map <std::string, std::string> annos;
task.getAnnotations (annos); task.getAnnotations (annos);
if (annos.size ()) if (annos.size ())
{ {
std::string format = context.config.get ("dateformat.annotation");
if (format == "")
format = context.config.get ("dateformat");
std::map <std::string, std::string>::iterator i; std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++) for (i = annos.begin (); i != annos.end (); i++)
{ {
Date dt (strtol (i->first.substr (11).c_str (), NULL, 10)); Date dt (strtol (i->first.substr (11).c_str (), NULL, 10));
description += "\n" + std::string (indent, ' ') + dt.toString (format) + " " + i->second; description += "\n" + std::string (_indent, ' ') + dt.toString (_dateformat) + " " + i->second;
} }
} }
@@ -227,15 +222,11 @@ void ColumnDescription::render (
task.getAnnotations (annos); task.getAnnotations (annos);
if (annos.size ()) if (annos.size ())
{ {
std::string format = context.config.get ("dateformat.annotation");
if (format == "")
format = context.config.get ("dateformat");
std::map <std::string, std::string>::iterator i; std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++) for (i = annos.begin (); i != annos.end (); i++)
{ {
Date dt (atoi (i->first.substr (11).c_str ())); Date dt (atoi (i->first.substr (11).c_str ()));
description += " " + dt.toString (format) + " " + i->second; description += " " + dt.toString (_dateformat) + " " + i->second;
} }
} }

View File

@@ -47,6 +47,8 @@ public:
private: private:
bool _hyphenate; bool _hyphenate;
std::string _dateformat;
int _indent;
}; };
#endif #endif

View File

@@ -858,6 +858,9 @@
#define STRING_UTF8_INVALID_CP_REP "Invalid codepoint representation." #define STRING_UTF8_INVALID_CP_REP "Invalid codepoint representation."
#define STRING_UTF8_INVALID_CP "Invalid Unicode codepoint." #define STRING_UTF8_INVALID_CP "Invalid Unicode codepoint."
// View
#define STRING_VIEW_TOO_SMALL "The report has a minimum width of {1} and does not fit in the available width of {2}."
// Usage text. This is an exception, and contains \n characters and formatting. // Usage text. This is an exception, and contains \n characters and formatting.
#define STRING_CMD_HELP_TEXT \ #define STRING_CMD_HELP_TEXT \
"Documentation for Taskwarrior can be found using 'man task', 'man taskrc', 'man " \ "Documentation for Taskwarrior can be found using 'man task', 'man taskrc', 'man " \

View File

@@ -875,6 +875,9 @@
#define STRING_UTF8_INVALID_CP_REP "Representación de codepoint no válida." #define STRING_UTF8_INVALID_CP_REP "Representación de codepoint no válida."
#define STRING_UTF8_INVALID_CP "Codepoint Unicode no válido." #define STRING_UTF8_INVALID_CP "Codepoint Unicode no válido."
// View
#define STRING_VIEW_TOO_SMALL "The report has a minimum width of {1} and does not fit in the available width of {2}."
// **************************************************************************************************** // ****************************************************************************************************
// Usage text. This is an exception, and contains \n characters and formatting. // Usage text. This is an exception, and contains \n characters and formatting.
/* FIXME más abajo /* FIXME más abajo