mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 10:07:19 +02:00
Columns
- Implemented ColPriority, with 'default' and 'long' formats. - Implemented ColProject 'parent' format.
This commit is contained in:
parent
dd1be996a6
commit
9fd819e3a0
9 changed files with 195 additions and 16 deletions
|
@ -6,6 +6,7 @@ include_directories (${CMAKE_SOURCE_DIR}/src
|
||||||
|
|
||||||
set (columns_SRCS Column.cpp Column.h
|
set (columns_SRCS Column.cpp Column.h
|
||||||
ColID.cpp ColID.h
|
ColID.cpp ColID.h
|
||||||
|
ColPriority.cpp ColPriority.h
|
||||||
ColProject.cpp ColProject.h)
|
ColProject.cpp ColProject.h)
|
||||||
|
|
||||||
add_library (columns STATIC ${columns_SRCS})
|
add_library (columns STATIC ${columns_SRCS})
|
||||||
|
|
|
@ -58,6 +58,9 @@ void ColumnID::measure (Task& task, int& minimum, int& maximum)
|
||||||
else length = (int) log10 ((double) task.id); // Slow
|
else length = (int) log10 ((double) task.id); // Slow
|
||||||
|
|
||||||
minimum = maximum = length;
|
minimum = maximum = length;
|
||||||
|
|
||||||
|
if (_style != "default")
|
||||||
|
throw std::string ("Unrecognized column format '") + _type + "." + _style + "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
// USA
|
// USA
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
#ifndef INCLUDED_ID
|
#ifndef INCLUDED_COLID
|
||||||
#define INCLUDED_ID
|
#define INCLUDED_COLID
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
93
src/columns/ColPriority.cpp
Normal file
93
src/columns/ColPriority.cpp
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 <Context.h>
|
||||||
|
#include <ColPriority.h>
|
||||||
|
#include <text.h>
|
||||||
|
|
||||||
|
extern Context context;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
ColumnPriority::ColumnPriority ()
|
||||||
|
{
|
||||||
|
_type = "string";
|
||||||
|
_style = "default";
|
||||||
|
_label = "Pri";
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
ColumnPriority::~ColumnPriority ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Overriden so that style <----> label are linked.
|
||||||
|
// Note that you can not determine which gets called first.
|
||||||
|
void ColumnPriority::setStyle (const std::string& value)
|
||||||
|
{
|
||||||
|
_style = value;
|
||||||
|
|
||||||
|
if (_style == "long" && _label == "Pri")
|
||||||
|
_label = "Priority";
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Set the minimum and maximum widths for the value.
|
||||||
|
void ColumnPriority::measure (Task& task, int& minimum, int& maximum)
|
||||||
|
{
|
||||||
|
std::string priority = task.get ("priority");
|
||||||
|
|
||||||
|
minimum = maximum = 1;
|
||||||
|
if (_style == "long")
|
||||||
|
{
|
||||||
|
if (priority == "H") minimum = maximum = 4;
|
||||||
|
else if (priority == "M") minimum = maximum = 6;
|
||||||
|
else if (priority == "L") minimum = maximum = 3;
|
||||||
|
}
|
||||||
|
else if (_style != "default")
|
||||||
|
throw std::string ("Unrecognized column format '") + _type + "." + _style + "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void ColumnPriority::render (
|
||||||
|
std::vector <std::string>& lines,
|
||||||
|
Task& task,
|
||||||
|
int width,
|
||||||
|
Color& color)
|
||||||
|
{
|
||||||
|
std::string priority = task.get ("priority");
|
||||||
|
if (_style == "long")
|
||||||
|
{
|
||||||
|
if (priority == "H") priority = "High";
|
||||||
|
else if (priority == "M") priority = "Medium";
|
||||||
|
else if (priority == "L") priority = "Low";
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.push_back (color.colorize (leftJustify (priority, width)));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
50
src/columns/ColPriority.h
Normal file
50
src/columns/ColPriority.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_COLPRIORITY
|
||||||
|
#define INCLUDED_COLPRIORITY
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <Column.h>
|
||||||
|
#include <Color.h>
|
||||||
|
#include <Task.h>
|
||||||
|
|
||||||
|
class ColumnPriority : public Column
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ColumnPriority ();
|
||||||
|
~ColumnPriority ();
|
||||||
|
|
||||||
|
void setStyle (const std::string&);
|
||||||
|
void measure (Task&, int&, int&);
|
||||||
|
void render (std::vector <std::string>&, Task&, int, Color&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
|
@ -50,6 +50,16 @@ ColumnProject::~ColumnProject ()
|
||||||
void ColumnProject::measure (Task& task, int& minimum, int& maximum)
|
void ColumnProject::measure (Task& task, int& minimum, int& maximum)
|
||||||
{
|
{
|
||||||
std::string project = task.get ("project");
|
std::string project = task.get ("project");
|
||||||
|
|
||||||
|
if (_style == "parent")
|
||||||
|
{
|
||||||
|
std::string::size_type period = project.find ('.');
|
||||||
|
if (period != std::string::npos)
|
||||||
|
project = project.substr (0, period);
|
||||||
|
}
|
||||||
|
else if (_style != "default")
|
||||||
|
throw std::string ("Unrecognized column format '") + _type + "." + _style + "'";
|
||||||
|
|
||||||
minimum = 0;
|
minimum = 0;
|
||||||
maximum = project.length ();
|
maximum = project.length ();
|
||||||
|
|
||||||
|
@ -70,14 +80,20 @@ void ColumnProject::render (
|
||||||
int width,
|
int width,
|
||||||
Color& color)
|
Color& color)
|
||||||
{
|
{
|
||||||
// TODO Can't use Nibbler here. Need to use a UTF8-safe version of extractLines.
|
std::string project = task.get ("project");
|
||||||
Nibbler nibbler (task.get ("project"));
|
if (_style == "parent")
|
||||||
std::string word;
|
|
||||||
while (nibbler.getUntilWS (word))
|
|
||||||
{
|
{
|
||||||
nibbler.skipWS ();
|
std::string::size_type period = project.find ('.');
|
||||||
lines.push_back (color.colorize (leftJustify (word, width)));
|
if (period != std::string::npos)
|
||||||
|
project = project.substr (0, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector <std::string> raw;
|
||||||
|
wrapText (raw, project, width);
|
||||||
|
|
||||||
|
std::vector <std::string>::iterator i;
|
||||||
|
for (i = raw.begin (); i != raw.end (); ++i)
|
||||||
|
lines.push_back (color.colorize (leftJustify (*i, width)));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
// USA
|
// USA
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
#ifndef INCLUDED_PROJECT
|
#ifndef INCLUDED_COLPROJECT
|
||||||
#define INCLUDED_PROJECT
|
#define INCLUDED_COLPROJECT
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
|
@ -28,19 +28,34 @@
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Column.h>
|
#include <Column.h>
|
||||||
#include <ColID.h>
|
#include <ColID.h>
|
||||||
|
#include <ColPriority.h>
|
||||||
#include <ColProject.h>
|
#include <ColProject.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TODO Supports the new complete column definition:
|
||||||
|
//
|
||||||
|
// <type>[.<format>][.<key>[.<direction>][.<break>]]
|
||||||
|
//
|
||||||
Column* Column::factory (const std::string& name)
|
Column* Column::factory (const std::string& name)
|
||||||
{
|
{
|
||||||
if (name == "id") return new ColumnID ();
|
// TODO Decompose name into type, format, key, direction and break.
|
||||||
if (name == "project") return new ColumnProject ();
|
|
||||||
|
|
||||||
throw std::string ("Unrecognized column type '") + name + "'";
|
Column* column;
|
||||||
return NULL;
|
if (name == "id") column = new ColumnID ();
|
||||||
|
else if (name == "priority") column = new ColumnPriority ();
|
||||||
|
else if (name == "project") column = new ColumnProject ();
|
||||||
|
else
|
||||||
|
throw std::string ("Unrecognized column type '") + name + "'";
|
||||||
|
|
||||||
|
// TODO Set format.
|
||||||
|
// TODO Set key.
|
||||||
|
// TODO Set direction.
|
||||||
|
// TODO Set break.
|
||||||
|
|
||||||
|
return column;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -45,10 +45,11 @@ public:
|
||||||
|
|
||||||
std::string getStyle () { return _style; }
|
std::string getStyle () { return _style; }
|
||||||
std::string getLabel () { return _label; }
|
std::string getLabel () { return _label; }
|
||||||
void setStyle (const std::string& value) { _style = value; }
|
|
||||||
void setLabel (const std::string& value) { _label = value; }
|
|
||||||
std::string type () const { return _type; }
|
std::string type () const { return _type; }
|
||||||
|
|
||||||
|
virtual void setStyle (const std::string& value) { _style = value; }
|
||||||
|
virtual void setLabel (const std::string& value) { _label = value; }
|
||||||
|
|
||||||
virtual void measure (Task&, int&, int&) = 0;
|
virtual void measure (Task&, int&, int&) = 0;
|
||||||
virtual void renderHeader (std::vector <std::string>&, int, Color&);
|
virtual void renderHeader (std::vector <std::string>&, int, Color&);
|
||||||
virtual void render (std::vector <std::string>&, Task&, int, Color&) = 0;
|
virtual void render (std::vector <std::string>&, Task&, int, Color&) = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue