Ejemplo n.º 1
0
Archivo: ui.c Proyecto: ab/pwman
void
ui_statusline_ask_char(char *msg, char *c, char* valid)
{
	int x = strlen(msg) + 5;
	char input[STRING_SHORT];

	*c = 0;
	do {
		ui_statusline_clear();
		if(*c != 0){
			ui_statusline_msg("Bad choice, press any key to try again");
			getch();
			ui_statusline_clear();
		}
		ui_statusline_msg(msg);

		echo();
		show_cursor();

		*c = mvwgetch(bottom, 1, x);

		noecho();
		hide_cursor();
		
	} while ( !strchr(valid, *c) );
	
	ui_statusline_clear();
}
Ejemplo n.º 2
0
Archivo: ui.c Proyecto: unixwitch/pwman
int
ui_ask_char(char const *msg, char *valid)
{
int		x = strlen(msg) + 5;
char		c = 0;

	do {
		ui_statusline_clear();
		if (c != 0) {
			ui_statusline_msg("Bad choice, press any key to try again");
			getch();
			ui_statusline_clear();
		}
		ui_statusline_msg(msg);

		echo();
		show_cursor();

		c = mvwgetch(bottom, 0, x);

		noecho();
		hide_cursor();

	} while (!strchr(valid, c));

	ui_statusline_clear();
	return c;
}
Ejemplo n.º 3
0
JSString*
__Window_readLine (JSContext* cx, WINDOW* win, JSBool moveFirst, jsval x, jsval y)
{
    char* string  = (char*) JS_malloc(cx, 16*sizeof(char));
    size_t length = 0;

    JS_BeginRequest(cx);
    JS_EnterLocalRootScope(cx);

    string[0] = (moveFirst
        ? mvwgetch(win, JSVAL_TO_INT(y), JSVAL_TO_INT(x))
        : wgetch(win));
    
    while (string[(++length)-1] != '\n') {
        if ((length+1) % 16) {
            string = (char*) JS_realloc(cx, string, (length+16+1)*sizeof(char));
        }
    
        string[length] = (char) wgetch(win);
    }

    string[length-1] = '\0';
    string = (char*) JS_realloc(cx, string, length*sizeof(char));

    JSString* jsString = JS_NewString(cx, string, strlen(string));

    JS_LeaveLocalRootScope(cx);
    JS_EndRequest(cx);
    return jsString;
}
Ejemplo n.º 4
0
int main(void)
{
  MEVENT event;
  int input;

  if(initscr() == NULL){
    fprintf(stderr, "initscr failure\n");
    exit(EXIT_FAILURE);
  }

  /* ????????????????¦³????????????? */
  cbreak();
  keypad(stdscr, TRUE);

  /* ???¦³???????????????????? */
  mousemask(BUTTON1_PRESSED |        /* ????????? */
	    BUTTON3_PRESSED |        /* ????????? */
	    REPORT_MOUSE_POSITION,   /* ????¦Ì??? */
	    NULL);
  refresh();

  /* 'q'??????????óø¦Ë */
  while((input = mvwgetch(stdscr, 0, 0)) != 'q'){
    /* ????????????¦Î??? */
    if(input == KEY_MOUSE){
      mvprintw(2, 5, "mouse event");
      /* MEVENT????¦³????? */
      if(getmouse(&event) != OK){
	mvprintw(3, 5, "getmouse failure");
	continue;
      }
      /* MEVENT????¦³?x,y,z????? */
      mvprintw(3, 5, "x = %d, y = %d, z = %d", event.x, event.y, event.z);
      /* ????????????"*"?????????????¦Î???????? */
      if(event.bstate == BUTTON1_PRESSED){
	mvprintw(event.y, event.x, "*");
      }
      /* ????????????" "?????????????¦Î???????? */
      else if(event.bstate == BUTTON3_PRESSED){
	mvprintw(event.y, event.x, " ");
      }
      refresh();
    }
    /* ??????????????????? */
    else{
      mvprintw(2, 5, "not mouse event %c", input);
    }
  }

  endwin();
  exit(EXIT_SUCCESS);
}
Ejemplo n.º 5
0
JSBool
Window_getChar (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval)
{
    JSObject* options;

    WINDOW* win = (WINDOW*) JS_GetPrivate(cx, object);

    JS_BeginRequest(cx);
    JS_EnterLocalRootScope(cx);

    if (argc == 0) {
        *rval = INT_TO_JSVAL(wgetch(win));
    }
    else {
        JS_ValueToObject(cx, argv[0], &options);

        if (!options) {
            JS_ReportError(cx, "Options isn't a valid object.");

            JS_LeaveLocalRootScope(cx);
            JS_EndRequest(cx);
            return JS_FALSE;
        }

        jsval x, y;

        JS_GetProperty(cx, options, "x", &x);
        if (JSVAL_IS_VOID(x) || JSVAL_IS_NULL(x)) {
            JS_GetProperty(cx, options, "X", &x);
        }

        JS_GetProperty(cx, options, "y", &y);
        if (JSVAL_IS_VOID(y) || JSVAL_IS_NULL(y)) {
            JS_GetProperty(cx, options, "Y", &y);
        }

        if (!JSVAL_IS_INT(x) || !JSVAL_IS_INT(y)) {
            JS_ReportError(cx, "An option is missing or isn't an int.");

            JS_LeaveLocalRootScope(cx);
            JS_EndRequest(cx);
            return JS_FALSE;
        }

        *rval = INT_TO_JSVAL(mvwgetch(win, JSVAL_TO_INT(y), JSVAL_TO_INT(x)));
    }

    JS_LeaveLocalRootScope(cx);
    JS_EndRequest(cx);

    return JS_TRUE;
}
Ejemplo n.º 6
0
void enter_string(char *title, char *content, int lines, int posy, int posx, char *buf, int length) {
  WINDOW *win = create_dialog_window(title);
  int i;
  int pos = 0;
  int ch = 0;

  //print out the content
  for(i = 0; i < lines; i++) {
    mvwprintw(win, i + 3, 1, "%s", &content[i * CONTENT_WIDTH]);
  }

  // - let the user input a string
  // read a char until we receive a line break 
  while((ch = mvwgetch(win, posy, posx + pos)) && ch != '\n') {
    // prevent a buffer overflow
    if(ch == KEY_BACKSPACE || ch == 127) {
      // delete the character at the current position from the screen and the buffer
      buf[pos] = '\0';
      mvwprintw(win, posy, posx + pos, " ");

      // go 1 back in the buffer but not under 0
      if(pos > 0) {
        pos--;
      }

      // delete the last typed character from the screen and the buffer
      mvwprintw(win, posy, posx + pos, " ");
      buf[pos] = '\0';
    
    // check if it is a letter
    } else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
      // print the character to the screen
      mvwprintw(win, posy, posx + pos, "%c", ch);

      // write the typed key into the buffer
      buf[pos] = ch; 
      // move forward in the buffer but not over the length - 1
      if(pos < length - 1) {
        pos++;
      }
    }
  }

  buf[length - 1] = '\0';
  // delete the dialog
  delwin(win);
}
Ejemplo n.º 7
0
Archivo: nmm.c Proyecto: ryanakca/nmm
/*
 * Announce winner, prompt user to play again, non-zero if user wants
 * to.
 */
int
gameend(const scrgame *sg)
{
  char c;
  if (sg->game->pieces[WHITE] < sg->game->pieces[BLACK]) {
    update_msgbox(sg->msg_w,
		  "Black wins! Play again?");
  } else {
    update_msgbox(sg->msg_w,
		  "White wins! Play again?");
  }
  mvwprintw(sg->score_w, promptrow, 2, "Play again?:     ");
  wrefresh(sg->score_w);
  c = mvwgetch(sg->score_w, promptrow, promptcol);
  c = tolower(c);
  return (c == 'y');
}
Ejemplo n.º 8
0
Archivo: scr.c Proyecto: anylonen/omega
static long input_number (WINDOW * w)
{
  int ch;
  int ypos, xpos;
  int numlen = 0;
  int amount = 0;

  getyx(w, ypos, xpos);

  while (1)
    {
      ch = mvwgetch(w, ypos, xpos);

      if ('\n' == ch || '\r' == ch)
        {
          return amount;
        }
      else if (EOF == ch || ESCAPE == ch)
        {
          return ABORT;
        }
      else if (BACKSPACE == ch || DELETE == ch)
        {
          if (numlen > 0)
            {
              --numlen;
              amount /= 10;
              mvwaddch(w, ypos, --xpos, ' ');
            }
        }
      else if (isdigit(ch) && (numlen < 9))
        {
          ++xpos;
          ++numlen;
          waddch(w, ch);
          amount = 10 * amount + (ch - '0');
        }
      else
        {
          beep();
        }
    }
}
Ejemplo n.º 9
0
char *GetCommandFromKeyboard(WINDOW *win, int y) {
  static char previousLine[MAXKEYLINELENGTH];
  static char line[MAXKEYLINELENGTH];
  int ch;
  int len;
  
  ch=mvwgetch(win, y, strlen(line));
  if (ch==ERR) return NULL;
  
  // Return with string to caller if got ENTER on an
  // non-empty string
  if ((ch==10) && (strlen(line)>0)) {
    strcpy(previousLine, line);
    line[0]=0;
    scroll(win);
    wrefresh(win);
    return previousLine;
  }
  
  // If BACKSPACE and non-empty string, delete & backup cursor
  if ((ch==8) && (strlen(line)>0)) {
    line[strlen(line)-1]=0;
    mvwaddch(win,y,strlen(line),' ');
    wrefresh(win);
    return NULL;
  }

  // If normal key and length<MAX than add keypress to string
  if ((ch>=' ') && (ch<127) && (strlen(line)<MAXKEYLINELENGTH)) {
    len=strlen(line);
    mvwaddch(win,y,len,ch);
    line[len]=ch;
    line[len+1]=0;
  }

  return NULL;  
}
Ejemplo n.º 10
0
/*
 * mvgetch --
 *      Read in a character from stdscr at the given location.
 */
int
mvgetch(int y, int x)
{
	return mvwgetch(stdscr, y, x);
}
Ejemplo n.º 11
0
/* save results */
static void save_results_table(void) {

    int rows,cols,n=40,length,c;
    WINDOW *mywin;
    FILE *outfile;
    DIR *mydir;
    struct dirent *mydirent;
    char fname[n+1];

    rows = (LINES - 3) / 2;
    length = strlen(save_table_str) + n + 2;
    cols = (COLS - length) / 2;

    /* create input window */
    mywin = subwin(stdscr,3,length,rows,cols);
    keypad(mywin,TRUE);
    wattrset(mywin,COLOR_PAIR(BG_PAIR));	/* setup colors */
    wbkgdset(mywin,COLOR_PAIR(BG_PAIR));
    werase(mywin);	/* erase and color window */

    mvwaddstr(mywin,1,1,save_table_str);
    length = strlen(save_table_str) + 1;
    box(mywin,0,0);
    wrefresh(mywin);

    echo();
    mvwgetnstr(mywin,1,length,fname,n);
    noecho();

    /* open current directory */
    mydir = opendir(".");
    if (mydir == NULL ) {
        werase(mywin);
        mvwaddstr(mywin,1,1,opendir_err);
        box(mywin,0,0);
        wrefresh(mywin);
        while ( (c = mvwgetch(mywin,1,strlen(save_file_exists)+1)) ) {
            if(c == 'n' || c == 'N') {
                delwin(mywin);
                return;
            }
        }
    }

    /* check existing files */
    while( (mydirent = readdir(mydir)) != NULL ) {
        if( strcmp(fname,mydirent->d_name) == 0 ) {
            werase(mywin);
            mvwaddstr(mywin,1,1,save_file_exists);
            box(mywin,0,0);
            wrefresh(mywin);
            while ( (c = mvwgetch(mywin,1,strlen(save_file_exists)+1)) ) {
                if(c == 'n' || c == 'N') {
                    delwin(mywin);
                    closedir(mydir);
                    return;
                }
                else if (c == 'y' || c == 'Y')
                    break;
            }
            break;
        }
    }

    closedir(mydir);

    /* open output file */
    errno = 0;
    outfile = fopen(fname,"w");
    if (errno) {
        werase(mywin);
        mvwaddstr(mywin,1,1,save_table_err);
        box(mywin,0,0);
        wrefresh(mywin);
        while( (c = mvwgetch(mywin,1,strlen(save_table_err+1))) ) {
            if( c == 13 ) {
                delwin(mywin);
                return;
            }
        }
    }

    /* write results */
    write_results(outfile);
    fclose(outfile);

    delwin(mywin);
    return;

}
Ejemplo n.º 12
0
void browse(int type, int nc, int nr, void *in)
{
  WINDOW *pdlscr, *wmenu, *wscroll, *warray, *whlab, *wvlab, *wtmp;
  char s[CHBUF],echobuf[CHBUF],line[CHBUF];
  chtype ch;
  int i,j,eps,ioff,joff,iecho;
  int ncols, nrows, mycols;
  extern int colwid, dcols, drows, width[];

  pdlscr = initscr();  /* sets LINES, COLS (which aren't macro constants...) */
  clear();  /* Clear the screen before we start drawing */

  colwid = width[type];
  ncols = (COLS-HLAB)/colwid;
  dcols = MIN(nc,ncols);
  mycols = dcols*colwid;

  nrows = LINES-3;
  drows = MIN(nr,nrows);

  cbreak();
  noecho();
  nonl();
  intrflush(pdlscr,FALSE);
  keypad(pdlscr,TRUE);
  /* Menu bar */
  wmenu  = subwin(pdlscr,1,COLS,0,0);
  wvlab  = subwin(pdlscr,1,mycols,1,HLAB);
  wscroll= subwin(pdlscr,drows,mycols+HLAB,2,0);
  warray = subwin(wscroll,drows,mycols,2,HLAB);
  whlab  = subwin(wscroll,drows,HLAB,2,0);

  keypad(warray,TRUE);
  scrollok(pdlscr,TRUE);
  scrollok(wscroll,TRUE);

  wmenu  = subwin(pdlscr,1,COLS,0,0);

  sprintf(s,"Perldl data browser: type %d, (%d,%d), type q to quit\n",
	  type,nc,nr);
  mvwaddstr(wmenu,0,10,s);
  wrefresh(wmenu);

  for (i=0;i<dcols;i++) {
    update_vlab(wvlab,i,0);
  }
  wrefresh(wvlab);

  for (j=0;j<drows;j++) {
    update_hlab(whlab,j,0);
  }
  wrefresh(whlab);

  for (j=0;j<drows;j++) {
    update_row(warray,j,0,0,type,nc,in);
  }

  i = j = eps = 0;
  ioff = joff = 0;
  while (tolower(ch=mvwgetch(warray,j-joff,(i-ioff)*colwid+
		      MIN(eps,colwid-2))) != 'q') {
    /* #define ECHOCH */
#ifdef ECHOCH
    sprintf(echobuf,"%8o",ch);
    mvwaddstr(wmenu,0,iecho,echobuf);
    iecho = (iecho < 72) ? iecho+8 :0;
    wrefresh(wmenu);
#endif
    switch (ch) {
    case KEY_LEFT:
    case KEY_RIGHT:
    case KEY_UP:
    case KEY_DOWN:
    case '\t':
    case '\015':
      if (eps) {
	line[eps] = '\0';
	set_value(i,j,type,nc,in,line);
      }
      set_cell(warray,i,j,ioff,joff,type,nc,in);
      eps = 0;
      wrefresh(warray);
      break;
    case '\b':
    case KEY_DL:
    case 0177:
      if (eps) {
	eps--;
	mvwaddch(warray,j-joff,(i-ioff)*colwid+MIN(eps,colwid-2),' ');
	wrefresh(warray);
      }
      continue;
    default:
      if (!eps && ch >= 32 && ch <= 127) {
	clear_cell(warray,i-ioff,j-joff);
	wrefresh(warray);
      }
      mvwaddch(warray,j-joff,(i-ioff)*colwid+MIN(eps,colwid-2),ch|A_UNDERLINE);
      line[eps++]=ch;
      continue;
    }

    switch (ch) {
    case KEY_LEFT:
      i = (i<2)?0:i-1;
      if (i-ioff == -1) {
	ioff--;
	wtmp = newwin(1,mycols-colwid,1,HLAB);
	overwrite(wvlab,wtmp);
	mvwin(wtmp,1,HLAB+colwid);
	overwrite(wtmp,wvlab);
	delwin(wtmp);
	update_vlab(wvlab,0,ioff);
	wtmp = newwin(drows,mycols-colwid,2,HLAB);
	overwrite(warray,wtmp);
	mvwin(wtmp,2,HLAB+colwid);
	overwrite(wtmp,warray);
	delwin(wtmp);
	update_col(warray,0,ioff,joff,type,nc,in);
	wrefresh(warray);
	wrefresh(wvlab);
      }
      break;
    case KEY_RIGHT:
    case '\t':
      i = (i>nc-2)?nc-1:i+1;
      if (i-ioff == dcols) {
	ioff++;
	wtmp = newwin(1,mycols-colwid,1,HLAB+colwid);
	overwrite(wvlab,wtmp);
	mvwin(wtmp,1,HLAB);
	overwrite(wtmp,wvlab);
	delwin(wtmp);
	update_vlab(wvlab,dcols-1,ioff);
	wtmp = newwin(drows,mycols-colwid,2,HLAB+colwid);
	overwrite(warray,wtmp);
	mvwin(wtmp,2,HLAB);
	overwrite(wtmp,warray);
	delwin(wtmp);
	update_col(warray,dcols-1,ioff,joff,type,nc,in);
	wrefresh(warray);
	wrefresh(wvlab);
      }
      break;
    case KEY_UP:
      j = (j<2)?0:j-1;
      if (j-joff == -1) {
	joff--;
	wscrl(wscroll,-1);
	wrefresh(wscroll);
	update_hlab(whlab,0,joff);
	wrefresh(whlab);
	update_row(warray,0,ioff,joff,type,nc,in);
	wrefresh(warray);
      }
      break;
    case KEY_DOWN:
    case '\015':
      j = (j>nr-2)?nr-1:j+1;
      if (j-joff == drows) {
	joff++;
	wscrl(wscroll,1);
	wrefresh(wscroll);
	update_hlab(whlab,drows-1,joff);
	wrefresh(whlab);
	update_row(warray,drows-1,ioff,joff,type,nc,in);
	wrefresh(warray);
      }
      break;
    }
  }
  nl();
  echo();
  nocbreak();
  endwin();
}
Ejemplo n.º 13
0
static int
test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
{
    WINDOW *txtbox = 0;
    WINDOW *txtwin = 0;
    FILE *fp;
    int j;
    int txt_x = 0, txt_y = 0;
    int base_y;
    int limit;
    cchar_t ch;
    cchar_t text[MAX_COLS];

    if (argv[level] == 0) {
	beep();
	return FALSE;
    }

    if (level > 1) {
	txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
	box(txtbox, 0, 0);
	wnoutrefresh(txtbox);

	txtwin = derwin(txtbox,
			getmaxy(txtbox) - 2,
			getmaxx(txtbox) - 2,
			1, 1);
	base_y = 0;
    } else {
	txtwin = stdscr;
	base_y = BASE_Y;
    }

    keypad(txtwin, TRUE);	/* enable keyboard mapping */
    (void) cbreak();		/* take input chars one at a time, no wait for \n */
    (void) noecho();		/* don't echo input */

    txt_y = base_y;
    txt_x = 0;
    wmove(txtwin, txt_y, txt_x);

    if ((fp = fopen(argv[level], "r")) != 0) {
	while ((j = fgetc(fp)) != EOF) {
	    if (waddch(txtwin, UChar(j)) != OK) {
		break;
	    }
	}
	fclose(fp);
    } else {
	wprintw(txtwin, "Cannot open:\n%s", argv[1]);
    }

    while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) {
	switch (j) {
	case KEY_DOWN:
	case 'j':
	    if (txt_y < getmaxy(txtwin) - 1)
		txt_y++;
	    else
		beep();
	    break;
	case KEY_UP:
	case 'k':
	    if (txt_y > base_y)
		txt_y--;
	    else
		beep();
	    break;
	case KEY_LEFT:
	case 'h':
	    if (txt_x > 0)
		txt_x--;
	    else
		beep();
	    break;
	case KEY_RIGHT:
	case 'l':
	    if (txt_x < getmaxx(txtwin) - 1)
		txt_x++;
	    else
		beep();
	    break;
	case 'w':
	    test_inchs(level + 1, argv, chrwin, strwin);
	    if (txtbox != 0) {
		touchwin(txtbox);
		wnoutrefresh(txtbox);
	    } else {
		touchwin(txtwin);
		wnoutrefresh(txtwin);
	    }
	    break;
	default:
	    beep();
	    break;
	}

	MvWPrintw(chrwin, 0, 0, "char:");
	wclrtoeol(chrwin);

	if (txtwin != stdscr) {
	    wmove(txtwin, txt_y, txt_x);
	    if (win_wch(txtwin, &ch) != ERR) {
		if (wadd_wch(chrwin, &ch) != ERR) {
		    for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
			if (mvwin_wch(txtwin, txt_y, j, &ch) != ERR) {
			    if (wadd_wch(chrwin, &ch) == ERR) {
				break;
			    }
			} else {
			    break;
			}
		    }
		}
	    }
	} else {
	    move(txt_y, txt_x);
	    if (in_wch(&ch) != ERR) {
		if (wadd_wch(chrwin, &ch) != ERR) {
		    for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
			if (mvin_wch(txt_y, j, &ch) != ERR) {
			    if (wadd_wch(chrwin, &ch) == ERR) {
				break;
			    }
			} else {
			    break;
			}
		    }
		}
	    }
	}
	wnoutrefresh(chrwin);

	MvWPrintw(strwin, 0, 0, "text:");
	wclrtobot(strwin);

	limit = getmaxx(strwin) - 5;

	if (txtwin != stdscr) {
	    wmove(txtwin, txt_y, txt_x);
	    if (win_wchstr(txtwin, text) != ERR) {
		(void) mvwadd_wchstr(strwin, 0, 5, text);
	    }

	    wmove(txtwin, txt_y, txt_x);
	    if (win_wchnstr(txtwin, text, limit) != ERR) {
		(void) mvwadd_wchstr(strwin, 1, 5, text);
	    }

	    if (mvwin_wchstr(txtwin, txt_y, txt_x, text) != ERR) {
		(void) mvwadd_wchstr(strwin, 2, 5, text);
	    }

	    if (mvwin_wchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) {
		(void) mvwadd_wchstr(strwin, 3, 5, text);
	    }
	} else {
	    move(txt_y, txt_x);
	    if (in_wchstr(text) != ERR) {
		(void) mvwadd_wchstr(strwin, 0, 5, text);
	    }

	    move(txt_y, txt_x);
	    if (in_wchnstr(text, limit) != ERR) {
		(void) mvwadd_wchstr(strwin, 1, 5, text);
	    }

	    if (mvin_wchstr(txt_y, txt_x, text) != ERR) {
		(void) mvwadd_wchstr(strwin, 2, 5, text);
	    }

	    if (mvin_wchnstr(txt_y, txt_x, text, limit) != ERR) {
		(void) mvwadd_wchstr(strwin, 3, 5, text);
	    }
	}

	wnoutrefresh(strwin);
    }
    if (level > 1) {
	delwin(txtwin);
	delwin(txtbox);
    }
    return TRUE;
}
Ejemplo n.º 14
0
static int
test_opaque(int level, char **argv, WINDOW *stswin)
{
    WINDOW *txtbox = 0;
    WINDOW *txtwin = 0;
    FILE *fp;
    int ch;
    int txt_x = 0, txt_y = 0;
    int base_y;
    bool in_status = FALSE;
    int active = 0;

    if (argv[level] == 0) {
	beep();
	return FALSE;
    }

    if (level > 1) {
	txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
	box(txtbox, 0, 0);
	wnoutrefresh(txtbox);

	txtwin = derwin(txtbox,
			getmaxy(txtbox) - 2,
			getmaxx(txtbox) - 2,
			1, 1);
	base_y = 0;
    } else {
	txtwin = stdscr;
	base_y = BASE_Y;
    }

    keypad(txtwin, TRUE);	/* enable keyboard mapping */
    (void) cbreak();		/* take input chars one at a time, no wait for \n */
    (void) noecho();		/* don't echo input */

    txt_y = base_y;
    txt_x = 0;
    wmove(txtwin, txt_y, txt_x);

    if ((fp = fopen(argv[level], "r")) != 0) {
	while ((ch = fgetc(fp)) != EOF) {
	    if (waddch(txtwin, UChar(ch)) != OK) {
		break;
	    }
	}
	fclose(fp);
    } else {
	wprintw(txtwin, "Cannot open:\n%s", argv[1]);
    }

    for (;;) {
	if (in_status) {
	    to_keyword(stswin, active);

	    ch = wgetch(stswin);
	    show_opaque(stswin, txtwin, TRUE, active);
	    if (Quit(ch))
		break;

	    switch (ch) {
	    case '\t':
		in_status = FALSE;
		break;
	    case KEY_DOWN:
	    case 'j':
		if (active < (int) SIZEOF(bool_funcs) - 1)
		    active++;
		else
		    beep();
		break;
	    case KEY_UP:
	    case 'k':
		if (active > 0)
		    active--;
		else
		    beep();
		break;
	    case ' ':
		bool_funcs[active].func(txtwin,
					!bool_funcs[active].func(txtwin, -1));
		break;
	    default:
		beep();
		break;
	    }
	    show_opaque(stswin, txtwin, FALSE, in_status ? active : -1);
	} else {
	    ch = mvwgetch(txtwin, txt_y, txt_x);
	    show_opaque(stswin, txtwin, TRUE, -1);
	    if (Quit(ch))
		break;

	    switch (ch) {
	    case '\t':
		in_status = TRUE;
		break;
	    case KEY_DOWN:
	    case 'j':
		if (txt_y < getmaxy(txtwin) - 1)
		    txt_y++;
		else
		    beep();
		break;
	    case KEY_UP:
	    case 'k':
		if (txt_y > base_y)
		    txt_y--;
		else
		    beep();
		break;
	    case KEY_LEFT:
	    case 'h':
		if (txt_x > 0)
		    txt_x--;
		else
		    beep();
		break;
	    case KEY_RIGHT:
	    case 'l':
		if (txt_x < getmaxx(txtwin) - 1)
		    txt_x++;
		else
		    beep();
		break;
	    case 'w':
		test_opaque(level + 1, argv, stswin);
		if (txtbox != 0) {
		    touchwin(txtbox);
		    wnoutrefresh(txtbox);
		} else {
		    touchwin(txtwin);
		    wnoutrefresh(txtwin);
		}
		break;
	    default:
		beep();
		napms(100);
		break;
	    }

	    show_opaque(stswin, txtwin, FALSE, -1);
	}
    }
    if (level > 1) {
	delwin(txtwin);
	delwin(txtbox);
    }
    return TRUE;
}
Ejemplo n.º 15
0
EIF_INTEGER c_ecurses_mvwgetch (EIF_POINTER w, EIF_INTEGER y, EIF_INTEGER x)
{
    return mvwgetch( ((WINDOW *) w) , (int) y, (int) x) ;
};
Ejemplo n.º 16
0
Archivo: nmm.c Proyecto: ryanakca/nmm
/*
 * Prompt user for input, handling backspace, return.
 * q twice at start of line: quit()
 * ? at start of line: printinstrs()
 * Otherwise, read up to length characters from sg->scorer_w into inp
 * Assume than inp always has room for at least '\0'
 * Recurse until no errors, return pointer to inp.
 */
