Instead of setting up the default keys by building the key struct

directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.
pull/1/head
nicm 2014-10-20 22:29:25 +00:00
parent f0b69c7711
commit 45dfc5a074
68 changed files with 86 additions and 403 deletions

View File

@ -37,7 +37,6 @@ const struct cmd_entry cmd_attach_session_entry = {
"c:drt:", 0, 0,
"[-dr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
CMD_CANTNEST|CMD_STARTSERVER,
NULL,
cmd_attach_session_exec
};

View File

@ -36,7 +36,6 @@ const struct cmd_entry cmd_bind_key_entry = {
"cnrt:", 1, -1,
"[-cnr] [-t mode-table] key command [arguments]",
0,
NULL,
cmd_bind_key_exec
};

View File

@ -33,7 +33,6 @@ const struct cmd_entry cmd_break_pane_entry = {
"dPF:t:", 0, 0,
"[-dP] [-F format] " CMD_TARGET_PANE_USAGE,
0,
NULL,
cmd_break_pane_exec
};

View File

@ -41,7 +41,6 @@ const struct cmd_entry cmd_capture_pane_entry = {
"[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] [-S start-line]"
CMD_TARGET_PANE_USAGE,
0,
NULL,
cmd_capture_pane_exec
};

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_choose_buffer_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
NULL,
cmd_choose_buffer_exec
};

View File

@ -36,7 +36,6 @@ const struct cmd_entry cmd_choose_client_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
NULL,
cmd_choose_client_exec
};

View File

@ -40,7 +40,6 @@ const struct cmd_entry cmd_choose_tree_entry = {
"[-suw] [-b session-template] [-c window template] [-S format] " \
"[-W format] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
cmd_choose_tree_exec
};
@ -49,7 +48,6 @@ const struct cmd_entry cmd_choose_session_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
0,
NULL,
cmd_choose_tree_exec
};
@ -58,7 +56,6 @@ const struct cmd_entry cmd_choose_window_entry = {
"F:t:", 0, 1,
CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
0,
NULL,
cmd_choose_tree_exec
};

View File

@ -31,7 +31,6 @@ const struct cmd_entry cmd_clear_history_entry = {
"t:", 0, 0,
CMD_TARGET_PANE_USAGE,
0,
NULL,
cmd_clear_history_exec
};

View File

@ -31,7 +31,6 @@ const struct cmd_entry cmd_clock_mode_entry = {
"t:", 0, 0,
CMD_TARGET_PANE_USAGE,
0,
NULL,
cmd_clock_mode_exec
};

View File

@ -29,7 +29,6 @@
* Prompt for command in client.
*/
void cmd_command_prompt_key_binding(struct cmd *, int);
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *);
int cmd_command_prompt_callback(void *, const char *);
@ -40,7 +39,6 @@ const struct cmd_entry cmd_command_prompt_entry = {
"I:p:t:", 0, 1,
"[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " [template]",
0,
cmd_command_prompt_key_binding,
cmd_command_prompt_exec
};
@ -54,34 +52,6 @@ struct cmd_command_prompt_cdata {
int idx;
};
void
cmd_command_prompt_key_binding(struct cmd *self, int key)
{
switch (key) {
case '$':
self->args = args_create(1, "rename-session '%%'");
args_set(self->args, 'I', "#S");
break;
case ',':
self->args = args_create(1, "rename-window '%%'");
args_set(self->args, 'I', "#W");
break;
case '.':
self->args = args_create(1, "move-window -t '%%'");
break;
case 'f':
self->args = args_create(1, "find-window '%%'");
break;
case '\'':
self->args = args_create(1, "select-window -t ':%%'");
args_set(self->args, 'p', "index");
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -26,7 +26,6 @@
* Asks for confirmation before executing a command.
*/
void cmd_confirm_before_key_binding(struct cmd *, int);
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *);
int cmd_confirm_before_callback(void *, const char *);
@ -37,7 +36,6 @@ const struct cmd_entry cmd_confirm_before_entry = {
"p:t:", 1, 1,
"[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
0,
cmd_confirm_before_key_binding,
cmd_confirm_before_exec
};
@ -46,24 +44,6 @@ struct cmd_confirm_before_data {
struct client *client;
};
void
cmd_confirm_before_key_binding(struct cmd *self, int key)
{
switch (key) {
case '&':
self->args = args_create(1, "kill-window");
args_set(self->args, 'p', "kill-window #W? (y/n)");
break;
case 'x':
self->args = args_create(1, "kill-pane");
args_set(self->args, 'p', "kill-pane #P? (y/n)");
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -24,7 +24,6 @@
* Enter copy mode.
*/
void cmd_copy_mode_key_binding(struct cmd *, int);
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_copy_mode_entry = {
@ -32,18 +31,9 @@ const struct cmd_entry cmd_copy_mode_entry = {
"t:u", 0, 0,
"[-u] " CMD_TARGET_PANE_USAGE,
0,
cmd_copy_mode_key_binding,
cmd_copy_mode_exec
};
void
cmd_copy_mode_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == KEYC_PPAGE)
args_set(self->args, 'u', NULL);
}
enum cmd_retval
cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -33,7 +33,6 @@ const struct cmd_entry cmd_delete_buffer_entry = {
"b:", 0, 0,
CMD_BUFFER_USAGE,
0,
NULL,
cmd_delete_buffer_exec
};

View File

@ -33,7 +33,6 @@ const struct cmd_entry cmd_detach_client_entry = {
"as:t:P", 0, 0,
"[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
CMD_READONLY,
NULL,
cmd_detach_client_exec
};

View File

@ -35,7 +35,6 @@ const struct cmd_entry cmd_display_message_entry = {
"[-p] [-c target-client] [-F format] " CMD_TARGET_PANE_USAGE
" [message]",
0,
NULL,
cmd_display_message_exec
};

View File

@ -31,7 +31,6 @@ const struct cmd_entry cmd_display_panes_entry = {
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
NULL,
cmd_display_panes_exec
};

View File

@ -47,7 +47,6 @@ const struct cmd_entry cmd_find_window_entry = {
"F:CNt:T", 1, 4,
"[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
0,
NULL,
cmd_find_window_exec
};

View File

@ -31,7 +31,6 @@ const struct cmd_entry cmd_has_session_entry = {
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
NULL,
cmd_has_session_exec
};

View File

@ -40,7 +40,6 @@ const struct cmd_entry cmd_if_shell_entry = {
"bt:", 2, 3,
"[-b] " CMD_TARGET_PANE_USAGE " shell-command command [command]",
0,
NULL,
cmd_if_shell_exec
};

View File

@ -29,7 +29,6 @@
* Join or move a pane into another (like split/swap/kill).
*/
void cmd_join_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *);
enum cmd_retval join_pane(struct cmd *, struct cmd_q *, int);
@ -39,7 +38,6 @@ const struct cmd_entry cmd_join_pane_entry = {
"bdhvp:l:s:t:", 0, 0,
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
0,
cmd_join_pane_key_binding,
cmd_join_pane_exec
};
@ -48,24 +46,9 @@ const struct cmd_entry cmd_move_pane_entry = {
"bdhvp:l:s:t:", 0, 0,
"[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
0,
NULL,
cmd_join_pane_exec
};
void
cmd_join_pane_key_binding(struct cmd *self, int key)
{
switch (key) {
case '%':
self->args = args_create(0);
args_set(self->args, 'h', NULL);
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -33,7 +33,6 @@ const struct cmd_entry cmd_kill_pane_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_PANE_USAGE,
0,
NULL,
cmd_kill_pane_exec
};

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_kill_server_entry = {
"", 0, 0,
"",
0,
NULL,
cmd_kill_server_exec
};
@ -43,7 +42,6 @@ const struct cmd_entry cmd_start_server_entry = {
"", 0, 0,
"",
CMD_STARTSERVER,
NULL,
cmd_kill_server_exec
};

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_kill_session_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_SESSION_USAGE,
0,
NULL,
cmd_kill_session_exec
};

View File

@ -31,7 +31,6 @@ const struct cmd_entry cmd_kill_window_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
cmd_kill_window_exec
};

View File

@ -33,7 +33,6 @@ const struct cmd_entry cmd_link_window_entry = {
"dks:t:", 0, 0,
"[-dk] " CMD_SRCDST_WINDOW_USAGE,
0,
NULL,
cmd_link_window_exec
};

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_list_buffers_entry = {
"F:", 0, 0,
"[-F format]",
0,
NULL,
cmd_list_buffers_exec
};

