static void read_cmd(menu_t* menu,int cmd) {
  switch(cmd) {
  case MENU_CMD_CANCEL:
    if(mpriv->hide_time)
      mpriv->hide_ts = GetTimerMS();
    else
      menu->show = 0;
    mpriv->show_ts = 0;
    return;
  case MENU_CMD_OK: {
    mp_cmd_t* c;
    if(mpriv->child) {
      char *str = mpriv->cur_history->buffer;
      int l = strlen(str);
      while(l > 0) {
	int w = write(mpriv->child_fd[0],str,l);
	if(w < 0) {
	  mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WriteError);
	  break;
	}
	l -= w;
	str += w;
      }
      if(write(mpriv->child_fd[0],"\n",1) < 0)
	mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WriteError);
      enter_cmd(menu);
      return;
    }
    c = mp_input_parse_cmd(mpriv->cur_history->buffer);
    enter_cmd(menu);
    if(!c)
      add_line(mpriv,"Invalid command try help");
    else {
      switch(c->id) {
      case MP_CMD_CHELP:
	add_line(mpriv,"MPlayer console 0.01");
	add_line(mpriv,"TODO: meaningful help message ;)");
	add_line(mpriv,"Enter any slave command");
	add_line(mpriv,"exit close this console");
	break;
      case MP_CMD_CEXIT:
	menu->show = 0;
	menu->cl = 1;
	break;
      case MP_CMD_CHIDE:
	if(mpriv->hide_time)
	  mpriv->hide_ts = GetTimerMS();
	else
	  menu->show = 0;
	mpriv->show_ts = 0;
	break;
      case MP_CMD_RUN:
	run_shell_cmd(menu,c->args[0].v.s);
	break;
      default: // Send the other commands to mplayer
	mp_input_queue_cmd(c);
      }
    }
    return;
  }
  case MENU_CMD_UP:
    if(mpriv->cur_history->prev)
      mpriv->cur_history = mpriv->cur_history->prev;
    break;
  case MENU_CMD_DOWN:
    if(mpriv->cur_history->next)
      mpriv->cur_history = mpriv->cur_history->next;
    break;
  }
}
Exemple #2
0
static void read_key(menu_t* menu,int c) {
  if(!mpriv->child || !mpriv->raw_child) switch(c) {
  case KEY_ESC:
    if(mpriv->hide_time)
      mpriv->hide_ts = GetTimerMS();
    else
      menu->show = 0;
    mpriv->show_ts = 0;
    return;
  case KEY_ENTER: {
    mp_cmd_t* c;
    if(mpriv->child) {
      char *str = mpriv->cur_history->buffer;
      int l = strlen(str);
      while(l > 0) {
	int w = write(mpriv->child_fd[0],str,l);
	if(w < 0) {
	  mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WriteError);
	  break;
	}
	l -= w;
	str += w;
      }
      if(write(mpriv->child_fd[0],"\n",1) < 0)
	mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WriteError);
      enter_cmd(menu);
      return;
    }
    c = mp_input_parse_cmd(mpriv->cur_history->buffer);
    enter_cmd(menu);
    if(!c)
      add_line(mpriv,"Invalid command try help");
    else {
      switch(c->id) {
      case MP_CMD_CHELP:
	add_line(mpriv,"MPlayer console 0.01");
	add_line(mpriv,"TODO: meaningful help message ;)");
	add_line(mpriv,"Enter any slave command");
	add_line(mpriv,"exit close this console");
	break;
      case MP_CMD_CEXIT:
	menu->show = 0;
	menu->cl = 1;
	break;
      case MP_CMD_CHIDE:
	if(mpriv->hide_time)
	  mpriv->hide_ts = GetTimerMS();
	else
	  menu->show = 0;
	mpriv->show_ts = 0;
	break;
      case MP_CMD_RUN:
	run_shell_cmd(menu,c->args[0].v.s);
	break;
      default: // Send the other commands to mplayer
	mp_input_queue_cmd(c);
      }
    }
    return;
  }
  case KEY_DELETE:
  case KEY_BS: {
    unsigned int i = strlen(mpriv->cur_history->buffer);
    if(i > 0)
      mpriv->cur_history->buffer[i-1] = '\0';
    return;
  }
  case KEY_UP:
    if(mpriv->cur_history->prev)
      mpriv->cur_history = mpriv->cur_history->prev;
    break;
  case KEY_DOWN:
    if(mpriv->cur_history->next)
      mpriv->cur_history = mpriv->cur_history->next;
    break;
  }

  if(mpriv->child && mpriv->raw_child) {
    write(mpriv->child_fd[0],&c,sizeof(int));
    return;
  }

  if(isascii(c)) {
    int l = strlen(mpriv->cur_history->buffer);
    if(l >= mpriv->cur_history->size) {
      mpriv->cur_history->size += 255;
      mpriv->cur_history->buffer = realloc(mpriv->cur_history,mpriv->cur_history->size);
    }
    mpriv->cur_history->buffer[l] = (char)c;
    mpriv->cur_history->buffer[l+1] = '\0';
  }

}