mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +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
|
||||
ColID.cpp ColID.h
|
||||
ColPriority.cpp ColPriority.h
|
||||
ColProject.cpp ColProject.h)
|
||||
|
||||
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
|
||||
|
||||
minimum = maximum = length;
|
||||
|
||||
if (_style != "default")
|
||||
throw std::string ("Unrecognized column format '") + _type + "." + _style + "'";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef INCLUDED_ID
|
||||
#define INCLUDED_ID
|
||||
#ifndef INCLUDED_COLID
|
||||
#define INCLUDED_COLID
|
||||
|
||||
#include <vector>
|
||||
#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)
|
||||
{
|
||||
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;
|
||||
maximum = project.length ();
|
||||
|
||||
|
@ -70,14 +80,20 @@ void ColumnProject::render (
|
|||
int width,
|
||||
Color& color)
|
||||
{
|
||||
// TODO Can't use Nibbler here. Need to use a UTF8-safe version of extractLines.
|
||||
Nibbler nibbler (task.get ("project"));
|
||||
std::string word;
|
||||
while (nibbler.getUntilWS (word))
|
||||
std::string project = task.get ("project");
|
||||
if (_style == "parent")
|
||||
{
|
||||
nibbler.skipWS ();
|
||||
lines.push_back (color.colorize (leftJustify (word, width)));
|
||||
std::string::size_type period = project.find ('.');
|
||||
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
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef INCLUDED_PROJECT
|
||||
#define INCLUDED_PROJECT
|
||||
#ifndef INCLUDED_COLPROJECT
|
||||
#define INCLUDED_COLPROJECT
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
|
|
@ -28,19 +28,34 @@
|
|||
#include <Context.h>
|
||||
#include <Column.h>
|
||||
#include <ColID.h>
|
||||
#include <ColPriority.h>
|
||||
#include <ColProject.h>
|
||||
#include <text.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TODO Supports the new complete column definition:
|
||||
//
|
||||
// <type>[.<format>][.<key>[.<direction>][.<break>]]
|
||||
//
|
||||
Column* Column::factory (const std::string& name)
|
||||
{
|
||||
if (name == "id") return new ColumnID ();
|
||||
if (name == "project") return new ColumnProject ();
|
||||
// TODO Decompose name into type, format, key, direction and break.
|
||||
|
||||
Column* column;
|
||||
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 + "'";
|
||||
return NULL;
|
||||
|
||||
// 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 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; }
|
||||
|
||||
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 renderHeader (std::vector <std::string>&, int, Color&);
|
||||
virtual void render (std::vector <std::string>&, Task&, int, Color&) = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue