示例#1
0
char curses_query_key(const char *query, int *count)
{
    int width, height, key;
    WINDOW *win;
    int cnt = 0;
    nh_bool hascount = FALSE;
    
    height = 3;
    width = strlen(query) + 4;
    win = newdialog(height, width);
    mvwprintw(win, 1, 2, query);
    wrefresh(win);
    
    key = nh_wgetch(win);
    while ((isdigit(key) || key == KEY_BACKSPACE) && count != NULL) {
	cnt = 10*cnt + (key - '0');
	key = nh_wgetch(win);
	hascount = TRUE;
    }
    
    if (count != NULL) {
	if (!hascount && !cnt)
	    cnt = -1; /* signal to caller that no count was given */
	*count = cnt;
    }
    
    delwin(win);
    redraw_game_windows();
    return key;
}
示例#2
0
static void
resize_curses_msgwin(struct gamewin *gw)
{
    int linecount;
    char **lines;
    struct win_msgwin *wmw = (struct win_msgwin *)gw->extra;

    layout_curses_msgwin(wmw, &linecount, &lines, 1);
    free_wrap(lines);

    gw->win = newdialog(wmw->layout_height, wmw->layout_width,
                        wmw->context == krc_notification ? 2 : 1, NULL);
}
示例#3
0
char curses_yn_function(const char *query, const char *resp, char def)
{
    int width, height, key;
    WINDOW *win;
    char prompt[QBUFSZ];
    char *rb, respbuf[QBUFSZ];

    strcpy(respbuf, resp);
    /* any acceptable responses that follow <esc> aren't displayed */
    if ((rb = strchr(respbuf, '\033')) != 0)
	*rb = '\0';
    sprintf(prompt, "%s [%s] ", query, respbuf);
    if (def)
	sprintf(prompt + strlen(prompt), "(%c) ", def);
    
    height = 3;
    width = strlen(prompt) + 5;
    win = newdialog(height, width);
    mvwprintw(win, 1, 2, prompt);
    wrefresh(win);
    
    do {
	key = tolower(nh_wgetch(win));
	
	if (key == '\033') {
	    if (strchr(resp, 'q'))
		key = 'q';
	    else if (strchr(resp, 'n'))
		key = 'n';
	    else
		key = def;
	    break;
	} else if (strchr(quit_chars, key)) {
	    key = def;
	    break;
	}
	
	if (!strchr(resp, key))
	    key = 0;
	
    } while (!key);
    
    delwin(win);
    redraw_game_windows();
    return key;
}
示例#4
0
int curses_msgwin(const char *msg)
{
    int key, len;
    int width = strlen(msg) + 4;
    int prevcurs = curs_set(0);
    WINDOW *win = newdialog(3, width);
    
    len = strlen(msg);
    while (isspace(msg[len-1]))
	len--;
    
    mvwaddnstr(win, 1, 2, msg, len);
    wrefresh(win);
    key = nh_wgetch(win); /* wait for any key */
    
    delwin(win);
    curs_set(prevcurs);
    redraw_game_windows();
    
    return key;
}