示例#1
0
static void search_mode_key(enum term_key_type type, unsigned int key)
{
	switch (type) {
	case KEY_NORMAL:
		switch (key) {
		case '\r':
			if (cmdline.buf.buffer[0]) {
				search_set_regexp(cmdline.buf.buffer);
				search_next();
				history_add(&search_history, cmdline.buf.buffer, search_history_size);
			} else {
				search_next();
			}
			cmdline_clear(&cmdline);
			set_input_mode(INPUT_NORMAL);
			break;
		}
		break;
	case KEY_META:
		switch (key) {
		case 'c':
			options.case_sensitive_search = (options.case_sensitive_search + 1) % 3;
			break;
		case 'r':
			search_set_direction(current_search_direction() ^ 1);
			break;
		}
		break;
	case KEY_SPECIAL:
		break;
	case KEY_PASTE:
		break;
	}
}
示例#2
0
文件: cmdline.c 项目: ameenross/dex
int cmdline_handle_key(struct cmdline *c, struct ptr_array *history, int key)
{
	char buf[4];
	int count;

	if (special_input_keypress(key, buf, &count)) {
		// \n is not allowed in command line because
		// command/search history file would break
		if (count && buf[0] != '\n')
			cmdline_insert_bytes(&cmdline, buf, count);
		c->search_pos = -1;
		return 1;
	}
	if (key <= KEY_UNICODE_MAX) {
		c->pos += gbuf_insert_ch(&c->buf, c->pos, key);
		return 1;
	}
	switch (key) {
	case CTRL('['): // ESC
	case CTRL('C'):
		cmdline_clear(c);
		return CMDLINE_CANCEL;
	case CTRL('D'):
		cmdline_delete(c);
		break;
	case CTRL('K'):
		cmdline_delete_eol(c);
		break;
	case CTRL('H'):
	case CTRL('?'):
		if (c->buf.len == 0)
			return CMDLINE_CANCEL;
		cmdline_backspace(c);
		break;
	case CTRL('U'):
		cmdline_delete_bol(c);
		break;
	case CTRL('V'):
		special_input_activate();
		break;
	case CTRL('W'):
		cmdline_erase_word(c);
		break;

	case CTRL('A'):
		c->pos = 0;
		return 1;
	case CTRL('B'):
		cmdline_prev_char(c);
		return 1;
	case CTRL('E'):
		c->pos = c->buf.len;
		return 1;
	case CTRL('F'):
		cmdline_next_char(c);
		return 1;
	case CTRL('Z'):
		suspend();
		return 1;
	case KEY_DELETE:
		cmdline_delete(c);
		break;

	case KEY_LEFT:
		cmdline_prev_char(c);
		return 1;
	case KEY_RIGHT:
		cmdline_next_char(c);
		return 1;
	case KEY_HOME:
		c->pos = 0;
		return 1;
	case KEY_END:
		c->pos = c->buf.len;
		return 1;
	case KEY_UP:
		if (history == NULL)
			return 0;
		if (c->search_pos < 0) {
			free(c->search_text);
			c->search_text = gbuf_cstring(&c->buf);
			c->search_pos = history->count;
		}
		if (history_search_forward(history, &c->search_pos, c->search_text))
			set_text(c, history->ptrs[c->search_pos]);
		return 1;
	case KEY_DOWN:
		if (history == NULL)
			return 0;
		if (c->search_pos < 0)
			return 1;
		if (history_search_backward(history, &c->search_pos, c->search_text)) {
			set_text(c, history->ptrs[c->search_pos]);
		} else {
			set_text(c, c->search_text);
			c->search_pos = -1;
		}
		return 1;
	case KEY_PASTE:
		cmdline_insert_paste(c);
		break;
	default:
		return 0;
	}
	c->search_pos = -1;
	return 1;
}
示例#3
0
文件: cmdline.c 项目: nellynette/dex
int cmdline_handle_key(struct cmdline *c, struct ptr_array *history, enum term_key_type type, unsigned int key)
{
	char buf[4];
	int count;

	if (special_input_keypress(type, key, buf, &count)) {
		// \n is not allowed in command line because
		// command/search history file would break
		if (count && buf[0] != '\n')
			cmdline_insert_bytes(&cmdline, buf, count);
		c->search_pos = -1;
		return 1;
	}
	switch (type) {
	case KEY_NORMAL:
		switch (key) {
		case CTRL('['): // ESC
		case CTRL('C'):
			cmdline_clear(c);
			return CMDLINE_CANCEL;
		case CTRL('D'):
			cmdline_delete(c);
			break;
		case CTRL('K'):
			cmdline_delete_eol(c);
			break;
		case CTRL('H'):
		case 0x7f: // ^?
			if (c->buf.len == 0)
				return CMDLINE_CANCEL;
			cmdline_backspace(c);
			break;
		case CTRL('U'):
			cmdline_delete_bol(c);
			break;
		case CTRL('V'):
			special_input_activate();
			break;
		case CTRL('W'):
			cmdline_erase_word(c);
			break;

		case CTRL('A'):
			c->pos = 0;
			return 1;
		case CTRL('B'):
			cmdline_prev_char(c);
			return 1;
		case CTRL('E'):
			c->pos = strlen(c->buf.buffer);
			return 1;
		case CTRL('F'):
			cmdline_next_char(c);
			return 1;
		case CTRL('Z'):
			suspend();
			return 1;
		default:
			// don't insert control characters
			if (key >= 0x20 && key != 0x7f) {
				cmdline_insert(c, key);
				return 1;
			}
			return 0;
		}
		break;
	case KEY_META:
		return 0;
	case KEY_SPECIAL:
		switch (key) {
		case SKEY_DELETE:
			cmdline_delete(c);
			break;

		case SKEY_LEFT:
			cmdline_prev_char(c);
			return 1;
		case SKEY_RIGHT:
			cmdline_next_char(c);
			return 1;
		case SKEY_HOME:
			c->pos = 0;
			return 1;
		case SKEY_END:
			c->pos = strlen(c->buf.buffer);
			return 1;
		case SKEY_UP:
			if (history == NULL)
				return 0;
			if (c->search_pos < 0) {
				free(c->search_text);
				c->search_text = xstrdup(c->buf.buffer);
				c->search_pos = history->count;
			}
			if (history_search_forward(history, &c->search_pos, c->search_text))
				set_text(c, history->ptrs[c->search_pos]);
			return 1;
		case SKEY_DOWN:
			if (history == NULL)
				return 0;
			if (c->search_pos < 0)
				return 1;
			if (history_search_backward(history, &c->search_pos, c->search_text)) {
				set_text(c, history->ptrs[c->search_pos]);
			} else {
				set_text(c, c->search_text);
				c->search_pos = -1;
			}
			return 1;
		default:
			return 0;
		}
		break;
	case KEY_PASTE:
		cmdline_insert_paste(c);
		break;
	}
	c->search_pos = -1;
	return 1;
}