diff --git a/src/View.cpp b/src/View.cpp index d9aa6c700..14c152bcb 100644 --- a/src/View.cpp +++ b/src/View.cpp @@ -25,8 +25,10 @@ // //////////////////////////////////////////////////////////////////////////////// +#include // TODO Remove #include #include +#include //////////////////////////////////////////////////////////////////////////////// View::View () @@ -164,6 +166,12 @@ std::string View::render (std::vector & data, std::vector & sequence) ideal.push_back (global_ideal); } + std::string combined; + join (combined, ",", minimal); + std::cout << "# minimal " << combined << "\n"; + join (combined, ",", ideal); + std::cout << "# ideal " << combined << "\n"; + // TODO Calculate final column widths. // TODO Compose column headers. diff --git a/src/columns/CMakeLists.txt b/src/columns/CMakeLists.txt index 2bd63b248..21c141fbe 100644 --- a/src/columns/CMakeLists.txt +++ b/src/columns/CMakeLists.txt @@ -5,7 +5,8 @@ include_directories (${CMAKE_SOURCE_DIR}/src ${TASK_INCLUDE_DIRS}) set (columns_SRCS Column.cpp Column.h - ID.cpp ID.h) + ColID.cpp ColID.h + ColProject.cpp ColProject.h) add_library (columns STATIC ${columns_SRCS}) diff --git a/src/columns/ID.cpp b/src/columns/ColID.cpp similarity index 99% rename from src/columns/ID.cpp rename to src/columns/ColID.cpp index 40006ed01..639590326 100644 --- a/src/columns/ID.cpp +++ b/src/columns/ColID.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include extern Context context; diff --git a/src/columns/ID.h b/src/columns/ColID.h similarity index 100% rename from src/columns/ID.h rename to src/columns/ColID.h diff --git a/src/columns/ColProject.cpp b/src/columns/ColProject.cpp new file mode 100644 index 000000000..5c9a22286 --- /dev/null +++ b/src/columns/ColProject.cpp @@ -0,0 +1,85 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +ColumnProject::ColumnProject () +{ + setLabel ("id"); +} + +//////////////////////////////////////////////////////////////////////////////// +ColumnProject::~ColumnProject () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// Set the minimum and maximum widths for the value. +void ColumnProject::measure (Task& task, int& minimum, int& maximum) +{ + std::string project = task.get ("project"); + minimum = maximum = project.length (); + + int longest = 0; + std::string::size_type last = -1; + std::string::size_type space = project.find (' '); + while (space != std::string::npos) + { + if (space - last - 1 > minimum) + longest = space - last - 1; + + last = space; + space = project.find (' ', last + 1); + } + + if (longest) + minimum = longest; +} + +//////////////////////////////////////////////////////////////////////////////// +void ColumnProject::renderHeader (std::vector & lines, int width) +{ + lines.push_back ("ID"); +} + +//////////////////////////////////////////////////////////////////////////////// +void ColumnProject::render (std::vector & lines, Task* task, int width) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +std::string ColumnProject::type () const +{ + return "number"; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColProject.h b/src/columns/ColProject.h new file mode 100644 index 000000000..e1b891b60 --- /dev/null +++ b/src/columns/ColProject.h @@ -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_PROJECT +#define INCLUDED_PROJECT + +#include +#include +#include +#include + +class ColumnProject : public Column +{ +public: + ColumnProject (); + ~ColumnProject (); + + void measure (Task&, int&, int&); + void renderHeader (std::vector &, int); + void render (std::vector &, Task*, int); + std::string type () const; + +private: +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/Column.cpp b/src/columns/Column.cpp index 450fb0e02..b3e6af510 100644 --- a/src/columns/Column.cpp +++ b/src/columns/Column.cpp @@ -28,14 +28,16 @@ #include #include #include -#include +#include +#include extern Context context; //////////////////////////////////////////////////////////////////////////////// Column* Column::factory (const std::string& name) { - if (name == "id") return new ColumnID (); + if (name == "id") return new ColumnID (); + if (name == "project") return new ColumnProject (); throw std::string ("Unrecognized column type '") + name + "'"; return NULL; diff --git a/test/.gitignore b/test/.gitignore index 27743f6fb..53ec7db64 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -36,3 +36,4 @@ tree2.t uri.t util.t variant.t +view.t diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2d7d8fdf6..26daa6061 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,7 @@ set (test_SRCS att.t autocomplete.t cmd.t color.t config.t date.t directory.t dom.t duration.t file.t filt.t grid.t json.t list.t nibbler.t path.t record.t rectangle.t rx.t seq.t subst.t t.benchmark.t t.t taskmod.t tdb.t tdb2.t text.t tree.t tree2.t uri.t util.t - variant.t) + variant.t view.t) add_custom_target (test ./run_all DEPENDS ${test_SRCS} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test) diff --git a/test/view.t.cpp b/test/view.t.cpp new file mode 100644 index 000000000..3b5613b1f --- /dev/null +++ b/test/view.t.cpp @@ -0,0 +1,73 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +#include +#include +#include +#include +#include + +Context context; + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (1); + + try + { + // Two sample tasks. + std::vector data; + data.push_back (Task ("[description:\"Migrate import out of core\" entry:\"1303155011\" project:\"task-2.1\" status:\"pending\" uuid:\"3bb54f40-c38f-4936-aae6-f67de6227e00\"]")); + data.push_back (Task ("[annotation_1303444800:\"Uli Martens\" description:\"New command: task show defaults, that dumps the Config.cpp defaults string, as an example of a complete .taskrc file\" entry:\"1303472714\" project:\"task-2.0\" status:\"pending\" uuid:\"f30cb9c3-3fc0-483f-bfb2-3bf134f00694\"]")); + + // Sequence of tasks. + std::vector sequence; + sequence.push_back (0); + sequence.push_back (1); + + // Create a view. + View view; + view.add (Column::factory ("id")); + view.add (Column::factory ("project")); + view.width (40); + + // Render the view. + std::cout << view.render (data, sequence) + << std::endl; + } + + catch (std::string& e) + { + t.fail ("Exception thrown."); + t.diag (e); + } + + return 0; +} + +////////////////////////////////////////////////////////////////////////////////