mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-04 03:18:33 +02:00
Bug #804 - URL link and break line
- Addressed bug #804 by allowing rc.hyphenate to control whether hyphens are inserted when long lines are broken. This may help prevent xterm from mis-parsing URLs in task annotations, when wrapped (thanks to Yann Davin). - Added unit tests.
This commit is contained in:
parent
08fcb5362e
commit
7dd3e081c7
20 changed files with 147 additions and 28 deletions
|
@ -72,6 +72,7 @@ std::string Config::defaults =
|
|||
"detection=on # Detects terminal width\n"
|
||||
"defaultwidth=80 # Without detection, assumed width\n"
|
||||
"avoidlastcolumn=no # Fixes Cygwin width problem\n"
|
||||
"hyphenate=on # Hyphenates lines wrapped on non-word-breaks\n"
|
||||
"#editor=vi # Preferred text editor\n"
|
||||
"edit.verbose=yes # Include comments in files created during task edit\n"
|
||||
"\n"
|
||||
|
|
|
@ -51,6 +51,8 @@ ColumnDepends::ColumnDepends ()
|
|||
_examples.push_back ("1 2 10");
|
||||
_examples.push_back ("[3]");
|
||||
_examples.push_back (context.config.get ("dependency.indicator"));
|
||||
|
||||
_hyphenate = context.config.getBoolean ("hyphenate");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -150,7 +152,7 @@ void ColumnDepends::render (
|
|||
join (combined, " ", blocking_ids);
|
||||
|
||||
std::vector <std::string> all;
|
||||
wrapText (all, combined, width);
|
||||
wrapText (all, combined, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = all.begin (); i != all.end (); ++i)
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
void render (std::vector <std::string>&, Task&, int, Color&);
|
||||
|
||||
private:
|
||||
bool _hyphenate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -71,6 +71,8 @@ ColumnDescription::ColumnDescription ()
|
|||
+ " " + t + " " + a4);
|
||||
_examples.push_back (d.substr (0, 20) + "...");
|
||||
_examples.push_back (d + " [4]");
|
||||
|
||||
_hyphenate = context.config.getBoolean ("hyphenate");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -199,7 +201,7 @@ void ColumnDescription::render (
|
|||
}
|
||||
|
||||
std::vector <std::string> raw;
|
||||
wrapText (raw, description, width);
|
||||
wrapText (raw, description, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = raw.begin (); i != raw.end (); ++i)
|
||||
|
@ -210,7 +212,7 @@ void ColumnDescription::render (
|
|||
else if (_style == "desc")
|
||||
{
|
||||
std::vector <std::string> raw;
|
||||
wrapText (raw, description, width);
|
||||
wrapText (raw, description, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = raw.begin (); i != raw.end (); ++i)
|
||||
|
@ -237,7 +239,7 @@ void ColumnDescription::render (
|
|||
}
|
||||
|
||||
std::vector <std::string> raw;
|
||||
wrapText (raw, description, width);
|
||||
wrapText (raw, description, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = raw.begin (); i != raw.end (); ++i)
|
||||
|
@ -264,7 +266,7 @@ void ColumnDescription::render (
|
|||
description += " [" + format ((int) annos.size ()) + "]";
|
||||
|
||||
std::vector <std::string> raw;
|
||||
wrapText (raw, description, width);
|
||||
wrapText (raw, description, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = raw.begin (); i != raw.end (); ++i)
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void render (std::vector <std::string>&, Task&, int, Color&);
|
||||
|
||||
private:
|
||||
bool _hyphenate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -47,6 +47,8 @@ ColumnProject::ColumnProject ()
|
|||
|
||||
_examples.push_back (STRING_COLUMN_EXAMPLES_PROJ);
|
||||
_examples.push_back (STRING_COLUMN_EXAMPLES_PAR);
|
||||
|
||||
_hyphenate = context.config.getBoolean ("hyphenate");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -96,7 +98,7 @@ void ColumnProject::render (
|
|||
}
|
||||
|
||||
std::vector <std::string> raw;
|
||||
wrapText (raw, project, width);
|
||||
wrapText (raw, project, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = raw.begin (); i != raw.end (); ++i)
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void render (std::vector <std::string>&, Task&, int, Color&);
|
||||
|
||||
private:
|
||||
bool _hyphenate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -51,6 +51,8 @@ ColumnString::ColumnString ()
|
|||
_styles.push_back (" Hello (wrapped)");
|
||||
_styles.push_back ("Hello (no-wrap) ");
|
||||
_styles.push_back (" Hello (no-wrap)");
|
||||
|
||||
_hyphenate = context.config.getBoolean ("hyphenate");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -96,7 +98,7 @@ void ColumnString::render (
|
|||
if (_style == "default" || _style == "left")
|
||||
{
|
||||
std::vector <std::string> raw;
|
||||
wrapText (raw, value, width);
|
||||
wrapText (raw, value, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = raw.begin (); i != raw.end (); ++i)
|
||||
|
@ -105,7 +107,7 @@ void ColumnString::render (
|
|||
else if (_style == "right")
|
||||
{
|
||||
std::vector <std::string> raw;
|
||||
wrapText (raw, value, width);
|
||||
wrapText (raw, value, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = raw.begin (); i != raw.end (); ++i)
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void render (std::vector <std::string>&, const std::string&, int, Color&);
|
||||
|
||||
private:
|
||||
bool _hyphenate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -50,6 +50,8 @@ ColumnTags::ColumnTags ()
|
|||
_examples.push_back (STRING_COLUMN_EXAMPLES_TAGS);
|
||||
_examples.push_back (context.config.get ("tag.indicator"));
|
||||
_examples.push_back ("[2]");
|
||||
|
||||
_hyphenate = context.config.getBoolean ("hyphenate");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -136,7 +138,7 @@ void ColumnTags::render (
|
|||
{
|
||||
std::replace (tags.begin (), tags.end (), ',', ' ');
|
||||
std::vector <std::string> all;
|
||||
wrapText (all, tags, width);
|
||||
wrapText (all, tags, width, _hyphenate);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = all.begin (); i != all.end (); ++i)
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
void render (std::vector <std::string>&, Task&, int, Color&);
|
||||
|
||||
private:
|
||||
bool _hyphenate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -151,6 +151,7 @@ int CmdShow::execute (std::string& output)
|
|||
" extensions"
|
||||
" fontunderline"
|
||||
" gc"
|
||||
" hyphenate"
|
||||
" import.synonym.bg"
|
||||
" import.synonym.description"
|
||||
" import.synonym.due"
|
||||
|
|
23
src/text.cpp
23
src/text.cpp
|
@ -52,7 +52,8 @@ static void replace_positional (std::string&, const std::string&, const std::str
|
|||
void wrapText (
|
||||
std::vector <std::string>& lines,
|
||||
const std::string& text,
|
||||
const int width)
|
||||
const int width,
|
||||
bool hyphenate)
|
||||
{
|
||||
std::string copy = text;
|
||||
std::string line;
|
||||
|
@ -61,7 +62,7 @@ void wrapText (
|
|||
|
||||
while (copy.length ()) // Used as Boolean, therefore UTF8 safe.
|
||||
{
|
||||
extractLine (copy, line, modified_width);
|
||||
extractLine (copy, line, modified_width, hyphenate);
|
||||
lines.push_back (line);
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +317,11 @@ int longestLine (const std::string& input)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void extractLine (std::string& text, std::string& line, int length)
|
||||
void extractLine (
|
||||
std::string& text,
|
||||
std::string& line,
|
||||
int length,
|
||||
bool hyphenate)
|
||||
{
|
||||
size_t eol = text.find ("\n");
|
||||
|
||||
|
@ -356,8 +361,16 @@ void extractLine (std::string& text, std::string& line, int length)
|
|||
{
|
||||
if (length > 1)
|
||||
{
|
||||
line = text.substr (0, length - 1) + "-";
|
||||
text = text.substr (length - 1);
|
||||
if (hyphenate)
|
||||
{
|
||||
line = text.substr (0, length - 1) + "-";
|
||||
text = text.substr (length - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
line = text.substr (0, length);
|
||||
text = text.substr (length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -33,14 +33,14 @@
|
|||
#include <cmake.h>
|
||||
|
||||
// text.cpp, Non-UTF-8 aware.
|
||||
void wrapText (std::vector <std::string>&, const std::string&, const int);
|
||||
void wrapText (std::vector <std::string>&, const std::string&, const int, bool);
|
||||
std::string trimLeft (const std::string& in, const std::string& t = " ");
|
||||
std::string trimRight (const std::string& in, const std::string& t = " ");
|
||||
std::string trim (const std::string& in, const std::string& t = " ");
|
||||
std::string unquoteText (const std::string&);
|
||||
int longestWord (const std::string&);
|
||||
int longestLine (const std::string&);
|
||||
void extractLine (std::string&, std::string&, int);
|
||||
void extractLine (std::string&, std::string&, int, bool);
|
||||
void splitq (std::vector<std::string>&, const std::string&, const char);
|
||||
void split (std::vector<std::string>&, const std::string&, const char);
|
||||
void split (std::vector<std::string>&, const std::string&, const std::string&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue