mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
View
- Implemented uuid.default and uuid.short.
This commit is contained in:
parent
9849b4082d
commit
ed7fc44685
5 changed files with 133 additions and 6 deletions
|
@ -7,7 +7,8 @@ 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)
|
||||
ColProject.cpp ColProject.h
|
||||
ColUUID.cpp ColUUID.h)
|
||||
|
||||
add_library (columns STATIC ${columns_SRCS})
|
||||
|
||||
|
|
74
src/columns/ColUUID.cpp
Normal file
74
src/columns/ColUUID.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <math.h>
|
||||
#include <Context.h>
|
||||
#include <ColUUID.h>
|
||||
#include <text.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnUUID::ColumnUUID ()
|
||||
{
|
||||
_type = "string";
|
||||
_style = "default";
|
||||
_label = "UUID";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnUUID::~ColumnUUID ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Set the minimum and maximum widths for the value.
|
||||
void ColumnUUID::measure (Task& task, int& minimum, int& maximum)
|
||||
{
|
||||
if (_style == "default") minimum = maximum = 36;
|
||||
else if (_style == "short") minimum = maximum = 8;
|
||||
else
|
||||
throw std::string ("Unrecognized column format '") + _type + "." + _style + "'";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void ColumnUUID::render (
|
||||
std::vector <std::string>& lines,
|
||||
Task& task,
|
||||
int width,
|
||||
Color& color)
|
||||
{
|
||||
// f30cb9c3-3fc0-483f-bfb2-3bf134f00694 default
|
||||
// 34f00694 short
|
||||
if (_style == "default")
|
||||
lines.push_back (color.colorize (leftJustify (task.get ("uuid"), width)));
|
||||
|
||||
else if (_style == "short")
|
||||
lines.push_back (color.colorize (leftJustify (task.get ("uuid").substr (28), width)));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
49
src/columns/ColUUID.h
Normal file
49
src/columns/ColUUID.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_COLUUID
|
||||
#define INCLUDED_COLUUID
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <Column.h>
|
||||
#include <Color.h>
|
||||
#include <Task.h>
|
||||
|
||||
class ColumnUUID : public Column
|
||||
{
|
||||
public:
|
||||
ColumnUUID ();
|
||||
~ColumnUUID ();
|
||||
|
||||
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 <ColUUID.h>
|
||||
#include <text.h>
|
||||
|
||||
extern Context context;
|
||||
|
@ -60,6 +61,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 == "uuid") column = new ColumnUUID ();
|
||||
else
|
||||
throw std::string ("Unrecognized column type '") + column_name + "'";
|
||||
|
||||
|
|
|
@ -44,9 +44,9 @@ int main (int argc, char** argv)
|
|||
context.config.set ("fontunderline", true);
|
||||
|
||||
// Two sample tasks.
|
||||
Task t1 ("[project:\"Home\" priority:\"H\"]");
|
||||
Task t1 ("[uuid:\"2a64f6e0-bf8e-430d-bf71-9ec3f0d9b661\" project:\"Home\" priority:\"H\"]");
|
||||
t1.id = 1;
|
||||
Task t2 ("[project:\"Garden Care\"]");
|
||||
Task t2 ("[uuid:\"f30cb9c3-3fc0-483f-bfb2-3bf134f00694\" project:\"Garden Care\"]");
|
||||
t2.id = 11;
|
||||
|
||||
std::vector <Task> data;
|
||||
|
@ -64,9 +64,10 @@ int main (int argc, char** argv)
|
|||
// Create a view.
|
||||
View view;
|
||||
view.add (Column::factory ("id"));
|
||||
view.add (Column::factory ("uuid.short"));
|
||||
view.add (Column::factory ("project"));
|
||||
view.add (Column::factory ("priority"));
|
||||
view.width (20);
|
||||
view.add (Column::factory ("priority.long"));
|
||||
view.width (80);
|
||||
view.leftMargin (4);
|
||||
view.extraPadding (0);
|
||||
view.intraPadding (1);
|
||||
|
@ -75,7 +76,7 @@ int main (int argc, char** argv)
|
|||
// Render the view.
|
||||
std::cout << view.render (data, sequence);
|
||||
|
||||
t.is (view.lines (), 4, "View::lines == 4");
|
||||
t.is (view.lines (), 3, "View::lines == 3");
|
||||
}
|
||||
|
||||
catch (std::string& e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue