1 /* 2 * GNT - The GLib Ncurses Toolkit 3 * 4 * GNT is the legal property of its developers, whose names are too numerous 5 * to list here. Please refer to the COPYRIGHT file distributed with this 6 * source distribution. 7 * 8 * This library is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 21 */ 22 23 #ifndef GNT_KEYS_H 24 #define GNT_KEYS_H 25 /** 26 * SECTION:gntkeys 27 * @section_id: libgnt-gntkeys 28 * @title: Keys 29 * @short_description: Key value lookup and transformation 30 */ 31 32 #include <curses.h> 33 #include <term.h> 34 35 /* 36 * terminfo/termcap doesn't provide all the information that I want to use, eg. 37 * ctrl-up, ctrl-down etc. So I am going to hard-code some of the information 38 * for some popular $TERMs 39 */ 40 extern char *gnt_key_cup; 41 extern char *gnt_key_cdown; 42 extern char *gnt_key_cleft; 43 extern char *gnt_key_cright; 44 45 #define SAFE(x) ((cur_term && (x)) ? (x) : "") 46 47 #define GNT_KEY_POPUP SAFE(key_f16) /* Apparently */ 48 49 /* Arrow keys */ 50 #define GNT_KEY_LEFT SAFE(key_left) 51 #define GNT_KEY_RIGHT SAFE(key_right) 52 #define GNT_KEY_UP SAFE(key_up) 53 #define GNT_KEY_DOWN SAFE(key_down) 54 55 #define GNT_KEY_CTRL_UP SAFE(gnt_key_cup) 56 #define GNT_KEY_CTRL_DOWN SAFE(gnt_key_cdown) 57 #define GNT_KEY_CTRL_RIGHT SAFE(gnt_key_cright) 58 #define GNT_KEY_CTRL_LEFT SAFE(gnt_key_cleft) 59 60 #define GNT_KEY_PGUP SAFE(key_ppage) 61 #define GNT_KEY_PGDOWN SAFE(key_npage) 62 #define GNT_KEY_HOME SAFE(key_home) 63 #define GNT_KEY_END SAFE(key_end) 64 65 #define GNT_KEY_ENTER SAFE(carriage_return) 66 67 #define GNT_KEY_BACKSPACE SAFE(key_backspace) 68 #define GNT_KEY_DEL SAFE(key_dc) 69 #define GNT_KEY_INS SAFE(key_ic) 70 #define GNT_KEY_BACK_TAB ((cur_term && back_tab) ? back_tab : SAFE(key_btab)) 71 72 #define GNT_KEY_CTRL_A "\001" 73 #define GNT_KEY_CTRL_B "\002" 74 #define GNT_KEY_CTRL_D "\004" 75 #define GNT_KEY_CTRL_E "\005" 76 #define GNT_KEY_CTRL_F "\006" 77 #define GNT_KEY_CTRL_G "\007" 78 #define GNT_KEY_CTRL_H "\010" 79 #define GNT_KEY_CTRL_I "\011" 80 #define GNT_KEY_CTRL_J "\012" 81 #define GNT_KEY_CTRL_K "\013" 82 #define GNT_KEY_CTRL_L "\014" 83 #define GNT_KEY_CTRL_M "\012" 84 #define GNT_KEY_CTRL_N "\016" 85 #define GNT_KEY_CTRL_O "\017" 86 #define GNT_KEY_CTRL_P "\020" 87 #define GNT_KEY_CTRL_R "\022" 88 #define GNT_KEY_CTRL_T "\024" 89 #define GNT_KEY_CTRL_U "\025" 90 #define GNT_KEY_CTRL_V "\026" 91 #define GNT_KEY_CTRL_W "\027" 92 #define GNT_KEY_CTRL_X "\030" 93 #define GNT_KEY_CTRL_Y "\031" 94 95 #define GNT_KEY_F1 SAFE(key_f1) 96 #define GNT_KEY_F2 SAFE(key_f2) 97 #define GNT_KEY_F3 SAFE(key_f3) 98 #define GNT_KEY_F4 SAFE(key_f4) 99 #define GNT_KEY_F5 SAFE(key_f5) 100 #define GNT_KEY_F6 SAFE(key_f6) 101 #define GNT_KEY_F7 SAFE(key_f7) 102 #define GNT_KEY_F8 SAFE(key_f8) 103 #define GNT_KEY_F9 SAFE(key_f9) 104 #define GNT_KEY_F10 SAFE(key_f10) 105 #define GNT_KEY_F11 SAFE(key_f11) 106 #define GNT_KEY_F12 SAFE(key_f12) 107 108 /** 109 * gnt_init_keys: 110 * 111 * Initialize the keys. 112 */ 113 void gnt_init_keys(void); 114 115 /** 116 * gnt_keys_refine: 117 * @text: The input text to refine. 118 * 119 * Refine input text. This usually looks at what the terminal claims it is, 120 * and tries to change the text to work around some oft-broken terminfo entries. 121 */ 122 void gnt_keys_refine(char *text); 123 124 /** 125 * gnt_key_translate: 126 * @name: The user-readable representation of an input (eg.: c-t) 127 * 128 * Translate a user-readable representation of an input to a machine-readable representation. 129 * 130 * Returns: A machine-readable representation of the input. 131 */ 132 const char *gnt_key_translate(const char *name); 133 134 /** 135 * gnt_key_lookup: 136 * @key: The machine-readable representation of an input. 137 * 138 * Translate a machine-readable representation of an input to a user-readable representation. 139 * 140 * Returns: A user-readable representation of the input (eg.: c-t). 141 */ 142 const char *gnt_key_lookup(const char *key); 143 144 /** 145 * gnt_keys_add_combination: 146 * @key: The key to add 147 * 148 * Add a key combination to the internal key-tree. 149 */ 150 void gnt_keys_add_combination(const char *key); 151 152 /** 153 * gnt_keys_del_combination: 154 * @key: The key to remove. 155 * 156 * Remove a key combination from the internal key-tree. 157 */ 158 void gnt_keys_del_combination(const char *key); 159 160 /** 161 * gnt_keys_find_combination: 162 * @key: The input string. 163 * 164 * Find a combination from the given string. 165 * 166 * Returns: The number of bytes in the combination that starts at the beginning 167 * of key (can be 0). 168 */ 169 int gnt_keys_find_combination(const char *key); 170 171 /* A lot of commonly used variable names are defined in <term.h>. 172 * #undef them to make life easier for everyone. */ 173 174 #undef columns 175 #undef lines 176 #undef buttons 177 #undef newline 178 #undef set_clock 179 180 #endif 181