当前位置: 首页>>代码示例>>C++>>正文


C++ ViewText::width方法代码示例

本文整理汇总了C++中ViewText::width方法的典型用法代码示例。如果您正苦于以下问题:C++ ViewText::width方法的具体用法?C++ ViewText::width怎么用?C++ ViewText::width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ViewText的用法示例。


在下文中一共展示了ViewText::width方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: execute

int CmdProjects::execute (std::string& output)
{
  int rc = 0;

  // Get all the tasks.
  handleRecurrence ();
  std::vector <Task> tasks = context.tdb2.pending.get_tasks ();

  if (context.config.getBoolean ("list.all.projects"))
  {
    std::vector <Task> extra = context.tdb2.completed.get_tasks ();
    std::vector <Task>::iterator task;
    for (task = extra.begin (); task != extra.end (); ++task)
      tasks.push_back (*task);
  }

  int quantity = tasks.size ();

  context.tdb2.commit ();

  // Apply filter.
  std::vector <Task> filtered;
  filter (tasks, filtered);

  std::stringstream out;

  // Scan all the tasks for their project name, building a map using project
  // names as keys.
  std::map <std::string, int> unique;
  std::map <std::string, int> high;
  std::map <std::string, int> medium;
  std::map <std::string, int> low;
  std::map <std::string, int> none;
  bool no_project = false;
  std::string project;
  std::string priority;
  std::vector <Task>::iterator task;
  for (task = filtered.begin (); task != filtered.end (); ++task)
  {
    project = task->get ("project");
    priority = task->get ("priority");

    unique[project] += 1;
    if (project == "")
      no_project = true;

         if (priority == "H") high[project]   += 1;
    else if (priority == "M") medium[project] += 1;
    else if (priority == "L") low[project]    += 1;
    else                      none[project]   += 1;
  }

  if (unique.size ())
  {
    // Render a list of project names from the map.
    ViewText view;
    view.width (context.getWidth ());
    view.add (Column::factory ("string",       STRING_COLUMN_LABEL_PROJECT));
    view.add (Column::factory ("string.right", STRING_COLUMN_LABEL_TASKS));
    view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_N));
    view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_H));
    view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_M));
    view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_L));

    std::map <std::string, int>::iterator project;
    for (project = unique.begin (); project != unique.end (); ++project)
    {
      int row = view.addRow ();
      view.set (row, 0, (project->first == "" ? STRING_CMD_PROJECTS_NONE : project->first));
      view.set (row, 1, project->second);
      view.set (row, 2, none[project->first]);
      view.set (row, 3, low[project->first]);
      view.set (row, 4, medium[project->first]);
      view.set (row, 5, high[project->first]);
    }

    int number_projects = unique.size ();
    if (no_project)
      --number_projects;

    out << optionalBlankLine ()
        << view.render ()
        << optionalBlankLine ()
        << (number_projects == 1
              ? format (STRING_CMD_PROJECTS_SUMMARY,  number_projects)
              : format (STRING_CMD_PROJECTS_SUMMARY2, number_projects))
        << " "
        << (quantity == 1
              ? format (STRING_CMD_PROJECTS_TASK,  quantity)
              : format (STRING_CMD_PROJECTS_TASKS, quantity))
        << "\n";
  }
  else
  {
    out << STRING_CMD_PROJECTS_NO << "\n";
    rc = 1;
  }

  output = out.str ();
  return rc;
//.........这里部分代码省略.........
开发者ID:zergin,项目名称:task,代码行数:101,代码来源:CmdProjects.cpp

示例2: execute

int CmdStatistics::execute (std::string& output)
{
  int rc = 0;
  std::stringstream out;

  std::string dateformat = context.config.get ("dateformat");

  // Go get the file sizes.
  size_t dataSize = context.tdb2.pending._file.size ()
                  + context.tdb2.completed._file.size ()
                  + context.tdb2.undo._file.size ()
/*
                  // TODO Re-enable this once 2.1 has taskd support.
                  + context.tdb2.backlog._file.size ()
                  + context.tdb2.synch_key._file.size ()
*/
                  ;

  // Count the undo transactions.
  std::vector <std::string> undoTxns = context.tdb2.undo.get_lines ();
  int undoCount = 0;
  std::vector <std::string>::iterator tx;
  for (tx = undoTxns.begin (); tx != undoTxns.end (); ++tx)
    if (*tx == "---")
      ++undoCount;

  // Get all the tasks.
  std::vector <Task> all = context.tdb2.all_tasks ();
  std::vector <Task> filtered;
  filter (all, filtered);

  Date now;
  time_t earliest   = time (NULL);
  time_t latest     = 1;
  int totalT        = 0;
  int deletedT      = 0;
  int pendingT      = 0;
  int completedT    = 0;
  int waitingT      = 0;
  int taggedT       = 0;
  int annotationsT  = 0;
  int recurringT    = 0;
  float daysPending = 0.0;
  int descLength    = 0;
  std::map <std::string, int> allTags;
  std::map <std::string, int> allProjects;

  std::vector <Task>::iterator task;
  for (task = filtered.begin (); task != filtered.end (); ++task)
  {
    ++totalT;

    Task::status status = task->getStatus ();
    switch (status)
    {
    case Task::deleted:   ++deletedT;   break;
    case Task::pending:   ++pendingT;   break;
    case Task::completed: ++completedT; break;
    case Task::recurring: ++recurringT; break;
    case Task::waiting:   ++waitingT;   break;
    }

    time_t entry = strtol (task->get ("entry").c_str (), NULL, 10);
    if (entry < earliest) earliest = entry;
    if (entry > latest)   latest   = entry;

    if (status == Task::completed)
    {
      time_t end = strtol (task->get ("end").c_str (), NULL, 10);
      daysPending += (end - entry) / 86400.0;
    }

    if (status == Task::pending)
      daysPending += (now.toEpoch () - entry) / 86400.0;

    descLength += task->get ("description").length ();

    std::map <std::string, std::string> annotations;
    task->getAnnotations (annotations);
    annotationsT += annotations.size ();

    std::vector <std::string> tags;
    task->getTags (tags);
    if (tags.size ()) ++taggedT;

    std::vector <std::string>::iterator t;
    for (t = tags.begin (); t != tags.end (); ++t)
      allTags[*t] = 0;

    std::string project = task->get ("project");
    if (project != "")
      allProjects[project] = 0;
  }

  // Create a table for output.
  ViewText view;
  view.width (context.getWidth ());
  view.intraPadding (2);
  view.add (Column::factory ("string", STRING_CMD_STATS_CATEGORY));
  view.add (Column::factory ("string", STRING_CMD_STATS_DATA));
//.........这里部分代码省略.........
开发者ID:SEJeff,项目名称:task,代码行数:101,代码来源:CmdStatistics.cpp

示例3: execute

int CmdHistoryMonthly::execute (std::string& output)
{
  int rc = 0;

  std::map <time_t, int> groups;          // Represents any month with data
  std::map <time_t, int> addedGroup;      // Additions by month
  std::map <time_t, int> completedGroup;  // Completions by month
  std::map <time_t, int> deletedGroup;    // Deletions by month

  // Scan the pending tasks.
  handleRecurrence ();
  std::vector <Task> filtered;
  filter (filtered);
  context.tdb2.commit ();

  std::vector <Task>::iterator task;
  for (task = filtered.begin (); task != filtered.end (); ++task)
  {
    Date entry (task->get_date ("entry"));

    Date end;
    if (task->has ("end"))
      end = Date (task->get_date ("end"));

    time_t epoch = entry.startOfMonth ().toEpoch ();
    groups[epoch] = 0;

    // Every task has an entry date.
    ++addedGroup[epoch];

    // All deleted tasks have an end date.
    if (task->getStatus () == Task::deleted)
    {
      epoch = end.startOfMonth ().toEpoch ();
      groups[epoch] = 0;
      ++deletedGroup[epoch];
    }

    // All completed tasks have an end date.
    else if (task->getStatus () == Task::completed)
    {
      epoch = end.startOfMonth ().toEpoch ();
      groups[epoch] = 0;
      ++completedGroup[epoch];
    }
  }

  // Now build the view.
  ViewText view;
  view.width (context.getWidth ());
  view.add (Column::factory ("string",       STRING_CMD_HISTORY_YEAR));
  view.add (Column::factory ("string",       STRING_CMD_HISTORY_MONTH));
  view.add (Column::factory ("string.right", STRING_CMD_HISTORY_ADDED));
  view.add (Column::factory ("string.right", STRING_CMD_HISTORY_COMP));
  view.add (Column::factory ("string.right", STRING_CMD_HISTORY_DEL));
  view.add (Column::factory ("string.right", STRING_CMD_HISTORY_NET));

  int totalAdded     = 0;
  int totalCompleted = 0;
  int totalDeleted   = 0;

  int priorYear = 0;
  int row = 0;
  std::map <time_t, int>::iterator i;
  for (i = groups.begin (); i != groups.end (); ++i)
  {
    row = view.addRow ();

    totalAdded     += addedGroup     [i->first];
    totalCompleted += completedGroup [i->first];
    totalDeleted   += deletedGroup   [i->first];

    Date dt (i->first);
    int m, d, y;
    dt.toMDY (m, d, y);

    if (y != priorYear)
    {
      view.set (row, 0, y);
      priorYear = y;
    }
    view.set (row, 1, Date::monthName(m));

    int net = 0;

    if (addedGroup.find (i->first) != addedGroup.end ())
    {
      view.set (row, 2, addedGroup[i->first]);
      net +=addedGroup[i->first];
    }

    if (completedGroup.find (i->first) != completedGroup.end ())
    {
      view.set (row, 3, completedGroup[i->first]);
      net -= completedGroup[i->first];
    }

    if (deletedGroup.find (i->first) != deletedGroup.end ())
    {
      view.set (row, 4, deletedGroup[i->first]);
//.........这里部分代码省略.........
开发者ID:georgebrock,项目名称:task,代码行数:101,代码来源:CmdHistory.cpp

示例4: execute

int CmdHelp::execute (std::string& output)
{
  ViewText view;
  view.width (context.getWidth ());
  view.add (Column::factory ("string.left", ""));
  view.add (Column::factory ("string.left", ""));
  view.add (Column::factory ("string.left", ""));

  // Static first row.
  int row = view.addRow ();
  view.set (row, 0, STRING_CMD_HELP_USAGE_LABEL);
  view.set (row, 1, "task");
  view.set (row, 2, STRING_CMD_HELP_USAGE_DESC);

  // Obsolete method of getting a list of all commands.
  std::vector <std::string> all;
  std::map <std::string, Command*>::iterator i;
  for (i = context.commands.begin (); i != context.commands.end (); ++i)
    all.push_back (i->first);

  // Sort alphabetically by usage.
  std::sort (all.begin (), all.end ());

  // Add the regular commands.
  std::vector <std::string>::iterator name;
  for (name = all.begin (); name != all.end (); ++name)
  {
    if ((*name)[0] != '_')
    {
      row = view.addRow ();
      view.set (row, 1, context.commands[*name]->usage ());
      view.set (row, 2, context.commands[*name]->description ());
    }
  }

  // Add the helper commands.
  for (name = all.begin (); name != all.end (); ++name)
  {
    if ((*name)[0] == '_')
    {
      row = view.addRow ();
      view.set (row, 1, context.commands[*name]->usage ());
      view.set (row, 2, context.commands[*name]->description ());
    }
  }

  // Add the aliases commands.
  row = view.addRow ();
  view.set (row, 1, " ");

  std::map <std::string, std::string>::iterator alias;
  for (alias =  context.aliases.begin ();
       alias != context.aliases.end ();
       ++alias)
  {
    row = view.addRow ();
    view.set (row, 1, alias->first);
    view.set (row, 2, format (STRING_CMD_HELP_ALIASED, alias->second));
  }

  output = "\n"
         + view.render ()
         + "\n"
         + STRING_CMD_HELP_TEXT;

  return 0;
}
开发者ID:georgebrock,项目名称:task,代码行数:67,代码来源:CmdHelp.cpp

示例5: execute

int CmdColor::execute (std::string& output)
{
  int rc = 0;

#ifdef FEATURE_COLOR
  // Get the non-attribute, non-fancy command line arguments.
  bool legend = false;
  std::vector <std::string> words = context.a3.extract_words ();
  std::vector <std::string>::iterator word;
  for (word = words.begin (); word != words.end (); ++word)
    if (closeEnough ("legend", *word))
      legend = true;

  std::stringstream out;
  if (context.color ())
  {
    // If the description contains 'legend', show all the colors currently in
    // use.
    if (legend)
    {
      out << "\n" << STRING_CMD_COLOR_HERE << "\n";

      ViewText view;
      view.width (context.getWidth ());
      view.add (Column::factory ("string", STRING_CMD_COLOR_COLOR));
      view.add (Column::factory ("string", STRING_CMD_COLOR_DEFINITION));

      Config::const_iterator item;
      for (item = context.config.begin (); item != context.config.end (); ++item)
      {
        // Skip items with 'color' in their name, that are not referring to
        // actual colors.
        if (item->first != "_forcecolor" &&
            item->first != "color"       &&
            item->first.find ("color") == 0)
        {
          Color color (context.config.get (item->first));
          int row = view.addRow ();
          view.set (row, 0, item->first, color);
          view.set (row, 1, item->second, color);
        }
      }

      out << view.render ()
          << "\n";
    }

    // If there is something in the description, then assume that is a color,
    // and display it as a sample.
    else if (words.size ())
    {
      Color one    ("black on bright yellow");
      Color two    ("underline cyan on bright blue");
      Color three  ("color214 on color202");
      Color four   ("rgb150 on rgb020");
      Color five   ("underline grey10 on grey3");
      Color six    ("red on color173");

      std::string swatch;
      for (word = words.begin (); word != words.end (); ++word)
      {
        if (word != words.begin ())
          swatch += " ";

        swatch += *word;
      }

      Color sample (swatch);

      out << "\n"
          << STRING_CMD_COLOR_EXPLANATION                                          << "\n"
          << "\n\n"
          << STRING_CMD_COLOR_16                                                   << "\n"
          << "  " << one.colorize ("task color black on bright yellow")            << "\n"
          << "  " << two.colorize ("task color underline cyan on bright blue")     << "\n"
          << "\n"
          << STRING_CMD_COLOR_256                                                  << "\n"
          << "  " << three.colorize ("task color color214 on color202")            << "\n"
          << "  " << four.colorize ("task color rgb150 on rgb020")                 << "\n"
          << "  " << five.colorize ("task color underline grey10 on grey3")        << "\n"
          << "  " << six.colorize ("task color red on color173")                   << "\n"
          << "\n"
          << STRING_CMD_COLOR_YOURS                                                << "\n\n"
          << "  " << sample.colorize ("task color " + swatch)                      << "\n\n";
    }

    // Show all supported colors.  Possibly show some unsupported ones too.
    else
    {
      out << "\n"
          << STRING_CMD_COLOR_BASIC
          << "\n"
          << " " << Color::colorize (" black ",   "black")
          << " " << Color::colorize (" red ",     "red")
          << " " << Color::colorize (" blue ",    "blue")
          << " " << Color::colorize (" green ",   "green")
          << " " << Color::colorize (" magenta ", "magenta")
          << " " << Color::colorize (" cyan ",    "cyan")
          << " " << Color::colorize (" yellow ",  "yellow")
          << " " << Color::colorize (" white ",   "white")
//.........这里部分代码省略.........
开发者ID:georgebrock,项目名称:task,代码行数:101,代码来源:CmdColor.cpp

示例6: execute

////////////////////////////////////////////////////////////////////////////////
// Project  Remaining  Avg Age  Complete  0%                  100%
// A               12      13d       55%  XXXXXXXXXXXXX-----------
// B              109   3d 12h       10%  XXX---------------------
int CmdSummary::execute (std::string& output)
{
  int rc = 0;

  // Scan the pending tasks.
  handleRecurrence ();

  // Apply filter.
  std::vector <Task> filtered;
  filter (filtered);
  context.tdb2.commit ();

  // Generate unique list of project names from all pending tasks.
  std::map <std::string, bool> allProjects;
  std::vector <Task>::iterator task;
  for (task = filtered.begin (); task != filtered.end (); ++task)
    if (task->getStatus () == Task::pending)
      allProjects[task->get ("project")] = false;

  // Initialize counts, sum.
  std::map <std::string, int> countPending;
  std::map <std::string, int> countCompleted;
  std::map <std::string, double> sumEntry;
  std::map <std::string, int> counter;
  time_t now = time (NULL);

  // Initialize counters.
  std::map <std::string, bool>::iterator project;
  for (project = allProjects.begin (); project != allProjects.end (); ++project)
  {
    countPending   [project->first] = 0;
    countCompleted [project->first] = 0;
    sumEntry       [project->first] = 0.0;
    counter        [project->first] = 0;
  }

  // Count the various tasks.
  for (task = filtered.begin (); task != filtered.end (); ++task)
  {
    std::string project = task->get ("project");
    ++counter[project];

    if (task->getStatus () == Task::pending ||
        task->getStatus () == Task::waiting)
    {
      ++countPending[project];

      time_t entry = strtol (task->get ("entry").c_str (), NULL, 10);
      if (entry)
        sumEntry[project] = sumEntry[project] + (double) (now - entry);
    }

    else if (task->getStatus () == Task::completed)
    {
      ++countCompleted[project];

      time_t entry = strtol (task->get ("entry").c_str (), NULL, 10);
      time_t end   = strtol (task->get ("end").c_str (), NULL, 10);
      if (entry && end)
        sumEntry[project] = sumEntry[project] + (double) (end - entry);
    }
  }

  // Create a table for output.
  ViewText view;
  view.width (context.getWidth ());
  view.add (Column::factory ("string",            STRING_CMD_SUMMARY_PROJECT));
  view.add (Column::factory ("string.right",      STRING_CMD_SUMMARY_REMAINING));
  view.add (Column::factory ("string.right",      STRING_CMD_SUMMARY_AVG_AGE));
  view.add (Column::factory ("string.right",      STRING_CMD_SUMMARY_COMPLETE));
  view.add (Column::factory ("string.left_fixed", "0%                        100%"));

  Color bar_color (context.config.get ("color.summary.bar"));
  Color bg_color  (context.config.get ("color.summary.background"));

  int barWidth = 30;
  std::vector <std::string> processed;
  std::map <std::string, bool>::iterator i;
  for (i = allProjects.begin (); i != allProjects.end (); ++i)
  {
    if (countPending[i->first] > 0)
    {
      const std::vector <std::string> parents = extractParents (i->first);
      std::vector <std::string>::const_iterator parent;
      for (parent = parents.begin (); parent != parents.end (); parent++)
      {
        if (std::find (processed.begin (), processed.end (), *parent)
           == processed.end ())
        {
          int row = view.addRow ();
          view.set (row, 0, indentProject (*parent));
          processed.push_back (*parent);
        }
      }

      int row = view.addRow ();
//.........这里部分代码省略.........
开发者ID:nigeil,项目名称:task,代码行数:101,代码来源:CmdSummary.cpp

示例7: execute

int CmdVersion::execute (std::string& output)
{
  std::stringstream out;

  // Create a table for the disclaimer.
  int width = context.getWidth ();
  ViewText disclaimer;
  disclaimer.width (width);
  disclaimer.add (Column::factory ("string", ""));
  disclaimer.set (disclaimer.addRow (), 0, STRING_CMD_VERSION_MIT);

  // Create a table for the URL.
  ViewText link;
  link.width (width);
  link.add (Column::factory ("string", ""));
  link.set (link.addRow (), 0, STRING_CMD_VERSION_DOCS);

  Color bold ("bold");

  out << "\n"
      << format (STRING_CMD_VERSION_BUILT,
                 (context.color () ? bold.colorize (PACKAGE) : PACKAGE),
                 (context.color () ? bold.colorize (VERSION) : VERSION))

#if defined (DARWIN)
      << "darwin"
#elif defined (SOLARIS)
      << "solaris"
#elif defined (CYGWIN)
      << "cygwin"
#elif defined (HAIKU)
      << "haiku"
#elif defined (OPENBSD)
      << "openbsd"
#elif defined (FREEBSD)
      << "freebsd"
#elif defined (NETBSD)
      << "netbsd"
#elif defined (LINUX)
      << "linux"
#elif defined (KFREEBSD)
      << "gnu-kfreebsd"
#elif defined (GNUHURD)
      << "gnu-hurd"
#else
      << STRING_CMD_VERSION_UNKNOWN
#endif

#if PACKAGE_LANGUAGE != LANGUAGE_ENG_USA
      << " "
      << STRING_LOCALIZATION_DESC
#endif

      << "\n"
      << STRING_CMD_VERSION_COPY
      << "\n"
      << "\n"
      << disclaimer.render ()
      << "\n"
      << link.render ()
      << "\n";

#if PACKAGE_LANGUAGE != LANGUAGE_ENG_USA
  out << STRING_LOCALIZATION_AUTHOR
      << "\n"
      << "\n";
#endif

  output = out.str ();
  return 0;
}
开发者ID:austinwagner,项目名称:task,代码行数:71,代码来源:CmdVersion.cpp

示例8: execute

int CmdTimesheet::execute (std::string& output)
{
  int rc = 0;

  // Scan the pending tasks.
  handleRecurrence ();
  std::vector <Task> all = context.tdb2.all_tasks ();
  context.tdb2.commit ();

  // What day of the week does the user consider the first?
  int weekStart = Date::dayOfWeek (context.config.get ("weekstart"));
  if (weekStart != 0 && weekStart != 1)
    throw std::string (STRING_DATE_BAD_WEEKSTART);

  // Determine the date of the first day of the most recent report.
  Date today;
  Date start;
  start -= (((today.dayOfWeek () - weekStart) + 7) % 7) * 86400;

  // Roll back to midnight.
  start = Date (start.month (), start.day (), start.year ());
  Date end = start + (7 * 86400);

  // Determine how many reports to run.
  int quantity = 1;
  std::vector <std::string> words = context.a3.extract_words ();
  if (words.size () == 1)
    quantity = strtol (words[0].c_str (), NULL, 10);;

  std::stringstream out;
  for (int week = 0; week < quantity; ++week)
  {
    Date endString (end);
    endString -= 86400;

    std::string title = start.toString (context.config.get ("dateformat"))
                        + " - "
                        + endString.toString (context.config.get ("dateformat"));

    Color bold (Color::nocolor, Color::nocolor, false, true, false);
    out << "\n"
        << (context.color () ? bold.colorize (title) : title)
        << "\n";

    // Render the completed table.
    ViewText completed;
    completed.width (context.getWidth ());
    completed.add (Column::factory ("string",       "   "));
    completed.add (Column::factory ("string",       STRING_COLUMN_LABEL_PROJECT));
    completed.add (Column::factory ("string.right", STRING_COLUMN_LABEL_DUE));
    completed.add (Column::factory ("string",       STRING_COLUMN_LABEL_DESC));

    std::vector <Task>::iterator task;
    for (task = all.begin (); task != all.end (); ++task)
    {
      // If task completed within range.
      if (task->getStatus () == Task::completed)
      {
        Date compDate (task->get_date ("end"));
        if (compDate >= start && compDate < end)
        {
          Color c (task->get ("fg") + " " + task->get ("bg"));
          if (context.color ())
            autoColorize (*task, c);

          int row = completed.addRow ();
          std::string format = context.config.get ("dateformat.report");
          if (format == "")
            format = context.config.get ("dateformat");
          completed.set (row, 1, task->get ("project"), c);

          if(task->has ("due"))
          {
            Date dt (task->get_date ("due"));
            completed.set (row, 2, dt.toString (format));
          }

          std::string description = task->get ("description");
          int indent = context.config.getInteger ("indent.annotation");

          std::map <std::string, std::string> annotations;
          task->getAnnotations (annotations);
          std::map <std::string, std::string>::iterator ann;
          for (ann = annotations.begin (); ann != annotations.end (); ++ann)
            description += "\n"
                         + std::string (indent, ' ')
                         + Date (ann->first.substr (11)).toString (context.config.get ("dateformat"))
                         + " "
                         + ann->second;

          completed.set (row, 3, description, c);
        }
      }
    }

    out << "  " << format (STRING_CMD_TIMESHEET_DONE, completed.rows ()) << "\n";

    if (completed.rows ())
      out << completed.render ()
          << "\n";
//.........这里部分代码省略.........
开发者ID:SEJeff,项目名称:task,代码行数:101,代码来源:CmdTimesheet.cpp

示例9: lastChange

void TDB2::show_diff (
  const std::string& current,
  const std::string& prior,
  const std::string& when)
{
  ISO8601d lastChange (strtol (when.c_str (), NULL, 10));

  // Set the colors.
  Color color_red   (context.color () ? context.config.get ("color.undo.before") : "");
  Color color_green (context.color () ? context.config.get ("color.undo.after") : "");

  if (context.config.get ("undo.style") == "side")
  {
    std::cout << "\n"
              << format (STRING_TDB2_LAST_MOD, lastChange.toString ())
              << "\n";

    // Attributes are all there is, so figure the different attribute names
    // between before and after.
    ViewText view;
    view.width (context.getWidth ());
    view.intraPadding (2);
    view.add (Column::factory ("string", ""));
    view.add (Column::factory ("string", STRING_TDB2_UNDO_PRIOR));
    view.add (Column::factory ("string", STRING_TDB2_UNDO_CURRENT));

    Color label (context.config.get ("color.label"));
    view.colorHeader (label);

    Task after (current);

    if (prior != "")
    {
      Task before (prior);

      std::vector <std::string> beforeAtts;
      for (auto& att : before)
        beforeAtts.push_back (att.first);

      std::vector <std::string> afterAtts;
      for (auto& att : after)
        afterAtts.push_back (att.first);

      std::vector <std::string> beforeOnly;
      std::vector <std::string> afterOnly;
      listDiff (beforeAtts, afterAtts, beforeOnly, afterOnly);

      int row;
      for (auto& name : beforeOnly)
      {
        row = view.addRow ();
        view.set (row, 0, name);
        view.set (row, 1, renderAttribute (name, before.get (name)), color_red);
      }

      for (auto& att : before)
      {
        std::string priorValue   = before.get (att.first);
        std::string currentValue = after.get  (att.first);

        if (currentValue != "")
        {
          row = view.addRow ();
          view.set (row, 0, att.first);
          view.set (row, 1, renderAttribute (att.first, priorValue),
                    (priorValue != currentValue ? color_red : Color ()));
          view.set (row, 2, renderAttribute (att.first, currentValue),
                    (priorValue != currentValue ? color_green : Color ()));
        }
      }

      for (auto& name : afterOnly)
      {
        row = view.addRow ();
        view.set (row, 0, name);
        view.set (row, 2, renderAttribute (name, after.get (name)), color_green);
      }
    }
    else
    {
      int row;
      for (auto& att : after)
      {
        row = view.addRow ();
        view.set (row, 0, att.first);
        view.set (row, 2, renderAttribute (att.first, after.get (att.first)), color_green);
      }
    }

    std::cout << "\n"
              << view.render ()
              << "\n";
  }

  // This style looks like this:
  //  --- before    2009-07-04 00:00:25.000000000 +0200
  //  +++ after    2009-07-04 00:00:45.000000000 +0200
  //
  // - name: old           // att deleted
  // + name:
//.........这里部分代码省略.........
开发者ID:austinwagner,项目名称:task,代码行数:101,代码来源:TDB2.cpp

示例10: execute

int CmdCalendar::execute (std::string& output)
{
  int rc = 0;

  // Each month requires 28 text columns width.  See how many will actually
  // fit.  But if a preference is specified, and it fits, use it.
  int width = context.getWidth ();
  int preferredMonthsPerLine = (context.config.getInteger ("monthsperline"));
  int monthsThatFit = width / 26;

  int monthsPerLine = monthsThatFit;
  if (preferredMonthsPerLine != 0 && preferredMonthsPerLine < monthsThatFit)
    monthsPerLine = preferredMonthsPerLine;

  // Load the pending tasks.
  handleRecurrence ();
  std::vector <Task> tasks = context.tdb2.pending.get_tasks ();

  Date today;
  bool getpendingdate = false;
  int monthsToDisplay = 1;
  int mFrom = today.month ();
  int yFrom = today.year ();
  int mTo = mFrom;
  int yTo = yFrom;

  // Defaults.
  monthsToDisplay = monthsPerLine;
  mFrom = today.month ();
  yFrom = today.year ();

  // Set up a vector of commands (1), for autoComplete.
  std::vector <std::string> commandNames;
  commandNames.push_back ("calendar");

  // Set up a vector of keywords, for autoComplete.
  std::vector <std::string> keywordNames;
  keywordNames.push_back ("due");

  // Set up a vector of months, for autoComplete.
  std::vector <std::string> monthNames;
  for (int i = 1; i <= 12; ++i)
    monthNames.push_back (lowerCase (Date::monthName (i)));

  // For autoComplete results.
  std::vector <std::string> matches;

  // Look at all args, regardless of sequence.
  int argMonth = 0;
  int argYear = 0;
  bool argWholeYear = false;

  std::vector <std::string> words = context.cli.getWords ();

  std::vector <std::string>::iterator arg;
  for (arg = words.begin (); arg != words.end (); ++arg)
  {
    // Some version of "calendar".
    if (autoComplete (lowerCase (*arg), commandNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
      continue;

    // "due".
    else if (autoComplete (lowerCase (*arg), keywordNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
      getpendingdate = true;

    // "y".
    else if (lowerCase (*arg) == "y")
      argWholeYear = true;

    // YYYY.
    else if (Lexer::isAllDigits (*arg) && arg->length () == 4)
      argYear = strtol (arg->c_str (), NULL, 10);

    // MM.
    else if (Lexer::isAllDigits (*arg) && arg->length () <= 2)
    {
      argMonth = strtol (arg->c_str (), NULL, 10);
      if (argMonth < 1 || argMonth > 12)
        throw format (STRING_CMD_CAL_BAD_MONTH, *arg);
    }

    // "January" etc.
    else if (autoComplete (lowerCase (*arg), monthNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
    {
      argMonth = Date::monthOfYear (matches[0]);
      if (argMonth == -1)
        throw format (STRING_CMD_CAL_BAD_MONTH, *arg);
    }

    else
      throw format (STRING_CMD_CAL_BAD_ARG, *arg);
  }

  // Supported combinations:
  //
  //   Command line  monthsToDisplay  mFrom  yFrom  getpendingdate
  //   ------------  ---------------  -----  -----  --------------
  //   cal             monthsPerLine  today  today           false
  //   cal y                      12  today  today           false
  //   cal due         monthsPerLine  today  today            true
//.........这里部分代码省略.........
开发者ID:gerarldlee,项目名称:task,代码行数:101,代码来源:CmdCalendar.cpp

示例11: renderMonths

std::string CmdCalendar::renderMonths (
  int firstMonth,
  int firstYear,
  const Date& today,
  std::vector <Task>& all,
  int monthsPerLine)
{
  // What day of the week does the user consider the first?
  int weekStart = Date::dayOfWeek (context.config.get ("weekstart"));
  if (weekStart != 0 && weekStart != 1)
    throw std::string (STRING_CMD_CAL_SUN_MON);

  // Build table for the number of months to be displayed.
  Color label (context.config.get ("color.label"));

  ViewText view;
  view.colorHeader (label);
  view.width (context.getWidth ());
  for (int i = 0 ; i < (monthsPerLine * 8); i += 8)
  {
    if (weekStart == 1)
    {
      view.add (Column::factory ("string.right", "    "));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2)));
    }
    else
    {
      view.add (Column::factory ("string.right", "    "));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2)));
      view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2)));
    }
  }

  // At most, we need 6 rows.
  view.addRow ();
  view.addRow ();
  view.addRow ();
  view.addRow ();
  view.addRow ();
  view.addRow ();

  // Set number of days per month, months to render, and years to render.
  std::vector<int> years;
  std::vector<int> months;
  std::vector<int> daysInMonth;
  int thisYear = firstYear;
  int thisMonth = firstMonth;
  for (int i = 0 ; i < monthsPerLine ; i++)
  {
    if (thisMonth < 13)
    {
      years.push_back (thisYear);
    }
    else
    {
      thisMonth -= 12;
      years.push_back (++thisYear);
    }
    months.push_back (thisMonth);
    daysInMonth.push_back (Date::daysInMonth (thisMonth++, thisYear));
  }

  int row = 0;

  Color color_today      (context.config.get ("color.calendar.today"));
  Color color_due        (context.config.get ("color.calendar.due"));
  Color color_duetoday   (context.config.get ("color.calendar.due.today"));
  Color color_overdue    (context.config.get ("color.calendar.overdue"));
  Color color_weekend    (context.config.get ("color.calendar.weekend"));
  Color color_holiday    (context.config.get ("color.calendar.holiday"));
  Color color_weeknumber (context.config.get ("color.calendar.weeknumber"));

  // Loop through months to be added on this line.
  for (int mpl = 0; mpl < monthsPerLine ; mpl++)
  {
    // Reset row counter for subsequent months
    if (mpl != 0)
      row = 0;

    // Loop through days in month and add to table.
    for (int d = 1; d <= daysInMonth[mpl]; ++d)
    {
      Date temp (months[mpl], d, years[mpl]);
      int dow = temp.dayOfWeek ();
      int woy = temp.weekOfYear (weekStart);

      if (context.config.getBoolean ("displayweeknumber"))
        view.set (row, (8 * mpl), woy, color_weeknumber);

//.........这里部分代码省略.........
开发者ID:gerarldlee,项目名称:task,代码行数:101,代码来源:CmdCalendar.cpp

示例12: execute

int CmdShow::execute (std::string& output)
{
  int rc = 0;
  std::stringstream out;

  // Obtain the arguments from the description.  That way, things like '--'
  // have already been handled.
  std::vector <std::string> words = context.a3.extract_words ();
  if (words.size () > 2)
    throw std::string (STRING_CMD_SHOW_ARGS);

  int width = context.getWidth ();

  // Complain about configuration variables that are not recognized.
  // These are the regular configuration variables.
  // Note that there is a leading and trailing space, to make it easier to
  // search for whole words.
  std::string recognized =
    " abbreviation.minimum"
    " active.indicator"
    " avoidlastcolumn"
    " bulk"
    " burndown.bias"
    " calendar.details"
    " calendar.details.report"
    " calendar.holidays"
    " calendar.legend"
    " calendar.offset"
    " calendar.offset.value"
    " color"
    " color.active"
    " color.alternate"
    " color.blocked"
    " color.burndown.done"
    " color.burndown.pending"
    " color.burndown.started"
    " color.calendar.due"
    " color.calendar.due.today"
    " color.calendar.holiday"
    " color.calendar.overdue"
    " color.calendar.today"
    " color.calendar.weekend"
    " color.calendar.weeknumber"
    " color.completed"
    " color.debug"
    " color.deleted"
    " color.due"
    " color.due.today"
    " color.footnote"
    " color.header"
    " color.history.add"
    " color.history.delete"
    " color.history.done"
    " color.label"
    " color.overdue"
    " color.pri.H"
    " color.pri.L"
    " color.pri.M"
    " color.pri.none"
    " color.recurring"
    " color.summary.background"
    " color.summary.bar"
    " color.sync.added"
    " color.sync.changed"
    " color.sync.rejected"
    " color.tagged"
    " color.undo.after"
    " color.undo.before"
    " column.padding"
    " complete.all.projects"
    " complete.all.tags"
    " confirmation"
    " data.location"
    " dateformat"
    " dateformat.annotation"
    " dateformat.holiday"
    " dateformat.report"
    " debug"
    " default.command"
    " default.due"
    " default.priority"
    " default.project"
    " defaultheight"
    " defaultwidth"
    " dependency.confirmation"
    " dependency.indicator"
    " dependency.reminder"
    " detection"
    " displayweeknumber"
    " dom"
    " due"
    " echo.command"                      // Deprecated 2.0
    " edit.verbose"                      // Deprecated 2.0
    " editor"
    " exit.on.missing.db"
    " expressions"
    " extensions"
    " fontunderline"
    " gc"
    " hyphenate"
//.........这里部分代码省略.........
开发者ID:SEJeff,项目名称:task,代码行数:101,代码来源:CmdShow.cpp

示例13: execute

int CmdReports::execute (std::string& output)
{
  std::vector <std::string> reports;

  // Add custom reports.
  std::vector <std::string> vars;
  context.config.all (vars);

  std::vector <std::string>::iterator i;
  for (i = vars.begin (); i != vars.end (); ++i)
  {
    if (i->substr (0, 7) == "report.")
    {
      std::string report = i->substr (7);
      std::string::size_type columns = report.find (".columns");
      if (columns != std::string::npos)
        reports.push_back (report.substr (0, columns));
    }
  }

  // Add known reports.
  reports.push_back ("burndown.daily");
  reports.push_back ("burndown.monthly");
  reports.push_back ("burndown.weekly");
  reports.push_back ("ghistory.annual");
  reports.push_back ("ghistory.monthly");
  reports.push_back ("history.annual");
  reports.push_back ("history.monthly");
  reports.push_back ("information");
  reports.push_back ("projects");
  reports.push_back ("summary");
  reports.push_back ("tags");

  std::sort (reports.begin (), reports.end ());

  // Compose the output.
  std::stringstream out;
  ViewText view;
  view.width (context.getWidth ());
  view.add (Column::factory ("string", STRING_CMD_REPORTS_REPORT));
  view.add (Column::factory ("string", STRING_CMD_REPORTS_DESC));

  // If an alternating row color is specified, notify the table.
  if (context.color ())
  {
    Color alternate (context.config.get ("color.alternate"));
    view.colorOdd (alternate);
    view.intraColorOdd (alternate);
  }

  std::vector <std::string>::iterator report;
  for (report = reports.begin (); report != reports.end (); ++report)
  {
    int row = view.addRow ();
    view.set (row, 0, *report);
    view.set (row, 1, context.commands[*report]->description ());
  }

  out << optionalBlankLine ()
      << view.render ()
      << optionalBlankLine ()
      << format (STRING_CMD_REPORTS_SUMMARY, reports.size ())
      << "\n";

  output = out.str ();
  return 0;
}
开发者ID:SEJeff,项目名称:task,代码行数:67,代码来源:CmdReports.cpp

示例14: execute

int CmdInfo::execute (std::string& output)
{
  int rc = 0;

  // Apply filter.
  std::vector <Task> filtered;
  filter (filtered);

  if (! filtered.size ())
  {
    context.footnote (STRING_FEEDBACK_NO_MATCH);
    rc = 1;
  }

  // Get the undo data.
  std::vector <std::string> undo;
  if (context.config.getBoolean ("journal.info"))
    undo = context.tdb2.undo.get_lines ();

  // Determine the output date format, which uses a hierarchy of definitions.
  //   rc.dateformat.info
  //   rc.dateformat
  std::string dateformat = context.config.get ("dateformat.info");
  if (dateformat == "")
    dateformat = context.config.get ("dateformat");

  std::string dateformatanno = context.config.get ("dateformat.annotation");
  if (dateformatanno == "")
    dateformatanno = dateformat;

  // Render each task.
  std::stringstream out;
  std::vector <Task>::iterator task;
  for (task = filtered.begin (); task != filtered.end (); ++task)
  {
    ViewText view;
    view.width (context.getWidth ());
    view.add (Column::factory ("string", STRING_COLUMN_LABEL_NAME));
    view.add (Column::factory ("string", STRING_COLUMN_LABEL_VALUE));

    // If an alternating row color is specified, notify the table.
    if (context.color ())
    {
      Color alternate (context.config.get ("color.alternate"));
      view.colorOdd (alternate);
      view.intraColorOdd (alternate);
    }

    Date now;

    // id
    int row = view.addRow ();
    view.set (row, 0, STRING_COLUMN_LABEL_ID);
    view.set (row, 1, (task->id ? format (task->id) : "-"));

    std::string status = ucFirst (Task::statusToText (task->getStatus ()));

    // description
    Color c;
    autoColorize (*task, c);
    std::string description = task->get ("description");
    int indent = context.config.getInteger ("indent.annotation");

    std::map <std::string, std::string> annotations;
    task->getAnnotations (annotations);
    std::map <std::string, std::string>::iterator ann;
    for (ann = annotations.begin (); ann != annotations.end (); ++ann)
      description += "\n"
                   + std::string (indent, ' ')
                   + Date (ann->first.substr (11)).toString (dateformatanno)
                   + " "
                   + ann->second;

    row = view.addRow ();
    view.set (row, 0, STRING_COLUMN_LABEL_DESC);
    view.set (row, 1, description, c);

    // status
    row = view.addRow ();
    view.set (row, 0, STRING_COLUMN_LABEL_STATUS);
    view.set (row, 1, status);

    // project
    if (task->has ("project"))
    {
      row = view.addRow ();
      view.set (row, 0, STRING_COLUMN_LABEL_PROJECT);
      view.set (row, 1, task->get ("project"));
    }

    // priority
    if (task->has ("priority"))
    {
      row = view.addRow ();
      view.set (row, 0, STRING_COLUMN_LABEL_PRIORITY);
      view.set (row, 1, task->get ("priority"));
    }

    // dependencies: blocked
    {
//.........这里部分代码省略.........
开发者ID:codito,项目名称:task,代码行数:101,代码来源:CmdInfo.cpp


注:本文中的ViewText::width方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。