Added copyright notices to files
[apps/madtty.git] / rote_keymap.c
1 /*
2 LICENSE INFORMATION:
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License (LGPL) as published by the Free Software Foundation.
6
7 Please refer to the COPYING file for more information.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17
18 Copyright (c) 2004 Bruno T. C. de Oliveira
19 */
20
21
22 #include "rote.h"
23
24 #include <ncurses.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 static const char *keytable[KEY_MAX+1];
29 static int initialized = 0;
30
31 static void keytable_init();
32
33 void rote_vt_keypress(RoteTerm *rt, int keycode) {
34    char c = (char) keycode;
35
36    if (!initialized) keytable_init();
37
38    if (keycode >= 0 && keycode < KEY_MAX && keytable[keycode])
39       rote_vt_write(rt, keytable[keycode], strlen(keytable[keycode]));
40    else
41       rote_vt_write(rt, &c, 1); /* not special, just write it */
42 }
43
44 static void keytable_init() {
45    initialized = 1;
46    memset(keytable, 0, KEY_MAX+1 * sizeof(const char*));
47
48    keytable['\n']          = "\r";
49    keytable[KEY_UP]        = "\e[A";
50    keytable[KEY_DOWN]      = "\e[B";
51    keytable[KEY_RIGHT]     = "\e[C";
52    keytable[KEY_LEFT]      = "\e[D";
53    keytable[KEY_BACKSPACE] = "\b";
54    keytable[KEY_HOME]      = "\e[1~";
55    keytable[KEY_IC]        = "\e[2~";
56    keytable[KEY_DC]        = "\e[3~";
57    keytable[KEY_END]       = "\e[4~";
58    keytable[KEY_PPAGE]     = "\e[5~";
59    keytable[KEY_NPAGE]     = "\e[6~";
60    keytable[KEY_SUSPEND]   = "\x1A";  /* Ctrl+Z gets mapped to this */
61    keytable[KEY_F(1)]      = "\e[[A";
62    keytable[KEY_F(2)]      = "\e[[B";
63    keytable[KEY_F(3)]      = "\e[[C";
64    keytable[KEY_F(4)]      = "\e[[D";
65    keytable[KEY_F(5)]      = "\e[[E";
66    keytable[KEY_F(6)]      = "\e[17~";
67    keytable[KEY_F(7)]      = "\e[18~";
68    keytable[KEY_F(8)]      = "\e[19~";
69    keytable[KEY_F(9)]      = "\e[20~";
70    keytable[KEY_F(10)]     = "\e[21~";
71 }
72
73