Ejemplo n.º 1
0
std::string
Options::help() const
{
  typedef std::vector<std::pair<std::string, std::string>> OptionHelp;

  auto group = m_help.find("");
  if (group == m_help.end())
  {
    return "";
  }

  OptionHelp format;

  size_t longest = 0;

  std::string result;

  for (const auto& o : group->second)
  {
    auto s = format_option(o.s, o.l, o.has_arg);
    longest = std::max(longest, s.size());
    format.push_back(std::make_pair(s, std::string()));
  }

  longest = std::min(longest, static_cast<size_t>(OPTION_LONGEST));

  //widest allowed description
  int allowed = 76 - longest - OPTION_DESC_GAP;

  auto fiter = format.begin();
  for (const auto& o : group->second)
  {
    auto d = format_description(o.desc, longest + OPTION_DESC_GAP, allowed);

    result += fiter->first;
    if (fiter->first.size() > longest)
    {
      result += "\n";
      result += std::string(longest + OPTION_DESC_GAP, ' ');
    }
    else
    {
      result += std::string(longest + OPTION_DESC_GAP - fiter->first.size(),
        ' ');
    }
    result += d;
    result += "\n";

    ++fiter;
  }

  return result;
}
Ejemplo n.º 2
0
void
StartScreenComponent::draw(DrawingContext& gc)
{
  // Paint the background wood panel
  for(int y = 0; y < gc.get_height(); y += background.get_height())
    for(int x = 0; x < gc.get_width(); x += background.get_width())
      gc.draw(background, Vector2i(x, y));

  gc.draw(blackboard, Vector2i(gc.get_width()/2, gc.get_height()/2));

  int left_x  = gc.get_width()/2 - 150;
  int right_x = gc.get_width()/2 + 150;
  int y = gc.get_height()/2 + 40;

  gc.print_center(Fonts::chalk_large,
                  Vector2i(gc.get_width() /2,
                           gc.get_height()/2 - 230),
                  _(plf.get_levelname()));

  gc.print_left(Fonts::chalk_normal,
                Vector2i(gc.get_width() /2 - 300,
                         gc.get_height()/2 - 170),
                format_description(800 - 200));

  y += 32;
  y += 45;

  gc.print_left (Fonts::chalk_normal, Vector2i(left_x,  y), _("Number of Pingus: "));
  gc.print_right(Fonts::chalk_normal, Vector2i(right_x, y), StringUtil::to_string(plf.get_number_of_pingus()));
  
  gc.print_left (Fonts::chalk_normal, Vector2i(left_x,  (y += 30)), _("Number to Save: "));
  gc.print_right(Fonts::chalk_normal, Vector2i(right_x, y), StringUtil::to_string(plf.get_number_to_save()));
  
  gc.print_left (Fonts::chalk_normal, Vector2i(left_x,  (y += 30)), _("Time: "));
  gc.print_right(Fonts::chalk_normal, Vector2i(right_x, y), time_str);

  gc.print_center(Fonts::chalk_small, 
                  Vector2i(gc.get_width()/2,
                           gc.get_height()/2 + 215),
                  _("Author: ") + plf.get_author());

  if (globals::developer_mode)
  {
    gc.print_center(Fonts::chalk_small, Vector2i(gc.get_width()/2, gc.get_height()-50), plf.get_resname());
  }
}
Ejemplo n.º 3
0
void print_list(My402List *list)
{
	print_title();

    My402ListElem * elem = NULL;
    int balance_value = 0, amount_value = 0;
    for (elem = My402ListFirst(list); elem != NULL; elem = My402ListNext(list, elem))
    {
        My402TransData * data = (My402TransData *)(elem -> obj);
        char line[LINE_LENGTH + 1], buffer[26];
        time_t timestamp;
        timestamp = data -> timestamp;
        strncpy(buffer, ctime(&timestamp), sizeof(buffer));
        format_line(line);
        format_time(line, buffer, 2);
        format_description(line, data -> description, 19);
        amount_value = cal_amount(data -> amount, data -> type);
        format_money(line, amount_value, 46, 61);
        balance_value = cal_balance(balance_value, data -> amount, data -> type);
        format_money(line, balance_value, 63, 78);
        fprintf(stdout, "%s\n", line);
    }
    print_line();
}
Ejemplo n.º 4
0
void print_list(My402List *list)
{
	print_title();

    My402ListElem * elem = NULL;
    long long balance_value = 0;
    int amount_value = 0;
    for (elem = My402ListFirst(list); elem != NULL; elem = My402ListNext(list, elem))
    {
        My402TransData * data = (My402TransData *)(elem -> obj);
        char buffer[26], date[16], description[25], amount[15], balance[15];
        time_t timestamp;
        timestamp = data -> timestamp;
        strncpy(buffer, ctime(&timestamp), sizeof(buffer));
        format_time(date, buffer);
        format_description(description, data -> description);
        amount_value = cal_amount(data -> amount, data -> type);
        format_money(amount, amount_value);
        balance_value = cal_balance(balance_value, data -> amount, data -> type);
        format_money(balance, balance_value);
        print_data(date, description, amount, balance);
    }
    print_line();
}
Ejemplo n.º 5
0
public:
    //! Character type
    typedef CharT char_type;
    //! String type
    typedef std::basic_string< char_type > string_type;

    //! Array of format element descriptors
    typedef std::vector< format_element > format_element_list;

    //! Characters of all literal parts of the format string
    string_type literal_chars;
    //! Format element descriptors
    format_element_list format_elements;

    BOOST_DEFAULTED_FUNCTION(format_description(), {})

    format_description(format_description const& that) : literal_chars(that.literal_chars), format_elements(that.format_elements)
    {
    }

    format_description(BOOST_RV_REF(format_description) that)
    {
        literal_chars.swap(that.literal_chars);
        format_elements.swap(that.format_elements);
    }

    format_description& operator= (format_description that)
    {
        literal_chars.swap(that.literal_chars);
        format_elements.swap(that.format_elements);