View File

@ -35,7 +35,6 @@ const struct cmd_entry cmd_list_clients_entry = {
"F:t:", 0, 0,
"[-F format] " CMD_TARGET_SESSION_USAGE,
CMD_READONLY,
NULL,
cmd_list_clients_exec
};

View File

@ -31,7 +31,6 @@ const struct cmd_entry cmd_list_commands_entry = {
"", 0, 0,
"",
0,
NULL,
cmd_list_commands_exec
};

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_list_keys_entry = {
"t:", 0, 0,
"[-t key-table]",
0,
NULL,
cmd_list_keys_exec
};

View File

@ -40,7 +40,6 @@ const struct cmd_entry cmd_list_panes_entry = {
"asF:t:", 0, 0,
"[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
cmd_list_panes_exec
};

View File

@ -35,7 +35,6 @@ const struct cmd_entry cmd_list_sessions_entry = {
"F:", 0, 0,
"[-F format]",
0,
NULL,
cmd_list_sessions_exec
};

View File

@ -38,7 +38,6 @@ const struct cmd_entry cmd_list_windows_entry = {
"F:at:", 0, 0,
"[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
0,
NULL,
cmd_list_windows_exec
};

View File

@ -39,7 +39,6 @@ const struct cmd_entry cmd_load_buffer_entry = {
"b:", 1, 1,
CMD_BUFFER_USAGE " path",
0,
NULL,
cmd_load_buffer_exec
};

View File

@ -31,7 +31,6 @@ const struct cmd_entry cmd_lock_server_entry = {
"", 0, 0,
"",
0,
NULL,
cmd_lock_server_exec
};
@ -40,7 +39,6 @@ const struct cmd_entry cmd_lock_session_entry = {
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
NULL,
cmd_lock_server_exec
};
@ -49,7 +47,6 @@ const struct cmd_entry cmd_lock_client_entry = {
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
NULL,
cmd_lock_server_exec
};

View File

@ -33,7 +33,6 @@ const struct cmd_entry cmd_move_window_entry = {
"dkrs:t:", 0, 0,
"[-dkr] " CMD_SRCDST_WINDOW_USAGE,
0,
NULL,
cmd_move_window_exec
};

View File

@ -40,7 +40,6 @@ const struct cmd_entry cmd_new_session_entry = {
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
"[-y height] [command]",
CMD_STARTSERVER|CMD_CANTNEST,
NULL,
cmd_new_session_exec
};

View File

@ -38,7 +38,6 @@ const struct cmd_entry cmd_new_window_entry = {
"[-adkP] [-c start-directory] [-F format] [-n window-name] "
CMD_TARGET_WINDOW_USAGE " [command]",
0,
NULL,
cmd_new_window_exec
};

View File

@ -38,7 +38,6 @@ const struct cmd_entry cmd_paste_buffer_entry = {
"db:prs:t:", 0, 0,
"[-dpr] [-s separator] " CMD_BUFFER_USAGE " " CMD_TARGET_PANE_USAGE,
0,
NULL,
cmd_paste_buffer_exec
};

View File

@ -41,7 +41,6 @@ const struct cmd_entry cmd_pipe_pane_entry = {
"ot:", 0, 1,
"[-o] " CMD_TARGET_PANE_USAGE " [command]",
0,
NULL,
cmd_pipe_pane_exec
};

View File

@ -31,7 +31,6 @@ const struct cmd_entry cmd_refresh_client_entry = {
"C:St:", 0, 0,
"[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
0,
NULL,
cmd_refresh_client_exec
};

View File

@ -33,7 +33,6 @@ const struct cmd_entry cmd_rename_session_entry = {
"t:", 1, 1,
CMD_TARGET_SESSION_USAGE " new-name",
0,
NULL,
cmd_rename_session_exec
};

View File

@ -33,7 +33,6 @@ const struct cmd_entry cmd_rename_window_entry = {
"t:", 1, 1,
CMD_TARGET_WINDOW_USAGE " new-name",
0,
NULL,
cmd_rename_window_exec
};

View File

@ -26,7 +26,6 @@
* Increase or decrease pane size.
*/
void cmd_resize_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_resize_pane_entry = {
@ -34,56 +33,9 @@ const struct cmd_entry cmd_resize_pane_entry = {
"DLRt:Ux:y:Z", 0, 1,
"[-DLRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]",
0,
cmd_resize_pane_key_binding,
cmd_resize_pane_exec
};
void
cmd_resize_pane_key_binding(struct cmd *self, int key)
{
switch (key) {
case KEYC_UP | KEYC_CTRL:
self->args = args_create(0);
args_set(self->args, 'U', NULL);
break;
case KEYC_DOWN | KEYC_CTRL:
self->args = args_create(0);
args_set(self->args, 'D', NULL);
break;
case KEYC_LEFT | KEYC_CTRL:
self->args = args_create(0);
args_set(self->args, 'L', NULL);
break;
case KEYC_RIGHT | KEYC_CTRL:
self->args = args_create(0);
args_set(self->args, 'R', NULL);
break;
case KEYC_UP | KEYC_ESCAPE:
self->args = args_create(1, "5");
args_set(self->args, 'U', NULL);
break;
case KEYC_DOWN | KEYC_ESCAPE:
self->args = args_create(1, "5");
args_set(self->args, 'D', NULL);
break;
case KEYC_LEFT | KEYC_ESCAPE:
self->args = args_create(1, "5");
args_set(self->args, 'L', NULL);
break;
case KEYC_RIGHT | KEYC_ESCAPE:
self->args = args_create(1, "5");
args_set(self->args, 'R', NULL);
break;
case 'z':
self->args = args_create(0);
args_set(self->args, 'Z', NULL);
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_respawn_window_entry = {
"kt:", 0, -1,
"[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
0,
NULL,
cmd_respawn_window_exec
};

View File

@ -24,7 +24,6 @@
* Rotate the panes in a window.
*/
void cmd_rotate_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_rotate_window_entry = {
@ -32,18 +31,9 @@ const struct cmd_entry cmd_rotate_window_entry = {
"Dt:U", 0, 0,
"[-DU] " CMD_TARGET_WINDOW_USAGE,
0,
cmd_rotate_window_key_binding,
cmd_rotate_window_exec
};
void
cmd_rotate_window_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == ('o' | KEYC_ESCAPE))
args_set(self->args, 'D', NULL);
}
enum cmd_retval
cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -40,7 +40,6 @@ const struct cmd_entry cmd_run_shell_entry = {
"bt:", 1, 1,
"[-b] " CMD_TARGET_PANE_USAGE " shell-command",
0,
NULL,
cmd_run_shell_exec
};

View File

@ -39,7 +39,6 @@ const struct cmd_entry cmd_save_buffer_entry = {
"ab:", 1, 1,
"[-a] " CMD_BUFFER_USAGE " path",
0,
NULL,
cmd_save_buffer_exec
};
@ -48,7 +47,6 @@ const struct cmd_entry cmd_show_buffer_entry = {
"b:", 0, 0,
CMD_BUFFER_USAGE,
0,
NULL,
cmd_save_buffer_exec
};

View File

@ -24,15 +24,12 @@
* Switch window to selected layout.
*/
void cmd_select_layout_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_layout_entry = {
"select-layout", "selectl",
"npt:", 0, 1,
"[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
0,
cmd_select_layout_key_binding,
cmd_select_layout_exec
};
@ -41,7 +38,6 @@ const struct cmd_entry cmd_next_layout_entry = {
"t:", 0, 0,
CMD_TARGET_WINDOW_USAGE,
0,
NULL,
cmd_select_layout_exec
};
@ -50,35 +46,9 @@ const struct cmd_entry cmd_previous_layout_entry = {
"t:", 0, 0,
CMD_TARGET_WINDOW_USAGE,
0,
NULL,
cmd_select_layout_exec
};
void
cmd_select_layout_key_binding(struct cmd *self, int key)
{
switch (key) {
case '1' | KEYC_ESCAPE:
self->args = args_create(1, "even-horizontal");
break;
case '2' | KEYC_ESCAPE:
self->args = args_create(1, "even-vertical");
break;
case '3' | KEYC_ESCAPE:
self->args = args_create(1, "main-horizontal");
break;
case '4' | KEYC_ESCAPE:
self->args = args_create(1, "main-vertical");
break;
case '5' | KEYC_ESCAPE:
self->args = args_create(1, "tiled");
break;
default:
self->args = args_create(0);
break;
}
}
enum cmd_retval
cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -24,7 +24,6 @@
* Select pane.
*/
void cmd_select_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_pane_entry = {
@ -32,7 +31,6 @@ const struct cmd_entry cmd_select_pane_entry = {
"DdeLlRt:U", 0, 0,
"[-DdeLlRU] " CMD_TARGET_PANE_USAGE,
0,
cmd_select_pane_key_binding,
cmd_select_pane_exec
};
@ -41,26 +39,9 @@ const struct cmd_entry cmd_last_pane_entry = {
"det:", 0, 0,
"[-de] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
cmd_select_pane_exec
};
void
cmd_select_pane_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == KEYC_UP)
args_set(self->args, 'U', NULL);
if (key == KEYC_DOWN)
args_set(self->args, 'D', NULL);
if (key == KEYC_LEFT)
args_set(self->args, 'L', NULL);
if (key == KEYC_RIGHT)
args_set(self->args, 'R', NULL);
if (key == 'o')
args_set(self->args, 't', ":.+");
}
enum cmd_retval
cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -26,7 +26,6 @@
* Select window by index.
*/
void cmd_select_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_window_entry = {
@ -34,7 +33,6 @@ const struct cmd_entry cmd_select_window_entry = {
"lnpTt:", 0, 0,
"[-lnpT] " CMD_TARGET_WINDOW_USAGE,
0,
cmd_select_window_key_binding,
cmd_select_window_exec
};
@ -43,7 +41,6 @@ const struct cmd_entry cmd_next_window_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_SESSION_USAGE,
0,
cmd_select_window_key_binding,
cmd_select_window_exec
};
@ -52,7 +49,6 @@ const struct cmd_entry cmd_previous_window_entry = {
"at:", 0, 0,
"[-a] " CMD_TARGET_SESSION_USAGE,
0,
cmd_select_window_key_binding,
cmd_select_window_exec
};
@ -61,24 +57,9 @@ const struct cmd_entry cmd_last_window_entry = {
"t:", 0, 0,
CMD_TARGET_SESSION_USAGE,
0,
NULL,
cmd_select_window_exec
};
void
cmd_select_window_key_binding(struct cmd *self, int key)
{
char tmp[16];
self->args = args_create(0);
if (key >= '0' && key <= '9') {
xsnprintf(tmp, sizeof tmp, ":%d", key - '0');
args_set(self->args, 't', tmp);
}
if (key == ('n' | KEYC_ESCAPE) || key == ('p' | KEYC_ESCAPE))
args_set(self->args, 'a', NULL);
}
enum cmd_retval
cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_send_keys_entry = {
"lRt:", 0, -1,
"[-lR] " CMD_TARGET_PANE_USAGE " key ...",
0,
NULL,
cmd_send_keys_exec
};
@ -43,7 +42,6 @@ const struct cmd_entry cmd_send_prefix_entry = {
"2t:", 0, 0,
"[-2] " CMD_TARGET_PANE_USAGE,
0,
NULL,
cmd_send_keys_exec
};

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_set_buffer_entry = {
"ab:n:", 0, 1,
"[-a] " CMD_BUFFER_USAGE " [-n new-buffer-name] data",
0,
NULL,
cmd_set_buffer_exec
};

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_set_environment_entry = {
"grt:u", 1, 2,
"[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
0,
NULL,
cmd_set_environment_exec
};

View File

@ -69,7 +69,6 @@ const struct cmd_entry cmd_set_option_entry = {
"agoqst:uw", 1, 2,
"[-agosquw] [-t target-session|target-window] option [value]",
0,
NULL,
cmd_set_option_exec
};
@ -78,7 +77,6 @@ const struct cmd_entry cmd_set_window_option_entry = {
"agoqt:u", 1, 2,
"[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
0,
NULL,
cmd_set_option_exec
};

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_show_environment_entry = {
"gt:", 0, 1,
"[-g] " CMD_TARGET_SESSION_USAGE " [name]",
0,
NULL,
cmd_show_environment_exec
};

View File

@ -36,7 +36,6 @@ const struct cmd_entry cmd_show_messages_entry = {
"IJTt:", 0, 0,
"[-IJT] " CMD_TARGET_CLIENT_USAGE,
0,
NULL,
cmd_show_messages_exec
};
@ -45,7 +44,6 @@ const struct cmd_entry cmd_server_info_entry = {
"", 0, 0,
"",
0,
NULL,
cmd_show_messages_exec
};

View File

@ -39,7 +39,6 @@ const struct cmd_entry cmd_show_options_entry = {
"gqst:vw", 0, 1,
"[-gqsvw] [-t target-session|target-window] [option]",
0,
NULL,
cmd_show_options_exec
};
@ -48,7 +47,6 @@ const struct cmd_entry cmd_show_window_options_entry = {
"gvt:", 0, 1,
"[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
0,
NULL,
cmd_show_options_exec
};

View File

@ -36,7 +36,6 @@ const struct cmd_entry cmd_source_file_entry = {
"", 1, 1,
"path",
0,
NULL,
cmd_source_file_exec
};

View File

@ -31,7 +31,6 @@
* Split a window (add a new pane).
*/
void cmd_split_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_split_window_entry = {
@ -40,18 +39,9 @@ const struct cmd_entry cmd_split_window_entry = {
"[-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] "
CMD_TARGET_PANE_USAGE " [command]",
0,
cmd_split_window_key_binding,
cmd_split_window_exec
};
void
cmd_split_window_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == '%')
args_set(self->args, 'h', NULL);
}
enum cmd_retval
cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_suspend_client_entry = {
"t:", 0, 0,
CMD_TARGET_CLIENT_USAGE,
0,
NULL,
cmd_suspend_client_exec
};

View File

@ -26,7 +26,6 @@
* Swap two panes.
*/
void cmd_swap_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_swap_pane_entry = {
@ -34,20 +33,9 @@ const struct cmd_entry cmd_swap_pane_entry = {
"dDs:t:U", 0, 0,
"[-dDU] " CMD_SRCDST_PANE_USAGE,
0,
cmd_swap_pane_key_binding,
cmd_swap_pane_exec
};
void
cmd_swap_pane_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
if (key == '{')
args_set(self->args, 'U', NULL);
else if (key == '}')
args_set(self->args, 'D', NULL);
}
enum cmd_retval
cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -33,7 +33,6 @@ const struct cmd_entry cmd_swap_window_entry = {
"ds:t:", 0, 0,
"[-d] " CMD_SRCDST_WINDOW_USAGE,
0,
NULL,
cmd_swap_window_exec
};

View File

@ -27,7 +27,6 @@
* Switch client to a different session.
*/
void cmd_switch_client_key_binding(struct cmd *, int);
enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_switch_client_entry = {
@ -35,27 +34,9 @@ const struct cmd_entry cmd_switch_client_entry = {
"lc:npt:r", 0, 0,
"[-lnpr] [-c target-client] [-t target-session]",
CMD_READONLY,
cmd_switch_client_key_binding,
cmd_switch_client_exec
};
void
cmd_switch_client_key_binding(struct cmd *self, int key)
{
self->args = args_create(0);
switch (key) {
case '(':
args_set(self->args, 'p', NULL);
break;
case ')':
args_set(self->args, 'n', NULL);
break;
case 'L':
args_set(self->args, 'l', NULL);
break;
}
}
enum cmd_retval
cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
{

View File

@ -34,7 +34,6 @@ const struct cmd_entry cmd_unbind_key_entry = {
"acnt:", 0, 1,
"[-acn] [-t mode-table] key",
0,
NULL,
cmd_unbind_key_exec
};

View File

@ -31,7 +31,6 @@ const struct cmd_entry cmd_unlink_window_entry = {
"kt:", 0, 0,
"[-k] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
cmd_unlink_window_exec
};

View File

@ -35,7 +35,6 @@ const struct cmd_entry cmd_wait_for_entry = {
"LSU", 1, 1,
"[-L|-S|-U] channel",
0,
NULL,
cmd_wait_for_exec
};

View File

@ -84,107 +84,99 @@ key_bindings_remove(int key)
void
key_bindings_init(void)
{
static const struct {
int key;
int can_repeat;
const struct cmd_entry *entry;
} table[] = {
{ ' ', 0, &cmd_next_layout_entry },
{ '!', 0, &cmd_break_pane_entry },
{ '"', 0, &cmd_split_window_entry },
{ '#', 0, &cmd_list_buffers_entry },
{ '$', 0, &cmd_command_prompt_entry },
{ '%', 0, &cmd_split_window_entry },
{ '&', 0, &cmd_confirm_before_entry },
{ '(', 0, &cmd_switch_client_entry },
{ ')', 0, &cmd_switch_client_entry },
{ ',', 0, &cmd_command_prompt_entry },
{ '-', 0, &cmd_delete_buffer_entry },
{ '.', 0, &cmd_command_prompt_entry },
{ '0', 0, &cmd_select_window_entry },
{ '1', 0, &cmd_select_window_entry },
{ '2', 0, &cmd_select_window_entry },
{ '3', 0, &cmd_select_window_entry },
{ '4', 0, &cmd_select_window_entry },
{ '5', 0, &cmd_select_window_entry },
{ '6', 0, &cmd_select_window_entry },
{ '7', 0, &cmd_select_window_entry },
{ '8', 0, &cmd_select_window_entry },
{ '9', 0, &cmd_select_window_entry },
{ ':', 0, &cmd_command_prompt_entry },
{ ';', 0, &cmd_last_pane_entry },
{ '=', 0, &cmd_choose_buffer_entry },
{ '?', 0, &cmd_list_keys_entry },
{ 'D', 0, &cmd_choose_client_entry },
{ 'L', 0, &cmd_switch_client_entry },
{ '[', 0, &cmd_copy_mode_entry },
{ '\'', 0, &cmd_command_prompt_entry },
{ '\002', /* C-b */ 0, &cmd_send_prefix_entry },
{ '\017', /* C-o */ 0, &cmd_rotate_window_entry },
{ '\032', /* C-z */ 0, &cmd_suspend_client_entry },
{ ']', 0, &cmd_paste_buffer_entry },
{ 'c', 0, &cmd_new_window_entry },
{ 'd', 0, &cmd_detach_client_entry },
{ 'f', 0, &cmd_command_prompt_entry },
{ 'i', 0, &cmd_display_message_entry },
{ 'l', 0, &cmd_last_window_entry },
{ 'n', 0, &cmd_next_window_entry },
{ 'o', 0, &cmd_select_pane_entry },
{ 'p', 0, &cmd_previous_window_entry },
{ 'q', 0, &cmd_display_panes_entry },
{ 'r', 0, &cmd_refresh_client_entry },
{ 's', 0, &cmd_choose_tree_entry },
{ 't', 0, &cmd_clock_mode_entry },
{ 'w', 0, &cmd_choose_window_entry },
{ 'x', 0, &cmd_confirm_before_entry },
{ 'z', 0, &cmd_resize_pane_entry },
{ '{', 0, &cmd_swap_pane_entry },
{ '}', 0, &cmd_swap_pane_entry },
{ '~', 0, &cmd_show_messages_entry },
{ '1' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
{ '2' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
{ '3' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
{ '4' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
{ '5' | KEYC_ESCAPE, 0, &cmd_select_layout_entry },
{ KEYC_PPAGE, 0, &cmd_copy_mode_entry },
{ 'n' | KEYC_ESCAPE, 0, &cmd_next_window_entry },
{ 'o' | KEYC_ESCAPE, 0, &cmd_rotate_window_entry },
{ 'p' | KEYC_ESCAPE, 0, &cmd_previous_window_entry },
{ KEYC_UP, 1, &cmd_select_pane_entry },
{ KEYC_DOWN, 1, &cmd_select_pane_entry },
{ KEYC_LEFT, 1, &cmd_select_pane_entry },
{ KEYC_RIGHT, 1, &cmd_select_pane_entry },
{ KEYC_UP | KEYC_ESCAPE, 1, &cmd_resize_pane_entry },
{ KEYC_DOWN | KEYC_ESCAPE, 1, &cmd_resize_pane_entry },
{ KEYC_LEFT | KEYC_ESCAPE, 1, &cmd_resize_pane_entry },
{ KEYC_RIGHT | KEYC_ESCAPE, 1, &cmd_resize_pane_entry },
{ KEYC_UP | KEYC_CTRL, 1, &cmd_resize_pane_entry },
{ KEYC_DOWN | KEYC_CTRL, 1, &cmd_resize_pane_entry },
{ KEYC_LEFT | KEYC_CTRL, 1, &cmd_resize_pane_entry },
{ KEYC_RIGHT | KEYC_CTRL, 1, &cmd_resize_pane_entry },
static const char* defaults[] = {
"bind C-b send-prefix",
"bind C-o rotate-window",
"bind C-z suspend-client",
"bind Space next-layout",
"bind ! break-pane",
"bind '\"' split-window",
"bind '#' list-buffers",
"bind '$' command-prompt -I'#S' \"rename-session '%%'\"",
"bind % split-window -h",
"bind & confirm-before -p\"kill-window #W? (y/n)\" kill-window",
"bind \"'\" command-prompt -pindex \"select-window -t ':%%'\"",
"bind ( switch-client -p",
"bind ) switch-client -n",
"bind , command-prompt -I'#W' \"rename-window '%%'\"",
"bind - delete-buffer",
"bind . command-prompt \"move-window -t '%%'\"",
"bind 0 select-window -t:0",
"bind 1 select-window -t:1",
"bind 2 select-window -t:2",
"bind 3 select-window -t:3",
"bind 4 select-window -t:4",
"bind 5 select-window -t:5",
"bind 6 select-window -t:6",
"bind 7 select-window -t:7",
"bind 8 select-window -t:8",
"bind 9 select-window -t:9",
"bind : command-prompt",
"bind \\; last-pane",
"bind = choose-buffer",
"bind ? list-keys",
"bind D choose-client",
"bind L switch-client -l",
"bind [ copy-mode",
"bind ] paste-buffer",
"bind c new-window",
"bind d detach-client",
"bind f command-prompt \"find-window '%%'\"",
"bind i display-message",
"bind l last-window",
"bind n next-window",
"bind o select-pane -t:.+",
"bind p previous-window",
"bind q display-panes",
"bind r refresh-client",
"bind s choose-tree",
"bind t clock-mode",
"bind w choose-window",
"bind x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
"bind z resize-pane -Z",
"bind { swap-pane -U",
"bind } swap-pane -D",
"bind '~' show-messages",
"bind PPage copy-mode -u",
"bind -r Up select-pane -U",
"bind -r Down select-pane -D",
"bind -r Left select-pane -L",
"bind -r Right select-pane -R",
"bind M-1 select-layout even-horizontal",
"bind M-2 select-layout even-vertical",
"bind M-3 select-layout main-horizontal",
"bind M-4 select-layout main-vertical",
"bind M-5 select-layout tiled",
"bind M-n next-window -a",
"bind M-o rotate-window -D",
"bind M-p previous-window -a",
"bind -r M-Up resize-pane -U 5",
"bind -r M-Down resize-pane -D 5",
"bind -r M-Left resize-pane -L 5",
"bind -r M-Right resize-pane -R 5",
"bind -r C-Up resize-pane -U",
"bind -r C-Down resize-pane -D",
"bind -r C-Left resize-pane -L",
"bind -r C-Right resize-pane -R",
};
u_int i;
struct cmd *cmd;
struct cmd_list *cmdlist;
char* cause;
int error;
struct cmd_q *cmdq;
RB_INIT(&key_bindings);
for (i = 0; i < nitems(table); i++) {
cmdlist = xcalloc(1, sizeof *cmdlist);
cmdlist->references = 1;
TAILQ_INIT(&cmdlist->list);
cmd = xcalloc(1, sizeof *cmd);
cmd->entry = table[i].entry;
if (cmd->entry->key_binding != NULL)
cmd->entry->key_binding(cmd, table[i].key);
else
cmd->args = args_create(0);
TAILQ_INSERT_HEAD(&cmdlist->list, cmd, qentry);
key_bindings_add(
table[i].key | KEYC_PREFIX, table[i].can_repeat, cmdlist);
cmdq = cmdq_new (NULL);
for (i = 0; i < nitems(defaults); i++) {
error = cmd_string_parse(defaults[i], &cmdlist,
"<default-keys>", i, &cause);
if (error != 0)
fatalx("bad default key");
cmdq_run (cmdq, cmdlist);
cmd_list_free (cmdlist);
}
cmdq_free (cmdq);
}
void

1
tmux.h
View File

@ -1492,7 +1492,6 @@ struct cmd_entry {
#define CMD_READONLY 0x4
int flags;
void (*key_binding)(struct cmd *, int);
enum cmd_retval (*exec)(struct cmd *, struct cmd_q *);
};