1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation. 3 * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org> 4 * All rights reserved. 5 */ 6 7 #ifndef _CMDLINE_VT100_H_ 8 #define _CMDLINE_VT100_H_ 9 10 #include <stdint.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #define vt100_bell "\007" 17 #define vt100_bs "\010" 18 #define vt100_bs_clear "\010 \010" 19 #define vt100_tab "\011" 20 #define vt100_crnl "\012\015" 21 #define vt100_clear_right "\033[0K" 22 #define vt100_clear_left "\033[1K" 23 #define vt100_clear_down "\033[0J" 24 #define vt100_clear_up "\033[1J" 25 #define vt100_clear_line "\033[2K" 26 #define vt100_clear_screen "\033[2J" 27 #define vt100_up_arr "\033\133\101" 28 #define vt100_down_arr "\033\133\102" 29 #define vt100_right_arr "\033\133\103" 30 #define vt100_left_arr "\033\133\104" 31 #define vt100_multi_right "\033\133%uC" 32 #define vt100_multi_left "\033\133%uD" 33 #define vt100_suppr "\033\133\063\176" 34 #ifndef RTE_EXEC_ENV_WINDOWS 35 #define vt100_home "\033M\033E" 36 #else 37 #define vt100_home "\033M\033[E" 38 #endif 39 #define vt100_word_left "\033\142" 40 #define vt100_word_right "\033\146" 41 42 /* Result of parsing : it must be synchronized with 43 * cmdline_vt100_commands[] in vt100.c */ 44 #define CMDLINE_KEY_UP_ARR 0 45 #define CMDLINE_KEY_DOWN_ARR 1 46 #define CMDLINE_KEY_RIGHT_ARR 2 47 #define CMDLINE_KEY_LEFT_ARR 3 48 #define CMDLINE_KEY_BKSPACE 4 49 #define CMDLINE_KEY_RETURN 5 50 #define CMDLINE_KEY_CTRL_A 6 51 #define CMDLINE_KEY_CTRL_E 7 52 #define CMDLINE_KEY_CTRL_K 8 53 #define CMDLINE_KEY_CTRL_Y 9 54 #define CMDLINE_KEY_CTRL_C 10 55 #define CMDLINE_KEY_CTRL_F 11 56 #define CMDLINE_KEY_CTRL_B 12 57 #define CMDLINE_KEY_SUPPR 13 58 #define CMDLINE_KEY_TAB 14 59 #define CMDLINE_KEY_CTRL_D 15 60 #define CMDLINE_KEY_CTRL_L 16 61 #define CMDLINE_KEY_RETURN2 17 62 #define CMDLINE_KEY_META_BKSPACE 18 63 #define CMDLINE_KEY_WLEFT 19 64 #define CMDLINE_KEY_WRIGHT 20 65 #define CMDLINE_KEY_HELP 21 66 #define CMDLINE_KEY_CTRL_W 22 67 #define CMDLINE_KEY_CTRL_P 23 68 #define CMDLINE_KEY_CTRL_N 24 69 #define CMDLINE_KEY_META_D 25 70 #define CMDLINE_KEY_BKSPACE2 26 71 72 extern const char *cmdline_vt100_commands[]; 73 74 enum cmdline_vt100_parser_state { 75 CMDLINE_VT100_INIT, 76 CMDLINE_VT100_ESCAPE, 77 CMDLINE_VT100_ESCAPE_CSI 78 }; 79 80 #define CMDLINE_VT100_BUF_SIZE 8 81 struct cmdline_vt100 { 82 uint8_t bufpos; 83 char buf[CMDLINE_VT100_BUF_SIZE]; 84 enum cmdline_vt100_parser_state state; 85 }; 86 87 /** 88 * Init 89 */ 90 void vt100_init(struct cmdline_vt100 *vt); 91 92 /** 93 * Input a new character. 94 * Return -1 if the character is not part of a control sequence 95 * Return -2 if c is not the last char of a control sequence 96 * Else return the index in vt100_commands[] 97 */ 98 int vt100_parser(struct cmdline_vt100 *vt, char c); 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 #endif 105