CNDP  22.08.0
cli_vt100.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2019-2022 Intel Corporation.
3  */
4 
5 #ifndef __CLI_VT100_H_
6 #define __CLI_VT100_H_
7 
13 // IWYU pragma: no_include <bits/termios-struct.h>
14 
15 #include <stdarg.h> // for va_end, va_list, va_start
16 #include <stdint.h> // for uint8_t
17 #include <stdio.h> // for fileno, fprintf, stderr, stdin, stdout
18 #include <string.h> // for strlen
19 #include <termios.h>
20 #include <unistd.h> // for read, write
21 #include <cne_atomic.h> // for atomic_exchange, atomic_int_least32_t, atomic...
22 #include <cne_common.h> // for CNDP_API
23 #include <cne_stdio.h> // for ESC
24 #include <cne_system.h>
25 #include <cne_tty.h>
26 #include <vt100_out.h> // for ESC
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #define VT100_INITIALIZE -1
33 
34 #define vt100_open_square '['
35 #define vt100_escape 0x1b
36 #define vt100_del 0x7f
37 
38 /* Key codes */
39 #define vt100_word_left ESC "b"
40 #define vt100_word_right ESC "f"
41 #define vt100_suppr ESC "[3~"
42 #define vt100_tab "\011"
43 
44 /* Action codes for cli_vt100 */
45 #define vt100_bell "\007"
46 #define vt100_bs "\010"
47 #define vt100_bs_clear "\b \b"
48 
49 /* Result of parsing : it must be synchronized with
50  * vt100_commands[] in vt100_keys.c */
51 enum {
52  VT100_INVALID_KEY = 0,
53  VT100_KEY_UP_ARR,
54  VT100_KEY_DOWN_ARR,
55  VT100_KEY_RIGHT_ARR,
56  VT100_KEY_LEFT_ARR,
57  VT100_KEY_BKSPACE,
58  VT100_KEY_RETURN,
59  VT100_KEY_CTRL_A,
60  VT100_KEY_CTRL_E,
61  VT100_KEY_CTRL_K,
62  VT100_KEY_CTRL_Y,
63  VT100_KEY_CTRL_C,
64  VT100_KEY_CTRL_F,
65  VT100_KEY_CTRL_B,
66  VT100_KEY_SUPPR,
67  VT100_KEY_TAB,
68  VT100_KEY_CTRL_D,
69  VT100_KEY_CTRL_L,
70  VT100_KEY_RETURN2,
71  VT100_KEY_META_BKSPACE,
72  VT100_KEY_WLEFT,
73  VT100_KEY_WRIGHT,
74  VT100_KEY_CTRL_W,
75  VT100_KEY_CTRL_P,
76  VT100_KEY_CTRL_N,
77  VT100_KEY_META_D,
78  VT100_KEY_CTRL_X,
79  VT100_MAX_KEYS
80 };
81 
82 extern const char *vt100_commands[];
83 
84 enum vt100_parse_state {
85  VT100_INIT,
86  VT100_ESCAPE,
87  VT100_ESCAPE_CSI,
88  VT100_DONE = -1,
89  VT100_CONTINUE = -2
90 };
91 
92 #define VT100_BUF_SIZE 8
93 struct cli_vt100 {
94  int bufpos;
95  char buf[VT100_BUF_SIZE];
96  enum vt100_parse_state state;
97 };
98 
99 struct vt100_cmds {
100  const char *str;
101  void (*func)(void);
102 };
103 
110 CNDP_API struct cli_vt100 *vt100_setup(void);
111 
118 CNDP_API void vt100_free(struct cli_vt100 *vt);
119 
132 CNDP_API int vt100_parse_input(struct cli_vt100 *vt, uint8_t c);
133 
140 CNDP_API void vt100_do_cmd(int idx);
141 
148 CNDP_API struct vt100_cmds *vt100_get_cmds(void);
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif /* __CLI_SCRN_H_ */
CNDP_API void vt100_do_cmd(int idx)
CNDP_API int vt100_parse_input(struct cli_vt100 *vt, uint8_t c)
CNDP_API struct cli_vt100 * vt100_setup(void)
CNDP_API void vt100_free(struct cli_vt100 *vt)
CNDP_API struct vt100_cmds * vt100_get_cmds(void)