Example #1
0
////////////////////////////////////////////////////////////////////////////////
// Set the minimum and maximum widths for the value.
void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int& maximum)
{
  std::string description = task.get (_name);

  // The text
  // <indent> <date> <anno>
  // ...
  if (_style == "default" ||
      _style == "combined")
  {
    minimum = longestWord (description);
    maximum = utf8_width (description);

    if (task.annotation_count)
    {
      unsigned int min_anno = _indent + ISO8601d::length (_dateformat);
      if (min_anno > minimum)
        minimum = min_anno;

      std::map <std::string, std::string> annos;
      task.getAnnotations (annos);
      for (auto& i : annos)
      {
        unsigned int len = min_anno + 1 + utf8_width (i.second);
        if (len > maximum)
          maximum = len;
      }
    }
  }

  // Just the text
  else if (_style == "desc")
  {
    maximum = utf8_width (description);
    minimum = longestWord (description);
  }

  // The text <date> <anno> ...
  else if (_style == "oneline")
  {
    minimum = longestWord (description);
    maximum = utf8_width (description);

    if (task.annotation_count)
    {
      auto min_anno = ISO8601d::length (_dateformat);
      std::map <std::string, std::string> annos;
      task.getAnnotations (annos);
      for (auto& i : annos)
        maximum += min_anno + 1 + utf8_width (i.second);
    }
  }

  // The te...
  else if (_style == "truncated")
  {
    minimum = 4;
    maximum = utf8_width (description);
  }

  // The text [2]
  else if (_style == "count")
  {
    // <description> + ' ' + '[' + <count> + ']'
    maximum = utf8_width (description) + 1 + 1 + format (task.annotation_count).length () + 1;
    minimum = longestWord (description);
  }

  // The te... [2]
  else if (_style == "truncated_count")
  {
    minimum = 4;
    maximum = utf8_width (description) + 1 + 1 + format (task.annotation_count).length () + 1;
  }

  else
    throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
}
Example #2
0
std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
{
  std::stringstream before;
  bool verbose = context.verbose ("edit");

  if (verbose)
    before << "# " << STRING_EDIT_HEADER_1 << "\n"
           << "# " << STRING_EDIT_HEADER_2 << "\n"
           << "# " << STRING_EDIT_HEADER_3 << "\n"
           << "# " << STRING_EDIT_HEADER_4 << "\n"
           << "# " << STRING_EDIT_HEADER_5 << "\n"
           << "# " << STRING_EDIT_HEADER_6 << "\n"
           << "#\n"
           << "# " << STRING_EDIT_HEADER_7 << "\n"
           << "# " << STRING_EDIT_HEADER_8 << "\n"
           << "# " << STRING_EDIT_HEADER_9 << "\n"
           << "#\n"
           << "# " << STRING_EDIT_HEADER_10 << "\n"
           << "# " << STRING_EDIT_HEADER_11 << "\n"
           << "# " << STRING_EDIT_HEADER_12 << "\n"
           << "#\n";

  before << "# " << STRING_EDIT_TABLE_HEADER_1 << "\n"
         << "# " << STRING_EDIT_TABLE_HEADER_2 << "\n"
         << "# ID:                " << task.id                                          << "\n"
         << "# UUID:              " << task.get ("uuid")                                << "\n"
         << "# Status:            " << ucFirst (Task::statusToText (task.getStatus ())) << "\n"  // L10N safe ucFirst.
         << "# Mask:              " << task.get ("mask")                                << "\n"
         << "# iMask:             " << task.get ("imask")                               << "\n"
         << "  Project:           " << task.get ("project")                             << "\n";

  std::vector <std::string> tags;
  task.getTags (tags);
  std::string allTags;
  join (allTags, " ", tags);

  if (verbose)
    before << "# " << STRING_EDIT_TAG_SEP << "\n";

  before << "  Tags:              " << allTags                                          << "\n"
         << "  Description:       " << task.get ("description")                         << "\n"
         << "  Created:           " << formatDate (task, "entry", dateformat)           << "\n"
         << "  Started:           " << formatDate (task, "start", dateformat)           << "\n"
         << "  Ended:             " << formatDate (task, "end", dateformat)             << "\n"
         << "  Scheduled:         " << formatDate (task, "scheduled", dateformat)       << "\n"
         << "  Due:               " << formatDate (task, "due", dateformat)             << "\n"
         << "  Until:             " << formatDate (task, "until", dateformat)           << "\n"
         << "  Recur:             " << task.get ("recur")                               << "\n"
         << "  Wait until:        " << formatDate (task, "wait", dateformat)            << "\n"
         << "# Modified:          " << formatDate (task, "modified", dateformat)        << "\n"
         << "  Parent:            " << task.get ("parent")                              << "\n";

  if (verbose)
    before << "# " << STRING_EDIT_HEADER_13 << "\n"
           << "# " << STRING_EDIT_HEADER_14 << "\n"
           << "# " << STRING_EDIT_HEADER_15 << "\n";

  std::map <std::string, std::string> annotations;
  task.getAnnotations (annotations);
  std::map <std::string, std::string>::iterator anno;
  for (anno = annotations.begin (); anno != annotations.end (); ++anno)
  {
    Date dt (strtol (anno->first.substr (11).c_str (), NULL, 10));
    before << "  Annotation:        " << dt.toString (dateformat)
           << " -- "                  << anno->second << "\n";
  }

  Date now;
  before << "  Annotation:        " << now.toString (dateformat) << " -- \n";

  // Add dependencies here.
  std::vector <std::string> dependencies;
  task.getDependencies (dependencies);
  std::stringstream allDeps;
  for (unsigned int i = 0; i < dependencies.size (); ++i)
  {
    if (i)
      allDeps << ",";

    Task t;
    context.tdb2.get (dependencies[i], t);
    if (t.getStatus () == Task::pending ||
        t.getStatus () == Task::waiting)
      allDeps << t.id;
    else
      allDeps << dependencies[i];
  }

  if (verbose)
    before << "# " << STRING_EDIT_DEP_SEP << "\n";

  before << "  Dependencies:      " << allDeps.str () << "\n";

  // UDAs
  std::vector <std::string> udas;
  std::map <std::string, Column*>::iterator col;
  for (col = context.columns.begin (); col != context.columns.end (); ++col)
    if (context.config.get ("uda." + col->first + ".type") != "")
      udas.push_back (col->first);

  if (udas.size ())
  {
    before << "# " << STRING_EDIT_UDA_SEP << "\n";
    std::sort (udas.begin (), udas.end ());
    std::vector <std::string>::iterator uda;
    for (uda = udas.begin (); uda != udas.end (); ++uda)
    {
      int pad = 13 - uda->length ();
      std::string padding = "";
      if (pad > 0)
        padding = std::string (pad, ' ');

      std::string type = context.config.get ("uda." + *uda + ".type");
      if (type == "string" || type == "numeric")    
        before << "  UDA " << *uda << ": " << padding << task.get (*uda) << "\n";
      else if (type == "date")
        before << "  UDA " << *uda << ": " << padding << formatDate (task, *uda, dateformat) << "\n";
      else if (type == "duration")
        before << "  UDA " << *uda << ": " << padding << formatDuration (task, *uda) << "\n";
    }
  }

  // UDA orphans
  std::vector <std::string> orphans;
  task.getUDAOrphans (orphans);

  if (orphans.size ())
  {
    before << "# " << STRING_EDIT_UDA_ORPHAN_SEP << "\n";
    std::sort (orphans.begin (), orphans.end ());
    std::vector <std::string>::iterator orphan;
    for (orphan = orphans.begin (); orphan != orphans.end (); ++orphan)
    {
      int pad = 6 - orphan->length ();
      std::string padding = "";
      if (pad > 0)
        padding = std::string (pad, ' ');

      before << "  UDA Orphan " << *orphan << ": " << padding << task.get (*orphan) << "\n";
    }
  }

  before << "# " << STRING_EDIT_END << "\n";
  return before.str ();
}
Example #3
0
void ColumnDescription::render (
  std::vector <std::string>& lines,
  Task& task,
  int width,
  Color& color)
{
  std::string description = task.get (_name);

  // This is a description
  // <date> <anno>
  // ...
  if (_style == "default" ||
      _style == "combined")
  {
    std::map <std::string, std::string> annos;
    task.getAnnotations (annos);
    if (annos.size ())
    {
      for (auto& i : annos)
      {
        ISO8601d dt (strtol (i.first.substr (11).c_str (), NULL, 10));
        description += "\n" + std::string (_indent, ' ') + dt.toString (_dateformat) + " " + i.second;
      }
    }

    std::vector <std::string> raw;
    wrapText (raw, description, width, _hyphenate);

    for (auto& i : raw)
      lines.push_back (color.colorize (leftJustify (i, width)));
  }

  // This is a description
  else if (_style == "desc")
  {
    std::vector <std::string> raw;
    wrapText (raw, description, width, _hyphenate);

    for (auto& i : raw)
      lines.push_back (color.colorize (leftJustify (i, width)));
  }

  // This is a description <date> <anno> ...
  else if (_style == "oneline")
  {
    std::map <std::string, std::string> annos;
    task.getAnnotations (annos);
    if (annos.size ())
    {
      for (auto& i : annos)
      {
        ISO8601d dt (strtol (i.first.substr (11).c_str (), NULL, 10));
        description += " " + dt.toString (_dateformat) + " " + i.second;
      }
    }

    std::vector <std::string> raw;
    wrapText (raw, description, width, _hyphenate);

    for (auto& i : raw)
      lines.push_back (color.colorize (leftJustify (i, width)));
  }

  // This is a des...
  else if (_style == "truncated")
  {
    int len = utf8_width (description);
    if (len > width)
      lines.push_back (color.colorize (description.substr (0, width - 3) + "..."));
    else
      lines.push_back (color.colorize (leftJustify (description, width)));
  }

  // This is a description [2]
  else if (_style == "count")
  {
    std::map <std::string, std::string> annos;
    task.getAnnotations (annos);

    if (annos.size ())
      description += " [" + format ((int) annos.size ()) + "]";

    std::vector <std::string> raw;
    wrapText (raw, description, width, _hyphenate);

    for (auto& i : raw)
      lines.push_back (color.colorize (leftJustify (i, width)));
  }

  // This is a des... [2]
  else if (_style == "truncated_count")
  {
    std::map <std::string, std::string> annos;
    task.getAnnotations (annos);
    int len = utf8_width (description);
    std::string annos_count;
    int len_annos = 0;

    if (annos.size ())
    {
      annos_count = " [" + format ((int) annos.size ()) + "]";
      len_annos = utf8_width (annos_count);
      len += len_annos;
    }

    if (len > width)
      lines.push_back (color.colorize (description.substr (0, width - len_annos - 3) + "..." + annos_count));
    else
      lines.push_back (color.colorize (leftJustify (description + annos_count, width)));
  }
}
Example #4
0
void ColumnDescription::render (
  std::vector <std::string>& lines,
  Task& task,
  int width,
  Color& color)
{
  std::string description = task.get (_name);

  // This is a description
  // <date> <anno>
  // ...
  if (_style == "default" ||
      _style == "combined")
  {
    std::map <std::string, std::string> annos;
    task.getAnnotations (annos);
    if (annos.size ())
    {
      std::map <std::string, std::string>::iterator i;
      for (i = annos.begin (); i != annos.end (); i++)
      {
        Date dt (strtol (i->first.substr (11).c_str (), NULL, 10));
        description += "\n" + std::string (_indent, ' ') + dt.toString (_dateformat) + " " + i->second;
      }
    }

    std::vector <std::string> raw;
    wrapText (raw, description, width, _hyphenate);

    std::vector <std::string>::iterator i;
    for (i = raw.begin (); i != raw.end (); ++i)
      lines.push_back (color.colorize (leftJustify (*i, width)));
  }

  // This is a description
  else if (_style == "desc")
  {
    std::vector <std::string> raw;
    wrapText (raw, description, width, _hyphenate);

    std::vector <std::string>::iterator i;
    for (i = raw.begin (); i != raw.end (); ++i)
      lines.push_back (color.colorize (leftJustify (*i, width)));
  }

  // This is a description <date> <anno> ...
  else if (_style == "oneline")
  {
    std::map <std::string, std::string> annos;
    task.getAnnotations (annos);
    if (annos.size ())
    {
      std::map <std::string, std::string>::iterator i;
      for (i = annos.begin (); i != annos.end (); i++)
      {
        Date dt (atoi (i->first.substr (11).c_str ()));
        description += " " + dt.toString (_dateformat) + " " + i->second;
      }
    }

    std::vector <std::string> raw;
    wrapText (raw, description, width, _hyphenate);

    std::vector <std::string>::iterator i;
    for (i = raw.begin (); i != raw.end (); ++i)
      lines.push_back (color.colorize (leftJustify (*i, width)));
  }

  // This is a des...
  else if (_style == "truncated")
  {
    int len = utf8_width (description);
    if (len > width)
      lines.push_back (color.colorize (description.substr (0, width - 3) + "..."));
    else
      lines.push_back (color.colorize (leftJustify (description, width)));
  }

  // This is a description [2]
  else if (_style == "count")
  {
    std::map <std::string, std::string> annos;
    task.getAnnotations (annos);

    if (annos.size ())
      description += " [" + format ((int) annos.size ()) + "]";

    std::vector <std::string> raw;
    wrapText (raw, description, width, _hyphenate);

    std::vector <std::string>::iterator i;
    for (i = raw.begin (); i != raw.end (); ++i)
      lines.push_back (color.colorize (leftJustify (*i, width)));
  }
}