示例#1
0
define_key(const char *str, int keycode)
{
    int code = ERR;

    T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode));
    if (SP == 0) {
	code = ERR;
    } else if (keycode > 0) {
	if (str != 0) {
	    define_key(str, 0);
	} else if (has_key(keycode)) {
	    while (_nc_remove_key(&(SP->_keytry), (unsigned) keycode))
		code = OK;
	}
	if (str != 0) {
	    if (key_defined(str) == 0) {
		(void) _nc_add_to_try(&(SP->_keytry), str, (unsigned) keycode);
		code = OK;
	    } else {
		code = ERR;
	    }
	}
    } else {
	while (_nc_remove_string(&(SP->_keytry), str))
	    code = OK;
    }
    returnCode(code);
}
示例#2
0
static void
really_define_key(WINDOW *win, const char *new_string, int code)
{
    int rc;
    const char *code_name = keyname(code);
    char *old_string;
    char *vis_string = 0;
    char temp[80];

    if (code_name == 0) {
	sprintf(temp, "Keycode %d", code);
	code_name = temp;
    }

    if ((old_string = keybound(code, 0)) != 0) {
	wprintw(win, "%s is %s\n",
		code_name,
		vis_string = visible(old_string));
    } else {
	wprintw(win, "%s is not bound\n",
		code_name);
    }
    log_last_line(win);

    if (vis_string != 0) {
	free(vis_string);
	vis_string = 0;
    }

    vis_string = visible(new_string);
    if ((rc = key_defined(new_string)) > 0) {
	wprintw(win, "%s was bound to %s\n", vis_string, keyname(rc));
	log_last_line(win);
    } else if (new_string != 0 && rc < 0) {
	wprintw(win, "%s conflicts with longer strings\n", vis_string);
	log_last_line(win);
    }
    rc = define_key(new_string, code);
    if (rc == ERR) {
	wprintw(win, "%s unchanged\n", code_name);
	log_last_line(win);
    } else if (new_string != 0) {
	wprintw(win, "%s is now bound to %s\n",
		vis_string,
		code_name);
	log_last_line(win);
    } else if (old_string != 0) {
	wprintw(win, "%s deleted\n", code_name);
	log_last_line(win);
    }
    if (vis_string != 0)
	free(vis_string);
    if (old_string != 0)
	free(old_string);
}
static PyObject*
curses_ex_key_defined(PyObject *self, PyObject *args) {
    const char *definition = NULL;
    if (!PyArg_ParseTuple(args, "y:key_defined", &definition))
        return NULL;

    if (ERR == key_defined(definition)) {
        curses_ex_seterror("key_defined");
        return NULL;
    }

    Py_RETURN_NONE;
}
示例#4
0
文件: ui_utils.c 项目: wildj79/tlf
/** lookup key code by capability name
 *
 * ncurses automatically maps extended capabilities (such as kNXT3 or similar)
 * to keycodes. But there is no fixed ordering for that.
 * So we look up the key code by its name on strtup and use that afterwards.
 * \param capability  - capability name
 * \return              keycode or 0 if no associated key found
 */
int lookup_key(char *capability) {
    char *esc_sequence = NULL;
    int keycode = 0;

    if (*capability == '\0') {
	return 0;
    }

    esc_sequence = tigetstr(capability);

    if (esc_sequence == NULL || esc_sequence == (char *)-1) {
	return 0;
    }

    keycode = key_defined(esc_sequence);

    return keycode;
}
示例#5
0
_nc_init_keytry(void)
{
    size_t n;

    /* The SP->_keytry value is initialized in newterm(), where the SP
     * structure is created, because we can not tell where keypad() or
     * mouse_activate() (which will call keyok()) are first called.
     */

    if (SP != 0) {
	for (n = 0; _nc_tinfo_fkeys[n].code; n++) {
	    if (_nc_tinfo_fkeys[n].offset < STRCOUNT) {
		(void) _nc_add_to_try(&(SP->_keytry),
				      CUR Strings[_nc_tinfo_fkeys[n].offset],
				      _nc_tinfo_fkeys[n].code);
	    }
	}
#if NCURSES_XNAMES
	/*
	 * Add any of the extended strings to the tries if their name begins
	 * with 'k', i.e., they follow the convention of other terminfo key
	 * names.
	 */
	{
	    TERMTYPE *tp = &(SP->_term->type);
	    for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) {
		const char *name = ExtStrname(tp, n, strnames);
		char *value = tp->Strings[n];
		if (name != 0
		    && *name == 'k'
		    && value != 0
		    && key_defined(value) == 0) {
		    (void) _nc_add_to_try(&(SP->_keytry),
					  value,
					  n - STRCOUNT + KEY_MAX);
		}
	    }
	}
#endif
#ifdef TRACE
	_nc_trace_tries(SP->_keytry);
#endif
    }
}