Use DECSLRM and DECFRA on terminals pretending to be VT520 or VT525 as
[tmux.git] / cmd-unbind-key.c
blob6d91d7cca139c973767676fe8cb6a77658d5491d
1 /* $OpenBSD$ */
3 /*
4 * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
21 #include <stdlib.h>
23 #include "tmux.h"
26 * Unbind key from command.
29 static enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmdq_item *);
31 const struct cmd_entry cmd_unbind_key_entry = {
32 .name = "unbind-key",
33 .alias = "unbind",
35 .args = { "anqT:", 0, 1, NULL },
36 .usage = "[-anq] [-T key-table] key",
38 .flags = CMD_AFTERHOOK,
39 .exec = cmd_unbind_key_exec
42 static enum cmd_retval
43 cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
45 struct args *args = cmd_get_args(self);
46 key_code key;
47 const char *tablename, *keystr = args_string(args, 0);
48 int quiet = args_has(args, 'q');
50 if (args_has(args, 'a')) {
51 if (keystr != NULL) {
52 if (!quiet)
53 cmdq_error(item, "key given with -a");
54 return (CMD_RETURN_ERROR);
57 tablename = args_get(args, 'T');
58 if (tablename == NULL) {
59 if (args_has(args, 'n'))
60 tablename = "root";
61 else
62 tablename = "prefix";
64 if (key_bindings_get_table(tablename, 0) == NULL) {
65 if (!quiet) {
66 cmdq_error(item, "table %s doesn't exist" ,
67 tablename);
69 return (CMD_RETURN_ERROR);
72 key_bindings_remove_table(tablename);
73 return (CMD_RETURN_NORMAL);
76 if (keystr == NULL) {
77 if (!quiet)
78 cmdq_error(item, "missing key");
79 return (CMD_RETURN_ERROR);
82 key = key_string_lookup_string(keystr);
83 if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
84 if (!quiet)
85 cmdq_error(item, "unknown key: %s", keystr);
86 return (CMD_RETURN_ERROR);
89 if (args_has(args, 'T')) {
90 tablename = args_get(args, 'T');
91 if (key_bindings_get_table(tablename, 0) == NULL) {
92 if (!quiet) {
93 cmdq_error(item, "table %s doesn't exist" ,
94 tablename);
96 return (CMD_RETURN_ERROR);
98 } else if (args_has(args, 'n'))
99 tablename = "root";
100 else
101 tablename = "prefix";
102 key_bindings_remove(tablename, key);
103 return (CMD_RETURN_NORMAL);