Пример #1
0
void display_cursing_board ( void )
{
  int x, y, val;
  chtype ch;

  terminal_max_x = getmaxx (stdscr);    /* (re)initialize term dims */
  terminal_max_y = getmaxy (stdscr);    /* (re)initialize term dims */
  set_display_ends ();
  if (terminal_max_x < endx - begx + 3 + BOARDXOFFSET) {
    cantcontinue("Now need more than %d cols on your terminal.\n", terminal_max_x);
  }
  if (terminal_max_y < endy - begy + 3 + BOARDYOFFSET) {
    cantcontinue("Now need more than %d lines on your terminal.\n", terminal_max_y);
  }
  move (BOARDYOFFSET, BOARDXOFFSET);
  chtype corner = '+' | COLOR_PAIR(COLPAIR4TEXT) | A_BOLD; /*FIXME: compute once */
  chtype top = '-' | COLOR_PAIR(COLPAIR4TEXT) | A_BOLD;
  chtype bot = top;
  if (plane_mode != FULL_PLANE_MODE) {
    bot = '-' | COLOR_PAIR(COLPAIR4TEXT); /* no bold */
  }
  chtype right = '|' | COLOR_PAIR(COLPAIR4TEXT) | A_BOLD;
  chtype left = right;
  if (plane_mode == QUARTER_PLANE_MODE) {
    left = ':' | COLOR_PAIR(COLPAIR4TEXT); /* no bold */
  }
  addch(corner); for (x = begx; x <= endx; x++) addch(top); addch(corner);
  for (y = endy+1; y-- > begy;) { /* downward loop :-( */
    move (BOARDYOFFSET + 1 + endy - y, BOARDXOFFSET);
    addch(left);
    for (x = begx; x <= endx; x++) {
      val = curr_val(x,y);
      ch = char_for_val(val);
      switch (val) {
      case 0: case 1: ch |= COLOR_PAIR(COLPAIR1VAL);break;
      case 2:         ch |= COLOR_PAIR(COLPAIR2VAL);break;
      case 3:         ch |= COLOR_PAIR(COLPAIR3VAL) | A_BOLD;break;
      case 4:         ch |= COLOR_PAIR(COLPAIR4VAL);break;
      default:        ch |= COLOR_PAIR(COLPAIR5VAL);break;
      }
      addch(ch);
    }
    addch(right);
  }
  move (BOARDYOFFSET + 1 + endy - y, BOARDXOFFSET);
  addch(corner);
  for (x = begx; x <= endx; x++)
    if ( (plane_mode == FULL_PLANE_MODE) || ((x-begx)%2 == 0) ) { /* every other one */
      addch(bot);
    } else {
      addch (' ');
    }
  addch(corner);
  refresh ();
}
Пример #2
0
int process_options(generator & gen, int arg_count, char *args[])
{
  std::unordered_map<std::string, process_option_func> options(
  {
    { "template", process_set_template_file }
  });

  for(int arg_it = 1; arg_it < arg_count; ++arg_it)
  {
    std::string curr_arg(args[arg_it]);

    // All options begin with `--`
    if(curr_arg.find("--") != 0)
    {
      // Return index of first non-flag
      return arg_it;
    }
    else
    {
      curr_arg.erase(0, 2);
    }

    // Transform input from `--<arg_name>=<value>` to `--<arg_name>` and `<value>`
    auto arg_value_separator_pos = curr_arg.find('=');
    if(arg_value_separator_pos == std::string::npos
    || arg_value_separator_pos >= curr_arg.size())
    {
      std::cerr << "Malformed option specified: \"" << curr_arg << "\"" << std::endl;
      continue;
    }

    std::string curr_val(curr_arg, arg_value_separator_pos + 1);
    curr_arg.erase(arg_value_separator_pos);

    // Call appropriate handler if one exists
    auto handler_find_it = options.find(curr_arg);
    if(handler_find_it != options.end())
    {
      handler_find_it->second(gen, curr_val);
    }
    else
    {
      std::cerr << "Invalid option specified: \"" << curr_arg << "\"" << std::endl;
    }
  }

  return arg_count;
}