version 1.25, 2014/10/20 23:27:14 |
version 1.26, 2015/04/20 15:34:56 |
|
|
|
|
const struct cmd_entry cmd_list_keys_entry = { |
const struct cmd_entry cmd_list_keys_entry = { |
"list-keys", "lsk", |
"list-keys", "lsk", |
"t:", 0, 0, |
"t:T:", 0, 0, |
"[-t key-table]", |
"[-t mode-table] [-T key-table]", |
0, |
0, |
cmd_list_keys_exec |
cmd_list_keys_exec |
}; |
}; |
|
|
cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) |
cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
|
struct key_table *table; |
struct key_binding *bd; |
struct key_binding *bd; |
const char *key; |
const char *key, *tablename, *r; |
char tmp[BUFSIZ], flags[8]; |
char tmp[BUFSIZ]; |
size_t used; |
size_t used; |
int width, keywidth; |
int repeat, width, tablewidth, keywidth; |
|
|
if (self->entry == &cmd_list_commands_entry) |
if (self->entry == &cmd_list_commands_entry) |
return (cmd_list_keys_commands(self, cmdq)); |
return (cmd_list_keys_commands(self, cmdq)); |
|
|
if (args_has(args, 't')) |
if (args_has(args, 't')) |
return (cmd_list_keys_table(self, cmdq)); |
return (cmd_list_keys_table(self, cmdq)); |
|
|
width = 0; |
tablename = args_get(args, 'T'); |
|
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) { |
|
cmdq_error(cmdq, "table %s doesn't exist", tablename); |
|
return (CMD_RETURN_ERROR); |
|
} |
|
|
RB_FOREACH(bd, key_bindings, &key_bindings) { |
repeat = 0; |
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX); |
tablewidth = keywidth = 0; |
if (key == NULL) |
RB_FOREACH(table, key_tables, &key_tables) { |
|
if (tablename != NULL && strcmp(table->name, tablename) != 0) |
continue; |
continue; |
|
RB_FOREACH(bd, key_bindings, &table->key_bindings) { |
|
key = key_string_lookup_key(bd->key); |
|
if (key == NULL) |
|
continue; |
|
|
keywidth = strlen(key); |
|
if (!(bd->key & KEYC_PREFIX)) { |
|
if (bd->can_repeat) |
if (bd->can_repeat) |
keywidth += 4; |
repeat = 1; |
else |
|
keywidth += 3; |
width = strlen(table->name); |
} else if (bd->can_repeat) |
if (width > tablewidth) |
keywidth += 3; |
tablewidth =width; |
if (keywidth > width) |
width = strlen(key); |
width = keywidth; |
if (width > keywidth) |
|
keywidth = width; |
|
} |
} |
} |
|
|
RB_FOREACH(bd, key_bindings, &key_bindings) { |
RB_FOREACH(table, key_tables, &key_tables) { |
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX); |
if (tablename != NULL && strcmp(table->name, tablename) != 0) |
if (key == NULL) |
|
continue; |
continue; |
|
RB_FOREACH(bd, key_bindings, &table->key_bindings) { |
|
key = key_string_lookup_key(bd->key); |
|
if (key == NULL) |
|
continue; |
|
|
*flags = '\0'; |
if (!repeat) |
if (!(bd->key & KEYC_PREFIX)) { |
r = ""; |
if (bd->can_repeat) |
else if (bd->can_repeat) |
xsnprintf(flags, sizeof flags, "-rn "); |
r = "-r "; |
else |
else |
xsnprintf(flags, sizeof flags, "-n "); |
r = " "; |
} else if (bd->can_repeat) |
used = xsnprintf(tmp, sizeof tmp, "%s-T %-*s %-*s ", r, |
xsnprintf(flags, sizeof flags, "-r "); |
(int)tablewidth, table->name, (int)keywidth, key); |
|
if (used < sizeof tmp) { |
|
cmd_list_print(bd->cmdlist, tmp + used, |
|
(sizeof tmp) - used); |
|
} |
|
|
used = xsnprintf(tmp, sizeof tmp, "%s%*s ", |
cmdq_print(cmdq, "bind-key %s", tmp); |
flags, (int) (width - strlen(flags)), key); |
} |
if (used >= sizeof tmp) |
|
continue; |
|
|
|
cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used); |
|
cmdq_print(cmdq, "bind-key %s", tmp); |
|
} |
} |
|
|
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |