Add :exec prompt command and inline test commands that uses key bindings
[tig.git] / include / tig / keys.h
blobda3d7b7a84c5c8ca9c7dc2617e51fe5716da78ef
1 /* Copyright (c) 2006-2014 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #ifndef TIG_KEYS_H
15 #define TIG_KEYS_H
17 #include "tig/tig.h"
18 #include "tig/request.h"
19 #include "tig/util.h"
22 * Keys
25 struct keybinding;
27 struct keymap {
28 const char *name;
29 struct keybinding **data;
30 size_t size;
31 bool hidden;
34 struct key {
35 union {
36 int value;
37 char bytes[7];
38 } data;
39 struct {
40 bool escape:1;
41 bool control:1;
42 bool multibytes:1;
43 } modifiers;
46 static inline unsigned long
47 key_to_unicode(struct key *key)
49 return key->modifiers.multibytes
50 ? utf8_to_unicode(key->data.bytes, strlen(key->data.bytes))
51 : 0;
54 struct keymap *get_keymap(const char *name, size_t namelen);
55 struct keymap *get_keymap_by_index(int i);
57 const char *get_key_name(const struct key key[], size_t keys);
58 enum status_code get_key_value(const char **name, struct key *key);
60 /* Looks for a key binding first in the given map, then in the generic map, and
61 * lastly in the default keybindings. */
62 enum request get_keybinding(struct keymap *keymap, struct key key[], size_t keys);
63 enum status_code add_keybinding(struct keymap *table, enum request request, struct key key[], size_t keys);
65 const char *get_keys(struct keymap *keymap, enum request request, bool all);
66 #define get_view_key(view, request) get_keys((view)->keymap, request, FALSE)
68 struct run_request_flags {
69 bool silent;
70 bool confirm;
71 bool exit;
72 bool internal;
75 struct run_request {
76 struct keymap *keymap;
77 struct run_request_flags flags;
78 const char **argv;
81 struct run_request *get_run_request(enum request request);
82 enum status_code add_run_request(struct keymap *keymap, struct key key[], size_t keys, const char **argv);
83 enum status_code parse_run_request_flags(struct run_request_flags *flags, const char **argv);
85 #endif
86 /* vim: set ts=8 sw=8 noexpandtab: */