예제 #1
0
파일: misc.cpp 프로젝트: ServerTech/cortex
void read_input(SearchInfo& search_info)
{
    int bytes;
    char input[256] = "", *endc;

    if(input_waiting())
    {
        search_info.stopped = 1;
        do
        {
            bytes = read(fileno(stdin), input, 256);
        } while (bytes < 0);
        endc = strchr(input, '\n');
        if(endc) *endc=0;

        if(strlen(input) > 0)
        {
            if(!strncmp(input, "quit", 4))
            {
                search_info.quit = 1;
            }
        }
        return;
    }
}
예제 #2
0
파일: cmd.c 프로젝트: CaptainHayashi/cuppa
/*
 * Checks to see if there is a command waiting on stdin and, if there is,
 * sends it to the command handler.
 *
 * 'usr' is a pointer to any user data that should be passed to executed
 * commands; 'cmds' is a pointer to an END_CMDS-terminated array of command
 * definitions (see cmd.h for details).
 */
enum error
check_commands(void *usr, const struct cmd *cmds)
{
	enum error	err = E_OK;

	if (input_waiting())
		err = handle_cmd(usr, cmds, stdin, NULL);

	return err;
}
예제 #3
0
파일: util.c 프로젝트: OrangeTide/fed
void alert_box(char *s)        /* alert the user to an error */
{
   char *b;
   int x, y, w;

   w = strlen(s) + 20;
   b = prepare_popup("Error", &x, &y, &w);
   hide_c();
   mywrite(s);
   clear_keybuf();
   while (m_b)
      poll_mouse();
   while ((!input_waiting()) && (!m_b))
      poll_mouse();
   if (input_waiting())
      input_char();
   else
      while (m_b)
	 poll_mouse();
   show_c();
   end_popup(b, &x, &y, &w);
}
예제 #4
0
파일: util.c 프로젝트: OrangeTide/fed
int do_input_text(char *buf, int size, int width, int (*valid)(char), int (*proc)(int, char *, int *, int *), int mouse_flag, int (*mouse_proc)(int x, int y, char *buf, int *oldlen))
{
   KEYPRESS k;
   int key;
   int askey;
   int ret;
   int x, y, len, cpos;
   int oldlen, c;
   int gap;
   int sel = TRUE;

   x = x_pos;
   y = y_pos;
   len = oldlen = cpos = strlen(buf);

   n_vid();

   do {
      goto1(x, y);

      if ((width > 0) && (len > width)) {
	 gap = len - width;

	 pch('.');
	 pch('.');
	 pch('.');
	 pch(' ');

	 mywrite(buf+gap+4);
      }
      else {
	 gap = 0;

	 mywrite(buf);
      }

      hi_vid();

      for (c=len-gap; c < ((width > 0) ? width : oldlen); c++)
	 pch(' ');

      oldlen = len;

      if (cpos-gap > 0)
	 goto2(x+cpos-gap, y);
      else
	 goto2(x, y);

      show_c();

      if (mouse_flag) {
	 display_mouse();
	 while (m_b)
	    poll_mouse();
	 while (TRUE) {
	    if (input_waiting()) {
	       k = input_char();
	       key = k.key;
	       if ((ascii(key) == CR) && (k.flags & KF_CTRL))
		  key = LF;
	       if (key)
		  break;
	    }
	    poll_mouse();
	    if ((m_b) && (mouse_proc)) {
	       hide_c(); 
	       key = (*mouse_proc)(x, y, buf, &oldlen);
	       len = cpos = strlen(buf);
	       sel = FALSE;
	       show_c();
	       if (key > 0)
		  break;
	    }
	 }
	 hide_mouse();
      }
      else {
	 while (m_b)
	    poll_mouse();

	 while ((!input_waiting()) && (!m_b))
	    poll_mouse();

	 if (m_b) {
	    if (m_b & 2)
	       key = ESC;
	    else
	       key = CR;
	 }
	 else {
	    k = input_char();
	    key = k.key;
	    if ((ascii(key) == CR) && (k.flags & KF_CTRL))
	       key = LF;
	 }
      }

      if ((!proc) || (!(*proc)(key, buf, &len, &cpos))) {

	 if ((key==CTRL_G) || (key==CTRL_C))
	    askey=ESC;
	 else
	    askey=ascii((char)key);

	 if ((askey==ESC) || (askey==CR) || (askey==LF)) {
	    ret = askey;
	    break;
	 }

	 if (key==LEFT_ARROW) {
	    if (cpos > 0)
	       cpos--;
	 }
	 else if (key==RIGHT_ARROW) {
	    if (cpos < len)
	       cpos++;
	 }
	 else if (key==K_HOME) {
	    cpos = 0;
	 }
	 else if (key==K_END) {
	    cpos = MAX(len, 0);
	 } 
	 else {
	    if ((sel) && ((key==K_DELETE) || (askey==BACKSPACE) || 
		  ((*valid)(askey)))) {
	       len = cpos = 0;
	       buf[0] = 0;
	    }

	    if (key==K_DELETE) {
	       if (cpos < len) {
		  for (c=cpos; c<len; c++)
		     buf[c] = buf[c+1];
		  len--;
	       }
	    }
	    else if (askey==BACKSPACE) {
	       if (cpos > 0) {
		  cpos--;
		  for (c=cpos; c<len; c++)
		     buf[c] = buf[c+1];
		  len--;
	       }
	    }
	    else {
	       if ((len<size) && ((*valid)(askey))) {
		  len++;
		  for (c=len; c>cpos; c--)
		     buf[c] = buf[c-1];
		  buf[cpos++]=askey;
	       }
	    }
	 }

	 if (proc)
	    (*proc)(-1, buf, &len, &cpos);
      }

      sel = FALSE;

   } while (TRUE);

   n_vid();
   return ret;
}
예제 #5
0
파일: gui.c 프로젝트: OrangeTide/fed
int do_listbox(LISTBOX *l, int *oklist, int *cancellist, int init_key, int instant_mouse)
{
   int key;
   int *pos;
   int done;
   int ret;
   int c;
   char *b = save_screen(l->x, l->y, l->w, l->h);
   int is_key;

   hide_c();
   draw_listbox(l);

   l->key = init_key;
   l->key2 = -1;

   display_mouse();

   while (m_b) {
      poll_mouse();

      if ((instant_mouse) &&
	  ((m_b & 2) ||
	   (mouse_inside_list(l)) ||
	   ((mouse_inside_parent(l)) &&
	    (get_mouse_item(l->parent) != l->parent->current))))
	 break;
   }

   do {
      if (l->key == -1) {
	 while (!input_waiting()) {
	    poll_mouse();
	    if (m_b)
	       break;
	 }
	 if (input_waiting()) {
	    key = input_char().key;
	    is_key = TRUE;
	 }
	 else {
	    int ox, oy, ob; 
	    int sel_item;
	    int first = TRUE;

	    key = 0;
	    is_key = FALSE;

	    while (m_b) {
	       if ((m_b & 2) && (!(l->flags & LISTBOX_USE_RMB))) {
		  key = ESC;
		  is_key = TRUE;
		  break;
	       }

	       sel_item = -1;
	       if (mouse_inside_list(l)) {
		  l->current = get_mouse_item(l);
		  if (l->current >= l->count)
		     l->current = l->count-1;
		  else
		     sel_item = l->current;
	       }

	       hide_mouse();
	       draw_contents(l);
	       display_mouse();

	       if (first) {
		  if (sel_item >= 0) {
		     if (l->flags & LISTBOX_MOUSE_OK) {
			key = CR;
			is_key = TRUE;
			break;
		     }
		     if (!(l->flags & LISTBOX_MOUSE_OK2)) {
			if (!mouse_dclick(FALSE)) {
			   if (mouse_dclick(TRUE)) {
			      key = CR;
			      is_key = TRUE;
			      break;
			   }
			}
		     }
		  }
		  else if (mouse_outside_list(l)) {
		     if (l->flags & LISTBOX_MOUSE_CANCEL) {
			key = ESC;
			is_key = TRUE;
			break;
		     }
		  }

		  first = FALSE;
	       }

	       if (mouse_inside_parent(l)) {
		  if (l->flags & LISTBOX_MOUSE_CANCEL) {
		     key = ESC;
		     is_key = TRUE;
		     break;
		  }
	       }

	       if (l->flags & LISTBOX_SCROLL) {
		  int changed = FALSE;

		  if ((m_y < l->y + l->yoff) && (l->scroll > 0)) {
		     l->scroll--;
		     l->current = l->scroll;
		     m_y = -1;
		     changed = TRUE;
		  }
		  else if ((m_y >= l->y + l->yoff + l->height) &&
			   (l->scroll < l->count - l->height)) {
		     l->scroll++;
		     l->current = l->scroll + l->height - 1;
		     if (l->current >= l->count)
			l->current = l->count-1;
		     m_y = -1;
		     changed = TRUE;
		  }

		  if (changed) {
		     hide_mouse();
		     draw_contents(l);
		     display_mouse();
		     delay(20);
		  }
	       }

	       do {
		  ox = m_x;
		  oy = m_y;
		  ob = m_b;
		  poll_mouse();
	       } while ((m_x == ox) && (m_y == oy) && 
			(m_b == ob) && (m_b) &&
			(!input_waiting()));

	       if ((!m_b) && (sel_item >= 0) &&
		   (l->flags & LISTBOX_MOUSE_OK2)) {
		  key = CR;
		  is_key = TRUE;
		  break;
	       }
	    }
	 }
      }
      else {
	 key = l->key;
	 l->key = l->key2;
	 l->key2 = -1;
	 is_key = TRUE;
      }

      done = FALSE;

      if (is_key) {
	 pos = oklist;
	 while (*pos) {
	    if ((*pos == key) || (ascii(key)==CR) || (ascii(key)==LF)) {
	       if ((l->current >= 0) && (l->current < l->count)) {
		  hide_mouse();
		  if (l->data[l->current].click_proc)
		     ret = (l->data[l->current].click_proc)
			       (l, l->data+l->current);
		  else
		     ret = l->data[l->current].data;
		  if (ret >= 0) {
		     l->key = key;
		     restore_screen(l->x, l->y, l->w, l->h, b);
		     show_c();
		     return ret;
		  }
		  else {
		     hide_c();
		     display_mouse();
		  }
	       }
	       done = TRUE;
	       break;
	    }
	    pos++;
	 }

	 if (!done) {
	    pos = cancellist;
	    while (*pos) {
	       if ((*pos == key) || (ascii(key)==ESC)) {
		  hide_mouse();
		  l->key = key;
		  restore_screen(l->x, l->y, l->w, l->h, b);
		  show_c();
		  return -1;
	       }
	       pos++;
	    }
	 }

	 if (!done) {
	    if (key==LEFT_ARROW)
	       l->current--;
	    else if (key==UP_ARROW)
	       l->current -= l->width;
	    else if (key==RIGHT_ARROW)
	       l->current++;
	    else if (key==DOWN_ARROW)
	       l->current += l->width;
	    else if (key==PAGE_UP)
	       l->current -= l->width * l->height - 1;
	    else if (key==PAGE_DOWN)
	       l->current += l->width * l->height - 1;
	    else if (key==K_HOME)
	       l->current = 0;
	    else if (key==K_END)
	       l->current = l->count-1;
	    else if (l->process_proc)
	       if ((*l->process_proc)(l, key))
		  goto skip;

	    for (c=0; c<l->count; c++)
	       if (tolower(l->data[c].text[0]) == tolower(ascii(key))) {
		  l->current = c;
		  if (l->flags & LISTBOX_FASTKEY)
		     l->key = oklist[0];
		  break;
	       }

	    skip: 
	    if (l->current < 0) {
	       if (l->flags & LISTBOX_WRAP)
		  l->current = MAX(0, l->count-1);
	       else
		  l->current = 0;
	    }
	    else if (l->current >= l->count) {
	       if (l->flags & LISTBOX_WRAP)
		  l->current = 0;
	       else
		  l->current = MAX(0, l->count-1);
	    }

	    while (l->current < l->scroll)
	       l->scroll -= l->width;
	    while (l->current >= l->scroll+l->width*l->height)
	       l->scroll += l->width;
	 } 
      }

      hide_mouse();
      draw_contents(l);
      display_mouse();

   } while (TRUE);
}