CNDP  22.08.0
cne_tty.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 __CNE_TTY_H_
6 #define __CNE_TTY_H_
7 
16 // IWYU pragma: no_include <bits/termios-struct.h>
17 
18 #include <termios.h>
19 #include <signal.h> // for sigaction
20 #include <stdarg.h> // for va_list
21 #include <stdint.h> // for uint16_t
22 #include <stdio.h> // for FILE
23 #include <string.h> // for strlen
24 #include <unistd.h> // for read, write
25 #include <cne_atomic.h> // for CNE_ATOMIC
26 #include <cne_common.h>
27 #include <cne_system.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #define TTY_BUFF_SIZE 1024
34 #define TTY_MAX_CMD_SIZE 16
35 
36 typedef union {
37  int val;
38  struct {
39  uint16_t nrows;
40  uint16_t ncols;
41  };
42 } tty_wsize_t;
43 
45 typedef struct {
46  int flags;
47  int fd_out;
48  int fd_in;
49  struct sigaction saved_action;
50  CNE_ATOMIC(uint_fast16_t) winsz;
51  tty_wsize_t wsize;
52  struct termios oldterm;
53  CNE_ATOMIC(int_least32_t) pause;
54 } cne_tty_t;
55 
56 enum {
57  TTY_IS_INITED = (1 << 0),
58  TTY_IS_A_TTY = (1 << 1),
59  TTY_COLOR_ON = (1 << 2),
60  TTY_WS_CHANGED = (1 << 8),
61 };
62 
63 extern cne_tty_t *this_tty;
64 
75 CNDP_API int tty_setup(int fd_in, int fd_out);
76 
80 CNDP_API void tty_destroy(void);
81 
85 CNDP_API void tty_enable_color(void);
86 
90 CNDP_API void tty_disable_color(void);
91 
98 CNDP_API int tty_is_color_on(void);
99 
106 CNDP_API int tty_is_inited(void);
107 
111 CNDP_API void tty_set_wchanged(void);
112 
116 CNDP_API void tty_clear_wchanged(void);
117 
126 CNDP_API int tty_did_wchange(void);
127 
134 CNDP_API tty_wsize_t *tty_window_size(void);
135 
139 CNDP_API int tty_num_rows(void);
140 
144 CNDP_API int tty_num_columns(void);
145 
160 CNDP_API int tty_poll(char *buf, int len, int timeout);
161 
172 CNDP_API int tty_write(const char *buf, int len);
173 
186 CNDP_API int tty_dwrite(int fd, const char *buf, int len);
187 
200 CNDP_API int tty_fwrite(FILE *f, const char *buf, int len);
201 
212 CNDP_API int tty_read(char *buf, int len);
213 
226 CNDP_API int tty_dread(int fd, char *buf, int len);
227 
240 CNDP_API int tty_fread(FILE *f, char *buf, int len);
241 
248 CNDP_API int tty_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
249 
258 CNDP_API int tty_fprintf(FILE *f, const char *fmt, ...) __attribute__((format(printf, 2, 0)));
259 
270 CNDP_API int tty_vprintf(const char *fmt, va_list ap) __attribute__((format(printf, 1, 0)));
271 
284 CNDP_API int tty_vfprintf(FILE *f, const char *fmt, va_list ap)
285  __attribute__((format(printf, 2, 0)));
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 
291 #endif /* __CNE_TTY_H_ */
CNDP_API tty_wsize_t * tty_window_size(void)
CNDP_API int tty_setup(int fd_in, int fd_out)
CNDP_API int tty_vfprintf(FILE *f, const char *fmt, va_list ap)
CNDP_API int tty_fread(FILE *f, char *buf, int len)
CNDP_API int tty_poll(char *buf, int len, int timeout)
CNDP_API int tty_num_rows(void)
CNDP_API int tty_vprintf(const char *fmt, va_list ap)
CNDP_API void tty_clear_wchanged(void)
CNDP_API int tty_num_columns(void)
CNDP_API int tty_fprintf(FILE *f, const char *fmt,...)
CNDP_API int tty_is_inited(void)
CNDP_API void tty_destroy(void)
CNDP_API int tty_printf(const char *fmt,...)
CNDP_API void tty_enable_color(void)
CNDP_API void tty_set_wchanged(void)
CNDP_API int tty_is_color_on(void)
CNDP_API int tty_read(char *buf, int len)
CNDP_API int tty_write(const char *buf, int len)
CNDP_API int tty_dread(int fd, char *buf, int len)
CNDP_API void tty_disable_color(void)
CNDP_API int tty_dwrite(int fd, const char *buf, int len)
CNDP_API int tty_did_wchange(void)
CNDP_API int tty_fwrite(FILE *f, const char *buf, int len)
CNE_ATOMIC(int_least32_t) pause
int fd_out
Definition: cne_tty.h:47
int fd_in
Definition: cne_tty.h:48
CNE_ATOMIC(uint_fast16_t) winsz
int flags
Definition: cne_tty.h:46