mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
View
- Implemented tags.default, tags.indicator, tags.count.
This commit is contained in:
parent
ed7fc44685
commit
8a87db6163
5 changed files with 183 additions and 1 deletions
|
@ -8,6 +8,7 @@ set (columns_SRCS Column.cpp Column.h
|
|||
ColID.cpp ColID.h
|
||||
ColPriority.cpp ColPriority.h
|
||||
ColProject.cpp ColProject.h
|
||||
ColTags.cpp ColTags.h
|
||||
ColUUID.cpp ColUUID.h)
|
||||
|
||||
add_library (columns STATIC ${columns_SRCS})
|
||||
|
|
125
src/columns/ColTags.cpp
Normal file
125
src/columns/ColTags.cpp
Normal file
|
@ -0,0 +1,125 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <algorithm>
|
||||
#include <Context.h>
|
||||
#include <Nibbler.h>
|
||||
#include <ColTags.h>
|
||||
#include <text.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnTags::ColumnTags ()
|
||||
{
|
||||
_type = "string";
|
||||
_style = "default";
|
||||
_label = "Tags";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnTags::~ColumnTags ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Overriden so that style <----> label are linked.
|
||||
// Note that you can not determine which gets called first.
|
||||
void ColumnTags::setStyle (const std::string& value)
|
||||
{
|
||||
_style = value;
|
||||
|
||||
if (_style == "indicator" && _label == "Tags") _label = _label.substr (0, context.config.get ("tag.indicator").length ());
|
||||
else if (_style == "count" && _label == "Tags") _label = "Tag";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Set the minimum and maximum widths for the value.
|
||||
void ColumnTags::measure (Task& task, int& minimum, int& maximum)
|
||||
{
|
||||
|
||||
if (_style == "indicator") minimum = maximum = context.config.get ("tag.indicator").length ();
|
||||
else if (_style == "count") minimum = maximum = 3;
|
||||
else if (_style == "default")
|
||||
{
|
||||
std::string tags = task.get ("tags");
|
||||
minimum = 0;
|
||||
maximum = tags.length ();
|
||||
|
||||
if (maximum)
|
||||
{
|
||||
std::vector <std::string> all;
|
||||
split (all, tags, ',');
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = all.begin (); i != all.end (); ++i)
|
||||
if (i->length () > minimum)
|
||||
minimum = i->length () + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw std::string ("Unrecognized column format '") + _type + "." + _style + "'";
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void ColumnTags::render (
|
||||
std::vector <std::string>& lines,
|
||||
Task& task,
|
||||
int width,
|
||||
Color& color)
|
||||
{
|
||||
std::string tags = task.get ("tags");
|
||||
if (tags != "")
|
||||
{
|
||||
if (_style == "indicator")
|
||||
{
|
||||
lines.push_back (
|
||||
color.colorize (
|
||||
rightJustify (context.config.get ("tag.indicator"), width)));
|
||||
}
|
||||
else if (_style == "count")
|
||||
{
|
||||
std::vector <std::string> all;
|
||||
split (all, tags, ',');
|
||||
lines.push_back (
|
||||
color.colorize (
|
||||
rightJustify ("[" + format ((int)all.size ()) + "]", width)));
|
||||
}
|
||||
else if (_style == "default")
|
||||
{
|
||||
std::replace (tags.begin (), tags.end (), ',', ' ');
|
||||
std::vector <std::string> all;
|
||||
wrapText (all, tags, width);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = all.begin (); i != all.end (); ++i)
|
||||
lines.push_back (color.colorize (rightJustify (*i, width)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
50
src/columns/ColTags.h
Normal file
50
src/columns/ColTags.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef INCLUDED_COLTAGS
|
||||
#define INCLUDED_COLTAGS
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <Column.h>
|
||||
#include <Color.h>
|
||||
#include <Task.h>
|
||||
|
||||
class ColumnTags : public Column
|
||||
{
|
||||
public:
|
||||
ColumnTags ();
|
||||
~ColumnTags ();
|
||||
|
||||
void setStyle (const std::string&);
|
||||
void measure (Task&, int&, int&);
|
||||
void render (std::vector <std::string>&, Task&, int, Color&);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -30,6 +30,7 @@
|
|||
#include <ColID.h>
|
||||
#include <ColPriority.h>
|
||||
#include <ColProject.h>
|
||||
#include <ColTags.h>
|
||||
#include <ColUUID.h>
|
||||
#include <text.h>
|
||||
|
||||
|
@ -61,6 +62,7 @@ Column* Column::factory (const std::string& name)
|
|||
if (column_name == "id") column = new ColumnID ();
|
||||
else if (column_name == "priority") column = new ColumnPriority ();
|
||||
else if (column_name == "project") column = new ColumnProject ();
|
||||
else if (column_name == "tags") column = new ColumnTags ();
|
||||
else if (column_name == "uuid") column = new ColumnUUID ();
|
||||
else
|
||||
throw std::string ("Unrecognized column type '") + column_name + "'";
|
||||
|
|
|
@ -42,9 +42,10 @@ int main (int argc, char** argv)
|
|||
{
|
||||
// Set up configuration.
|
||||
context.config.set ("fontunderline", true);
|
||||
context.config.set ("tag.indicator", "+");
|
||||
|
||||
// Two sample tasks.
|
||||
Task t1 ("[uuid:\"2a64f6e0-bf8e-430d-bf71-9ec3f0d9b661\" project:\"Home\" priority:\"H\"]");
|
||||
Task t1 ("[uuid:\"2a64f6e0-bf8e-430d-bf71-9ec3f0d9b661\" project:\"Home\" priority:\"H\" tags:\"one,two\"]");
|
||||
t1.id = 1;
|
||||
Task t2 ("[uuid:\"f30cb9c3-3fc0-483f-bfb2-3bf134f00694\" project:\"Garden Care\"]");
|
||||
t2.id = 11;
|
||||
|
@ -67,6 +68,9 @@ int main (int argc, char** argv)
|
|||
view.add (Column::factory ("uuid.short"));
|
||||
view.add (Column::factory ("project"));
|
||||
view.add (Column::factory ("priority.long"));
|
||||
view.add (Column::factory ("tags"));
|
||||
view.add (Column::factory ("tags.indicator"));
|
||||
view.add (Column::factory ("tags.count"));
|
||||
view.width (80);
|
||||
view.leftMargin (4);
|
||||
view.extraPadding (0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue