Exemple #1
0
/******************************************************\
 * Description:	Checks if the exit key has been       *
 *		pressed.  If so, it checks if the     *
 *		file has been saved since the last    *
 *		modification.  If it hasn't it prompts*
 *		the user asking if they would like to *
 *		save.				      *
 * Returns:     2 == save, 1 == no save, 0 == cancel  *
\******************************************************/
int quitProgram(int notChanged, short int ch)
{   
    short int str;
							/* if exit key...     */
    if ((ch == KEY_F(8)) || (ch == CTRL_AND('q')) || (ch == CTRL_AND('x')))
    {
        if (!notChanged)				/* if changes made    */
        {
							/* prompt for exit    */
            str = questionWin("Do you want to save changes? (y/n)");

            if (str == 'Y' || str == 'y')		/* if yes, save       */
                return 2;
            else if ((str != 'N') && (str != 'n'))	/* don't quit, cancel */
                return 0;
        }

        return 1;					/* quit, don't save   */
    }
    else 
        return 0;					/* don't quit         */
}
Exemple #2
0
void map()
{
	struct list *l;
	int found = 0;
	int c = gui_getch(GETCH_COOKED);

	for(l = maps; l && l->data; l = l->next){
		struct map *m = l->data;

		if(m->c == c){
			gui_queue(m->cmd);
			found = 1;
			/* keep looking for more */
		}
	}

	if(!found && c != CTRL_AND('['))
		gui_status(GUI_ERR, "map %c not defined", c);
}
Exemple #3
0
char *prompt(char promp, const char *initial)
{
    int len;
    char *buf;
    int i;

    if(initial) {
        len = strlen(initial) + 1;

        buf = umalloc(len);
        i = len - 1;

        strcpy(buf, initial);

    } else {
        len = 10;
        buf = umalloc(len);
        i = 0;
    }

    int y, x;
    nc_get_yx(&y, &x);
    nc_set_yx(nc_LINES() - 1, 0);
    nc_addch(promp);

    for(int x = 0; x < i; x++)
        nc_addch(buf[x]);

    nc_clrtoeol();

    bool reading = true;

    while(reading) {
        bool wasraw;
        int ch = io_getch(IO_NOMAP | IO_MAPRAW, &wasraw, true);

        switch(ch) {
        case CTRL_AND('?'):
        case CTRL_AND('H'):
        case 263:
        case 127:
            /* backspace */
            if(i == 0)
                goto cancel;
            buf[--i] = '\0';
            nc_set_yx(nc_LINES() - 1, i + 1);
            break;

        case '\n':
        case '\r':
            reading = false;
            break;

        case CTRL_AND('u'):
            buf[i = 0] = '\0';
            nc_set_yx(nc_LINES() - 1, i + 1);
            break;

        case K_ESC:
            if(!wasraw)
                goto cancel;
        /* fall */

        default:
            buf[i++] = ch;
            nc_addch(ch);
            if(i == len)
                buf = urealloc(buf, len *= 2);
            buf[i] = '\0';
            break;
        }
    }

    nc_set_yx(y, x);
    return buf;
cancel:
    nc_set_yx(y, x);
    free(buf);
    return NULL;
}