1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2020 Dmitry Kozlyuk 3 */ 4 5 #ifndef _CMDLINE_PRIVATE_H_ 6 #define _CMDLINE_PRIVATE_H_ 7 8 #include <stdarg.h> 9 10 #include <rte_common.h> 11 #include <rte_os_shim.h> 12 #ifdef RTE_EXEC_ENV_WINDOWS 13 #include <rte_windows.h> 14 #else 15 #include <termios.h> 16 #endif 17 18 #include <cmdline.h> 19 20 #define RDLINE_BUF_SIZE 512 21 #define RDLINE_PROMPT_SIZE 32 22 #define RDLINE_VT100_BUF_SIZE 8 23 #define RDLINE_HISTORY_BUF_SIZE BUFSIZ 24 #define RDLINE_HISTORY_MAX_LINE 64 25 26 struct rdline { 27 volatile enum rdline_status status; 28 /* rdline bufs */ 29 struct cirbuf left; 30 struct cirbuf right; 31 char left_buf[RDLINE_BUF_SIZE+2]; /* reserve 2 chars for the \n\0 */ 32 char right_buf[RDLINE_BUF_SIZE]; 33 34 char prompt[RDLINE_PROMPT_SIZE]; 35 unsigned int prompt_size; 36 37 char kill_buf[RDLINE_BUF_SIZE]; 38 unsigned int kill_size; 39 40 /* history */ 41 struct cirbuf history; 42 char history_buf[RDLINE_HISTORY_BUF_SIZE]; 43 int history_cur_line; 44 45 /* callbacks and func pointers */ 46 rdline_write_char_t *write_char; 47 rdline_validate_t *validate; 48 rdline_complete_t *complete; 49 50 /* vt100 parser */ 51 struct cmdline_vt100 vt100; 52 53 /* opaque pointer */ 54 void *opaque; 55 }; 56 57 #ifdef RTE_EXEC_ENV_WINDOWS 58 struct terminal { 59 DWORD input_mode; 60 DWORD output_mode; 61 int is_console_input; 62 int is_console_output; 63 }; 64 #endif 65 66 struct cmdline { 67 int s_in; 68 int s_out; 69 cmdline_parse_ctx_t *ctx; 70 struct rdline rdl; 71 char prompt[RDLINE_PROMPT_SIZE]; 72 #ifdef RTE_EXEC_ENV_WINDOWS 73 struct terminal oldterm; 74 char repeated_char; 75 WORD repeat_count; 76 #else 77 struct termios oldterm; 78 #endif 79 }; 80 81 /* Disable buffering and echoing, save previous settings to oldterm. */ 82 void terminal_adjust(struct cmdline *cl); 83 84 /* Restore terminal settings form oldterm. */ 85 void terminal_restore(const struct cmdline *cl); 86 87 /* Read one character from input. */ 88 ssize_t cmdline_read_char(struct cmdline *cl, char *c); 89 90 /* Force current cmdline read to unblock. */ 91 void cmdline_cancel(struct cmdline *cl); 92 93 /* vdprintf(3) */ 94 __rte_format_printf(2, 0) 95 int cmdline_vdprintf(int fd, const char *format, va_list op); 96 97 int rdline_init(struct rdline *rdl, 98 rdline_write_char_t *write_char, 99 rdline_validate_t *validate, 100 rdline_complete_t *complete, 101 void *opaque); 102 103 #endif 104