mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Color
- Implemented Color::strip which can remove the color codes from a string.
This commit is contained in:
parent
93cfbf8dd2
commit
6464a2bca5
3 changed files with 33 additions and 1 deletions
|
@ -506,6 +506,32 @@ std::string Color::colorize (const std::string& input)
|
|||
return input;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Remove color codes from a string.
|
||||
std::string Color::strip (const std::string& input)
|
||||
{
|
||||
int length = input.length ();
|
||||
bool inside = false;
|
||||
std::string output;
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
if (inside)
|
||||
{
|
||||
if (input[i] == 'm')
|
||||
inside = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input[i] == 033)
|
||||
inside = true;
|
||||
else
|
||||
output += input[i];
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Color::colorize (const std::string& input, const std::string& spec)
|
||||
{
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
|
||||
std::string colorize (const std::string&);
|
||||
static std::string colorize (const std::string&, const std::string&);
|
||||
static std::string strip (const std::string&);
|
||||
|
||||
bool nontrivial ();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue