mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	If xterm-keys is on, use xterm(1) style keys for Home and End as well as
modified keys.
This commit is contained in:
		
							
								
								
									
										10
									
								
								input-keys.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								input-keys.c
									
									
									
									
									
								
							| @@ -158,6 +158,7 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m) | ||||
| 	char				*out; | ||||
| 	key_code			 justkey; | ||||
| 	struct utf8_data		 ud; | ||||
| 	int				 mode; | ||||
|  | ||||
| 	log_debug("writing key 0x%llx (%s) to %%%u", key, | ||||
| 	    key_string_lookup_key(key), wp->id); | ||||
| @@ -194,8 +195,9 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m) | ||||
| 	 * Then try to look this up as an xterm key, if the flag to output them | ||||
| 	 * is set. | ||||
| 	 */ | ||||
| 	mode = wp->screen->mode; | ||||
| 	if (options_get_number(wp->window->options, "xterm-keys")) { | ||||
| 		if ((out = xterm_keys_lookup(key)) != NULL) { | ||||
| 		if ((out = xterm_keys_lookup(key, mode)) != NULL) { | ||||
| 			bufferevent_write(wp->event, out, strlen(out)); | ||||
| 			free(out); | ||||
| 			return; | ||||
| @@ -206,11 +208,9 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m) | ||||
| 	for (i = 0; i < nitems(input_keys); i++) { | ||||
| 		ike = &input_keys[i]; | ||||
|  | ||||
| 		if ((ike->flags & INPUTKEY_KEYPAD) && | ||||
| 		    !(wp->screen->mode & MODE_KKEYPAD)) | ||||
| 		if ((ike->flags & INPUTKEY_KEYPAD) && (~mode & MODE_KKEYPAD)) | ||||
| 			continue; | ||||
| 		if ((ike->flags & INPUTKEY_CURSOR) && | ||||
| 		    !(wp->screen->mode & MODE_KCURSOR)) | ||||
| 		if ((ike->flags & INPUTKEY_CURSOR) && (~mode & MODE_KCURSOR)) | ||||
| 			continue; | ||||
|  | ||||
| 		if ((key & KEYC_ESCAPE) && (ike->key | KEYC_ESCAPE) == key) | ||||
|   | ||||
							
								
								
									
										34
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								tmux.1
									
									
									
									
									
								
							| @@ -1142,14 +1142,6 @@ Commands in copy mode may be prefaced by an optional repeat count. | ||||
| With vi key bindings, a prefix is entered using the number keys; with | ||||
| emacs, the Alt (meta) key and a number begins prefix entry. | ||||
| .Pp | ||||
| Mode key bindings are defined in two tables: | ||||
| .Em vi-choice | ||||
| and | ||||
| .Em emacs-choice | ||||
| for keys used when choosing from lists (such as produced by the | ||||
| .Ic choose-window | ||||
| command). | ||||
| .Pp | ||||
| The synopsis for the | ||||
| .Ic copy-mode | ||||
| command is: | ||||
| @@ -2138,7 +2130,6 @@ Commands related to key bindings are as follows: | ||||
| .Bl -tag -width Ds | ||||
| .It Xo Ic bind-key | ||||
| .Op Fl nr | ||||
| .Op Fl t Ar mode-table | ||||
| .Op Fl T Ar key-table | ||||
| .Ar key Ar command Op Ar arguments | ||||
| .Xc | ||||
| @@ -2187,18 +2178,10 @@ flag indicates this key may repeat, see the | ||||
| .Ic repeat-time | ||||
| option. | ||||
| .Pp | ||||
| If | ||||
| .Fl t | ||||
| is present, | ||||
| .Ar key | ||||
| is bound in | ||||
| .Ar mode-table . | ||||
| .Pp | ||||
| To view the default bindings and possible commands, see the | ||||
| .Ic list-keys | ||||
| command. | ||||
| .It Xo Ic list-keys | ||||
| .Op Fl t Ar mode-table | ||||
| .Op Fl T Ar key-table | ||||
| .Xc | ||||
| .D1 (alias: Ic lsk ) | ||||
| @@ -2210,15 +2193,6 @@ With | ||||
| .Fl T | ||||
| only | ||||
| .Ar key-table . | ||||
| .Pp | ||||
| With | ||||
| .Fl t , | ||||
| the key bindings in | ||||
| .Ar mode-table | ||||
| are listed; this may be one of: | ||||
| .Em vi-choice | ||||
| or | ||||
| .Em emacs-choice . | ||||
| .It Xo Ic send-keys | ||||
| .Op Fl lMRX | ||||
| .Op Fl N Ar repeat-count | ||||
| @@ -2263,17 +2237,15 @@ Send the prefix key, or with | ||||
| the secondary prefix key, to a window as if it was pressed. | ||||
| .It Xo Ic unbind-key | ||||
| .Op Fl an | ||||
| .Op Fl t Ar mode-table | ||||
| .Op Fl T Ar key-table | ||||
| .Ar key | ||||
| .Xc | ||||
| .D1 (alias: Ic unbind ) | ||||
| Unbind the command bound to | ||||
| .Ar key . | ||||
| .Fl n , | ||||
| .Fl T | ||||
| .Fl n | ||||
| and | ||||
| .Fl t | ||||
| .Fl T | ||||
| are the same as for | ||||
| .Ic bind-key . | ||||
| If | ||||
| @@ -2498,7 +2470,7 @@ interactive menu when required. | ||||
| .It Ic terminal-overrides[] Ar string | ||||
| Allow terminal descriptions read using | ||||
| .Xr terminfo 5 | ||||
| to be overriden. | ||||
| to be overridden. | ||||
| Each entry is a colon-separated string made up of a terminal type pattern | ||||
| (matched using | ||||
| .Xr fnmatch 3 ) | ||||
|   | ||||
							
								
								
									
										66
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										66
									
								
								tmux.h
									
									
									
									
									
								
							| @@ -471,58 +471,10 @@ struct msg_stderr_data { | ||||
| 	char	data[BUFSIZ]; | ||||
| }; | ||||
|  | ||||
| /* Mode key commands. */ | ||||
| enum mode_key_cmd { | ||||
| 	MODEKEY_NONE, | ||||
| 	MODEKEY_OTHER, | ||||
|  | ||||
| 	/* Menu (choice) keys. */ | ||||
| 	MODEKEYCHOICE_BACKSPACE, | ||||
| 	MODEKEYCHOICE_BOTTOMLINE, | ||||
| 	MODEKEYCHOICE_CANCEL, | ||||
| 	MODEKEYCHOICE_CHOOSE, | ||||
| 	MODEKEYCHOICE_DOWN, | ||||
| 	MODEKEYCHOICE_ENDOFLIST, | ||||
| 	MODEKEYCHOICE_PAGEDOWN, | ||||
| 	MODEKEYCHOICE_PAGEUP, | ||||
| 	MODEKEYCHOICE_SCROLLDOWN, | ||||
| 	MODEKEYCHOICE_SCROLLUP, | ||||
| 	MODEKEYCHOICE_STARTNUMBERPREFIX, | ||||
| 	MODEKEYCHOICE_STARTOFLIST, | ||||
| 	MODEKEYCHOICE_TOPLINE, | ||||
| 	MODEKEYCHOICE_TREE_COLLAPSE, | ||||
| 	MODEKEYCHOICE_TREE_COLLAPSE_ALL, | ||||
| 	MODEKEYCHOICE_TREE_EXPAND, | ||||
| 	MODEKEYCHOICE_TREE_EXPAND_ALL, | ||||
| 	MODEKEYCHOICE_TREE_TOGGLE, | ||||
| 	MODEKEYCHOICE_UP, | ||||
| }; | ||||
|  | ||||
| /* Data required while mode keys are in use. */ | ||||
| struct mode_key_data { | ||||
| 	struct mode_key_tree   *tree; | ||||
| }; | ||||
| /* Mode keys. */ | ||||
| #define MODEKEY_EMACS 0 | ||||
| #define MODEKEY_VI 1 | ||||
|  | ||||
| /* Binding between a key and a command. */ | ||||
| struct mode_key_binding { | ||||
| 	key_code			 key; | ||||
| 	enum mode_key_cmd		 cmd; | ||||
|  | ||||
| 	RB_ENTRY(mode_key_binding)	 entry; | ||||
| }; | ||||
| RB_HEAD(mode_key_tree, mode_key_binding); | ||||
|  | ||||
| /* Named mode key table description. */ | ||||
| struct mode_key_entry; | ||||
| struct mode_key_table { | ||||
| 	const char			*name; | ||||
| 	const struct mode_key_cmdstr	*cmdstr; | ||||
| 	struct mode_key_tree		*tree; | ||||
| 	const struct mode_key_entry	*table;	/* default entries */ | ||||
| }; | ||||
|  | ||||
| /* Modes. */ | ||||
| #define MODE_CURSOR 0x1 | ||||
| #define MODE_INSERT 0x2 | ||||
| @@ -1580,20 +1532,6 @@ void printflike(4, 5) hooks_run(struct hooks *, struct client *, | ||||
| void printflike(4, 5) hooks_insert(struct hooks *, struct cmdq_item *, | ||||
| 		    struct cmd_find_state *, const char *, ...); | ||||
|  | ||||
| /* mode-key.c */ | ||||
| extern struct mode_key_tree mode_key_tree_vi_choice; | ||||
| extern struct mode_key_tree mode_key_tree_emacs_choice; | ||||
| int	mode_key_cmp(struct mode_key_binding *, struct mode_key_binding *); | ||||
| RB_PROTOTYPE(mode_key_tree, mode_key_binding, entry, mode_key_cmp); | ||||
| const char *mode_key_tostring(const struct mode_key_cmdstr *, | ||||
| 	    enum mode_key_cmd); | ||||
| enum mode_key_cmd mode_key_fromstring(const struct mode_key_cmdstr *, | ||||
| 	    const char *); | ||||
| const struct mode_key_table *mode_key_findtable(const char *); | ||||
| void	mode_key_init_trees(void); | ||||
| void	mode_key_init(struct mode_key_data *, struct mode_key_tree *); | ||||
| enum mode_key_cmd mode_key_lookup(struct mode_key_data *, key_code); | ||||
|  | ||||
| /* notify.c */ | ||||
| void	notify_input(struct window_pane *, struct evbuffer *); | ||||
| void	notify_client(const char *, struct client *); | ||||
| @@ -1950,7 +1888,7 @@ void	 input_parse(struct window_pane *); | ||||
| void	 input_key(struct window_pane *, key_code, struct mouse_event *); | ||||
|  | ||||
| /* xterm-keys.c */ | ||||
| char	*xterm_keys_lookup(key_code); | ||||
| char	*xterm_keys_lookup(key_code, int); | ||||
| int	 xterm_keys_find(const char *, size_t, size_t *, key_code *); | ||||
|  | ||||
| /* colour.c */ | ||||
|   | ||||
							
								
								
									
										43
									
								
								xterm-keys.c
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								xterm-keys.c
									
									
									
									
									
								
							| @@ -50,7 +50,17 @@ struct xterm_keys_entry { | ||||
| 	const char	*template; | ||||
| }; | ||||
|  | ||||
| static const struct xterm_keys_entry xterm_keys_table[] = { | ||||
| static const struct xterm_keys_entry xterm_keys_standard[] = { | ||||
| 	{ KEYC_HOME,	"\033[H" }, | ||||
| 	{ KEYC_END,	"\033[F" }, | ||||
| }; | ||||
|  | ||||
| static const struct xterm_keys_entry xterm_keys_cursor[] = { | ||||
| 	{ KEYC_HOME,	"\033OH" }, | ||||
| 	{ KEYC_END,	"\033OF" }, | ||||
| }; | ||||
|  | ||||
| static const struct xterm_keys_entry xterm_keys_modified[] = { | ||||
| 	{ KEYC_F1,	"\033[1;_P" }, | ||||
| 	{ KEYC_F1,	"\033O1;_P" }, | ||||
| 	{ KEYC_F1,	"\033O_P" }, | ||||
| @@ -189,8 +199,8 @@ xterm_keys_find(const char *buf, size_t len, size_t *size, key_code *key) | ||||
| 	int				 matched; | ||||
| 	key_code			 modifiers; | ||||
|  | ||||
| 	for (i = 0; i < nitems(xterm_keys_table); i++) { | ||||
| 		entry = &xterm_keys_table[i]; | ||||
| 	for (i = 0; i < nitems(xterm_keys_modified); i++) { | ||||
| 		entry = &xterm_keys_modified[i]; | ||||
|  | ||||
| 		matched = xterm_keys_match(entry->template, buf, len, size, | ||||
| 		    &modifiers); | ||||
| @@ -205,10 +215,10 @@ xterm_keys_find(const char *buf, size_t len, size_t *size, key_code *key) | ||||
|  | ||||
| /* Lookup a key number from the table. */ | ||||
| char * | ||||
| xterm_keys_lookup(key_code key) | ||||
| xterm_keys_lookup(key_code key, int mode) | ||||
| { | ||||
| 	const struct xterm_keys_entry	*entry; | ||||
| 	u_int				 i; | ||||
| 	const struct xterm_keys_entry	*table, *entry; | ||||
| 	u_int				 items, i; | ||||
| 	key_code			 modifiers; | ||||
| 	char				*out; | ||||
|  | ||||
| @@ -224,21 +234,32 @@ xterm_keys_lookup(key_code key) | ||||
| 	 * If the key has no modifiers, return NULL and let it fall through to | ||||
| 	 * the normal lookup. | ||||
| 	 */ | ||||
| 	if (modifiers == 1) | ||||
| 		return (NULL); | ||||
| 	if (modifiers != 1) { | ||||
| 		table = xterm_keys_modified; | ||||
| 		items = nitems(xterm_keys_modified); | ||||
| 	} else { | ||||
| 		if (mode & MODE_KCURSOR) { | ||||
| 			table = xterm_keys_cursor; | ||||
| 			items = nitems(xterm_keys_cursor); | ||||
| 		} else { | ||||
| 			table = xterm_keys_standard; | ||||
| 			items = nitems(xterm_keys_standard); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	/* Otherwise, find the key in the table. */ | ||||
| 	key &= ~(KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL); | ||||
| 	for (i = 0; i < nitems(xterm_keys_table); i++) { | ||||
| 		entry = &xterm_keys_table[i]; | ||||
| 	for (i = 0; i < items; i++) { | ||||
| 		entry = &table[i]; | ||||
| 		if (key == entry->key) | ||||
| 			break; | ||||
| 	} | ||||
| 	if (i == nitems(xterm_keys_table)) | ||||
| 	if (i == items) | ||||
| 		return (NULL); | ||||
|  | ||||
| 	/* Copy the template and replace the modifier. */ | ||||
| 	out = xstrdup(entry->template); | ||||
| 	if (modifiers != 1) | ||||
| 		out[strcspn(out, "_")] = '0' + modifiers; | ||||
| 	return (out); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 nicm
					nicm