00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _RDLINE_H_
00025 #define _RDLINE_H_
00026
00034 #include <cirbuf.h>
00035 #include <vt100.h>
00036
00037 #define vt100_bell "\007"
00038 #define vt100_bs "\010"
00039 #define vt100_bs_clear "\010 \010"
00040 #define vt100_tab "\011"
00041 #define vt100_crnl "\012\015"
00042 #define vt100_clear_right "\033[0K"
00043 #define vt100_clear_left "\033[1K"
00044 #define vt100_clear_down "\033[0J"
00045 #define vt100_clear_up "\033[1J"
00046 #define vt100_clear_line "\033[2K"
00047 #define vt100_clear_screen "\033[2J"
00048 #define vt100_up_arr "\033\133\101"
00049 #define vt100_down_arr "\033\133\102"
00050 #define vt100_right_arr "\033\133\103"
00051 #define vt100_left_arr "\033\133\104"
00052 #define vt100_multi_right "\033\133%uC"
00053 #define vt100_multi_left "\033\133%uD"
00054 #define vt100_suppr "\033\133\063\176"
00055 #define vt100_home "\033M\033E"
00056 #define vt100_word_left "\033\142"
00057 #define vt100_word_right "\033\146"
00058
00059
00060 #define RDLINE_BUF_SIZE 64
00061 #define RDLINE_PROMPT_SIZE 16
00062 #define RDLINE_VT100_BUF_SIZE 8
00063 #define RDLINE_HISTORY_BUF_SIZE 128
00064 #define RDLINE_HISTORY_MAX_LINE 64
00065
00066 enum rdline_status {
00067 RDLINE_INIT,
00068 RDLINE_RUNNING,
00069 };
00070
00071 struct rdline;
00072
00073 typedef void (rdline_write_char_t)(char);
00074 typedef void (rdline_validate_t)(const char *buf, uint8_t size);
00075 typedef int8_t (rdline_complete_t)(const char *buf, char *dstbuf,
00076 uint8_t dstsize, int16_t *state);
00077
00078 struct rdline {
00079 enum rdline_status status;
00080
00081 struct cirbuf left;
00082 struct cirbuf right;
00083 char left_buf[RDLINE_BUF_SIZE+2];
00084 char right_buf[RDLINE_BUF_SIZE];
00085
00086 char prompt[RDLINE_PROMPT_SIZE];
00087 uint8_t prompt_size;
00088
00089 #ifdef CONFIG_MODULE_RDLINE_KILL_BUF
00090 char kill_buf[RDLINE_BUF_SIZE];
00091 uint8_t kill_size;
00092 #endif
00093
00094 #ifdef CONFIG_MODULE_RDLINE_HISTORY
00095
00096 struct cirbuf history;
00097 char history_buf[RDLINE_HISTORY_BUF_SIZE];
00098 int8_t history_cur_line;
00099 #endif
00100
00101
00102 rdline_write_char_t *write_char;
00103 rdline_validate_t *validate;
00104 rdline_complete_t *complete;
00105
00106
00107 struct vt100 vt100;
00108 };
00109
00120 void rdline_init(struct rdline *rdl,
00121 rdline_write_char_t *write_char,
00122 rdline_validate_t *validate,
00123 rdline_complete_t *complete);
00124
00125
00131 void rdline_newline(struct rdline *rdl, const char *prompt);
00132
00137 void rdline_stop(struct rdline *rdl);
00138
00143 void rdline_restart(struct rdline *rdl);
00144
00149 void rdline_redisplay(struct rdline *rdl);
00150
00151
00164 int8_t rdline_char_in(struct rdline * rdl, char c);
00165
00170 const char *rdline_get_buffer(struct rdline *rdl);
00171
00172
00179 int8_t rdline_add_history(struct rdline *rdl, const char *buf);
00180
00185 void rdline_clear_history(struct rdline *rdl);
00186
00190 char *rdline_get_history_item(struct rdline *rdl, uint8_t i);
00191
00192 #endif