2 * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of California, Berkeley nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef _CMDLINE_VT100_H_
29 #define _CMDLINE_VT100_H_
31 #define vt100_bell "\007"
32 #define vt100_bs "\010"
33 #define vt100_bs_clear "\010 \010"
34 #define vt100_tab "\011"
35 #define vt100_crnl "\012\015"
36 #define vt100_clear_right "\033[0K"
37 #define vt100_clear_left "\033[1K"
38 #define vt100_clear_down "\033[0J"
39 #define vt100_clear_up "\033[1J"
40 #define vt100_clear_line "\033[2K"
41 #define vt100_clear_screen "\033[2J"
42 #define vt100_up_arr "\033\133\101"
43 #define vt100_down_arr "\033\133\102"
44 #define vt100_right_arr "\033\133\103"
45 #define vt100_left_arr "\033\133\104"
46 #define vt100_multi_right "\033\133%uC"
47 #define vt100_multi_left "\033\133%uD"
48 #define vt100_suppr "\033\133\063\176"
49 #define vt100_home "\033M\033E"
50 #define vt100_word_left "\033\142"
51 #define vt100_word_right "\033\146"
54 /* Result of parsing : it must be synchronized with
55 * cmdline_vt100_commands[] in vt100.c */
56 #define CMDLINE_KEY_UP_ARR 0
57 #define CMDLINE_KEY_DOWN_ARR 1
58 #define CMDLINE_KEY_RIGHT_ARR 2
59 #define CMDLINE_KEY_LEFT_ARR 3
60 #define CMDLINE_KEY_BKSPACE 4
61 #define CMDLINE_KEY_RETURN 5
62 #define CMDLINE_KEY_CTRL_A 6
63 #define CMDLINE_KEY_CTRL_E 7
64 #define CMDLINE_KEY_CTRL_K 8
65 #define CMDLINE_KEY_CTRL_Y 9
66 #define CMDLINE_KEY_CTRL_C 10
67 #define CMDLINE_KEY_CTRL_F 11
68 #define CMDLINE_KEY_CTRL_B 12
69 #define CMDLINE_KEY_SUPPR 13
70 #define CMDLINE_KEY_TAB 14
71 #define CMDLINE_KEY_CTRL_D 15
72 #define CMDLINE_KEY_CTRL_L 16
73 #define CMDLINE_KEY_RETURN2 17
74 #define CMDLINE_KEY_META_BKSPACE 18
75 #define CMDLINE_KEY_WLEFT 19
76 #define CMDLINE_KEY_WRIGHT 20
77 #define CMDLINE_KEY_HELP 21
79 extern const char *cmdline_vt100_commands[];
81 enum cmdline_vt100_parser_state {
84 CMDLINE_VT100_ESCAPE_CSI,
87 #define CMDLINE_VT100_BUF_SIZE 8
88 struct cmdline_vt100 {
90 char buf[CMDLINE_VT100_BUF_SIZE];
91 enum cmdline_vt100_parser_state state;
97 void vt100_init(struct cmdline_vt100 *vt);
100 * Input a new character.
101 * Return -1 if the character is not part of a control sequence
102 * Return -2 if c is not the last char of a control sequence
103 * Else return the index in vt100_commands[]
105 int vt100_parser(struct cmdline_vt100 *vt, char c);