char *
getinput(scrgame *sg, char *inp, const int length)
{
  int l, ch, i, quitc;
  quitc = 0;
  /* Clear the prompt area */
  mvwaddstr(sg->score_w, promptrow, promptcol, "          |");
  wrefresh(sg->score_w);
  for (l = 0; l < length - 1; l++) {
    ch = mvwgetch(sg->score_w, promptrow, promptcol + l);
    if (ch == 12) {
      /* We were given a ^L */
      full_redraw(sg);
      update_msgbox(sg->msg_w, "");
      for (i = 0; i < l; i++) {
	mvwaddch(sg->score_w, promptrow, promptcol + i, inp[i]);
      }
      wrefresh(sg->score_w);
      l--;
      continue;
    }
    if (ch == '\b' || ch == KEY_BACKSPACE ||
	ch == KEY_DC || ch == 127) {
      /* We need to retake the current character; l++ will increase
       * it, so counteract that with an l-- to remove the BACKSPACE. */
      l--;
      if (l >= 0) {
	/* Erase the input char from the screen */
	mvwaddch(sg->score_w, promptrow, promptcol + l, ' ');
	/* And another l-- so that we overwrite the input char from
	 * inp on the next iteration of this loop. */
	l--;
      } else {
	/* We're at the start of the line, so there was no input char
	 * to erase */
      }
      wrefresh(sg->score_w);
      update_msgbox(sg->msg_w, "");
      continue;
    } else if (isalnum(ch)) {
      if (ch == 'q' && l == 0) {
	if (quitc) {
	  quit();
	} else {
	  quitc = 1;
	  update_msgbox(sg->msg_w, "Enter 'q' again to quit");
	  mvwaddch(sg->score_w, promptrow, promptcol, ' ');
	  l--;
	}
      } else {
	inp[l] = (char) ch;
	mvwaddch(sg->score_w, promptrow, promptcol + l, ch);
      }
      wrefresh(sg->score_w);
    } else if (ch == '?' && l == 0) {
      printinstrs(sg);
      mvwaddch(sg->score_w, promptrow, promptcol, ' ');
      l--;
    } else if (ch == '\n') {
      inp[l] = '\0';
      break;
    } else {
      update_msgbox(sg->msg_w, "Unexpected non-ASCII input");
      return getinput(sg, inp, length);
    }
  }
  /* l <= length-1 */
  inp[l] = '\0';
  return inp;
}
Ejemplo n.º 17
0
static int
test_get_wstr(int level, char **argv, WINDOW *strwin)
{
    WINDOW *txtbox = 0;
    WINDOW *txtwin = 0;
    FILE *fp;
    int ch;
    int rc;
    int txt_x = 0, txt_y = 0;
    int base_y;
    int flavor = 0;
    int limit = getmaxx(strwin) - 5;
    int actual;
    wint_t buffer[MAX_COLS];

    if (argv[level] == 0) {
	beep();
	return FALSE;
    }

    if (level > 1) {
	txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
	box(txtbox, 0, 0);
	wnoutrefresh(txtbox);

	txtwin = derwin(txtbox,
			getmaxy(txtbox) - 2,
			getmaxx(txtbox) - 2,
			1, 1);
	base_y = 0;
    } else {
	txtwin = stdscr;
	base_y = BASE_Y;
    }

    keypad(txtwin, TRUE);	/* enable keyboard mapping */
    (void) cbreak();		/* take input chars one at a time, no wait for \n */
    (void) noecho();		/* don't echo input */

    txt_y = base_y;
    txt_x = 0;
    wmove(txtwin, txt_y, txt_x);

    if ((fp = fopen(argv[level], "r")) != 0) {
	while ((ch = fgetc(fp)) != EOF) {
	    if (waddch(txtwin, UChar(ch)) != OK) {
		break;
	    }
	}
	fclose(fp);
    } else {
	wprintw(txtwin, "Cannot open:\n%s", argv[1]);
    }

    wmove(txtwin, txt_y, txt_x);
    actual = ShowFlavor(strwin, txtwin, flavor, limit);
    while (!Quit(ch = mvwgetch(txtwin, txt_y, txt_x))) {
	switch (ch) {
	case KEY_DOWN:
	case 'j':
	    if (txt_y < getmaxy(txtwin) - 1) {
		MovePrompt(txtwin, actual, ++txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;
	case KEY_UP:
	case 'k':
	    if (txt_y > base_y) {
		MovePrompt(txtwin, actual, --txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;
	case KEY_LEFT:
	case 'h':
	    if (txt_x > 0) {
		MovePrompt(txtwin, actual, txt_y, --txt_x);
	    } else {
		beep();
	    }
	    break;
	case KEY_RIGHT:
	case 'l':
	    if (txt_x < getmaxx(txtwin) - 1) {
		MovePrompt(txtwin, actual, txt_y, ++txt_x);
	    } else {
		beep();
	    }
	    break;

	case 'w':
	    test_get_wstr(level + 1, argv, strwin);
	    if (txtbox != 0) {
		touchwin(txtbox);
		wnoutrefresh(txtbox);
	    } else {
		touchwin(txtwin);
		wnoutrefresh(txtwin);
	    }
	    break;

	case '-':
	    if (limit > 0) {
		actual = ShowFlavor(strwin, txtwin, flavor, --limit);
		MovePrompt(txtwin, actual, txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;

	case '+':
	    actual = ShowFlavor(strwin, txtwin, flavor, ++limit);
	    MovePrompt(txtwin, actual, txt_y, txt_x);
	    break;

	case '<':
	    if (flavor > 0) {
		actual = ShowFlavor(strwin, txtwin, --flavor, limit);
		MovePrompt(txtwin, actual, txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;

	case '>':
	    if (flavor + 1 < eMaxFlavor) {
		actual = ShowFlavor(strwin, txtwin, ++flavor, limit);
		MovePrompt(txtwin, actual, txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;

	case ':':
	    actual = ShowFlavor(strwin, txtwin, flavor, limit);
	    *buffer = '\0';
	    rc = ERR;
	    echo();
	    (void) wattrset(txtwin, A_REVERSE);
	    switch (flavor) {
	    case eGetStr:
		if (txtwin != stdscr) {
		    wmove(txtwin, txt_y, txt_x);
		    rc = wget_wstr(txtwin, buffer);
		} else {
		    move(txt_y, txt_x);
		    rc = get_wstr(buffer);
		}
		break;
	    case eGetNStr:
		if (txtwin != stdscr) {
		    wmove(txtwin, txt_y, txt_x);
		    rc = wgetn_wstr(txtwin, buffer, limit);
		} else {
		    move(txt_y, txt_x);
		    rc = getn_wstr(buffer, limit);
		}
		break;
	    case eMvGetStr:
		if (txtwin != stdscr) {
		    rc = mvwget_wstr(txtwin, txt_y, txt_x, buffer);
		} else {
		    rc = mvget_wstr(txt_y, txt_x, buffer);
		}
		break;
	    case eMvGetNStr:
		if (txtwin != stdscr) {
		    rc = mvwgetn_wstr(txtwin, txt_y, txt_x, buffer, limit);
		} else {
		    rc = mvgetn_wstr(txt_y, txt_x, buffer, limit);
		}
		break;
	    case eMaxFlavor:
		break;
	    }
	    noecho();
	    (void) wattrset(txtwin, A_NORMAL);
	    wprintw(strwin, "%d", rc);
	    (void) waddwstr(strwin, (wchar_t *) buffer);
	    wnoutrefresh(strwin);
	    break;
	default:
	    beep();
	    break;
	}
	doupdate();
    }
    if (level > 1) {
	delwin(txtwin);
	delwin(txtbox);
    }
    return TRUE;
}