#include <cirbuf.h>
#include <vt100.h>
Go to the source code of this file.
Data Structures | |
struct | rdline |
Defines | |
#define | vt100_bell "\007" |
#define | vt100_bs "\010" |
#define | vt100_bs_clear "\010 \010" |
#define | vt100_tab "\011" |
#define | vt100_crnl "\012\015" |
#define | vt100_clear_right "\033[0K" |
#define | vt100_clear_left "\033[1K" |
#define | vt100_clear_down "\033[0J" |
#define | vt100_clear_up "\033[1J" |
#define | vt100_clear_line "\033[2K" |
#define | vt100_clear_screen "\033[2J" |
#define | vt100_up_arr "\033\133\101" |
#define | vt100_down_arr "\033\133\102" |
#define | vt100_right_arr "\033\133\103" |
#define | vt100_left_arr "\033\133\104" |
#define | vt100_multi_right "\033\133%uC" |
#define | vt100_multi_left "\033\133%uD" |
#define | vt100_suppr "\033\133\063\176" |
#define | vt100_home "\033M\033E" |
#define | vt100_word_left "\033\142" |
#define | vt100_word_right "\033\146" |
#define | RDLINE_BUF_SIZE 64 |
#define | RDLINE_PROMPT_SIZE 16 |
#define | RDLINE_VT100_BUF_SIZE 8 |
#define | RDLINE_HISTORY_BUF_SIZE 128 |
#define | RDLINE_HISTORY_MAX_LINE 64 |
Typedefs | |
typedef void( | rdline_write_char_t )(char) |
typedef void( | rdline_validate_t )(const char *buf, uint8_t size) |
typedef int8_t( | rdline_complete_t )(const char *buf, char *dstbuf, uint8_t dstsize, int16_t *state) |
Enumerations | |
enum | rdline_status { RDLINE_INIT, RDLINE_RUNNING } |
Functions | |
void | rdline_init (struct rdline *rdl, rdline_write_char_t *write_char, rdline_validate_t *validate, rdline_complete_t *complete) |
void | rdline_newline (struct rdline *rdl, const char *prompt) |
void | rdline_stop (struct rdline *rdl) |
void | rdline_restart (struct rdline *rdl) |
void | rdline_redisplay (struct rdline *rdl) |
int8_t | rdline_char_in (struct rdline *rdl, char c) |
const char * | rdline_get_buffer (struct rdline *rdl) |
int8_t | rdline_add_history (struct rdline *rdl, const char *buf) |
void | rdline_clear_history (struct rdline *rdl) |
char * | rdline_get_history_item (struct rdline *rdl, uint8_t i) |
#define RDLINE_BUF_SIZE 64 |
#define RDLINE_HISTORY_BUF_SIZE 128 |
#define vt100_bell "\007" |
#define vt100_bs "\010" |
#define vt100_clear_right "\033[0K" |
#define vt100_home "\033M\033E" |
#define vt100_left_arr "\033\133\104" |
#define vt100_multi_left "\033\133%uD" |
#define vt100_multi_right "\033\133%uC" |
#define vt100_right_arr "\033\133\103" |
typedef int8_t( rdline_complete_t)(const char *buf, char *dstbuf, uint8_t dstsize, int16_t *state) |
typedef void( rdline_validate_t)(const char *buf, uint8_t size) |
typedef void( rdline_write_char_t)(char) |
enum rdline_status |
int8_t rdline_add_history | ( | struct rdline * | rdl, | |
const char * | buf | |||
) |
Add the buffer to history. return < 0 on error.
rdl | A pointer to a struct rdline | |
buf | A buffer that is terminated by '' |
Definition at line 535 of file rdline.c.
Referenced by rdline_char_in().
int8_t rdline_char_in | ( | struct rdline * | rdl, | |
char | c | |||
) |
append a char to the readline buffer. Return 1 when the line has been validated. Return 2 when the user asked to complete the buffer. Return -1 if it is not running. Return -2 if EOF (ctrl-d on an empty line). Else return 0. XXX error case when the buffer is full ?
rdl | A pointer to a struct rdline | |
c | The character to append |
Definition at line 142 of file rdline.c.
References cirbuf_add_buf_tail(), cirbuf_add_head(), cirbuf_add_tail(), cirbuf_add_tail_safe(), cirbuf_align_left(), cirbuf_del_buf_head(), cirbuf_del_head(), cirbuf_del_head_safe(), cirbuf_del_tail(), cirbuf_del_tail_safe(), cirbuf_get_buf_head(), cirbuf_get_head(), CIRBUF_GET_LEN, cirbuf_get_tail(), cirbuf_init(), CIRBUF_IS_EMPTY, rdline::complete, KEY_BKSPACE, KEY_CTRL_A, KEY_CTRL_B, KEY_CTRL_C, KEY_CTRL_D, KEY_CTRL_E, KEY_CTRL_F, KEY_CTRL_K, KEY_CTRL_L, KEY_CTRL_Y, KEY_DOWN_ARR, KEY_HELP, KEY_LEFT_ARR, KEY_META_BKSPACE, KEY_RETURN, KEY_RETURN2, KEY_RIGHT_ARR, KEY_SUPPR, KEY_TAB, KEY_UP_ARR, KEY_WLEFT, KEY_WRIGHT, rdline::left, rdline::left_buf, rdline::prompt, rdline_add_history(), RDLINE_BUF_SIZE, rdline_get_buffer(), rdline_get_history_item(), RDLINE_INIT, rdline_newline(), rdline_redisplay(), RDLINE_RUNNING, rdline::right, rdline::right_buf, rdline::status, rdline::validate, rdline::vt100, vt100_bs, vt100_clear_right, vt100_init(), vt100_left_arr, vt100_multi_left, vt100_multi_right, vt100_parser(), vt100_right_arr, and rdline::write_char.
void rdline_clear_history | ( | struct rdline * | rdl | ) |
const char* rdline_get_buffer | ( | struct rdline * | rdl | ) |
Return the current buffer, terminated by ''.
rdl | A pointer to a struct rdline |
Definition at line 96 of file rdline.c.
References cirbuf_align_left(), CIRBUF_GET_LEN, rdline::left, rdline::left_buf, rdline::right, and rdline::right_buf.
Referenced by rdline_char_in().
char* rdline_get_history_item | ( | struct rdline * | rdl, | |
uint8_t | i | |||
) |
void rdline_init | ( | struct rdline * | rdl, | |
rdline_write_char_t * | write_char, | |||
rdline_validate_t * | validate, | |||
rdline_complete_t * | complete | |||
) |
Init fields for a struct rdline. Call this only once at the beginning of your program.
rdl | A pointer to an uninitialized struct rdline | |
write_char | The function used by the function to write a character | |
validate | A pointer to the function to execute when the user validates the buffer. | |
complete | A pointer to the function to execute when the user completes the buffer. |
Definition at line 46 of file rdline.c.
References cirbuf_init(), rdline::complete, RDLINE_HISTORY_BUF_SIZE, RDLINE_INIT, rdline::status, rdline::validate, and rdline::write_char.
void rdline_newline | ( | struct rdline * | rdl, | |
const char * | prompt | |||
) |
Init the current buffer, and display a prompt.
rdl | A pointer to a struct rdline | |
prompt | A string containing the prompt |
Definition at line 62 of file rdline.c.
References cirbuf_init(), i, rdline::left, rdline::left_buf, rdline::prompt, rdline::prompt_size, RDLINE_BUF_SIZE, RDLINE_RUNNING, rdline::right, rdline::right_buf, rdline::status, rdline::vt100, vt100_init(), and rdline::write_char.
Referenced by rdline_char_in().
void rdline_redisplay | ( | struct rdline * | rdl | ) |
Redisplay the current buffer
rdl | A pointer to a struct rdline |
Definition at line 127 of file rdline.c.
References CIRBUF_FOREACH, rdline::left, rdline::prompt, rdline::prompt_size, vt100_home, and rdline::write_char.
Referenced by rdline_char_in().
void rdline_restart | ( | struct rdline * | rdl | ) |
Restart after a call to rdline_stop()
rdl | A pointer to a struct rdline |
Definition at line 90 of file rdline.c.
References RDLINE_RUNNING, and rdline::status.
void rdline_stop | ( | struct rdline * | rdl | ) |
Call it and all received chars will be ignored.
rdl | A pointer to a struct rdline |
Definition at line 84 of file rdline.c.
References RDLINE_INIT, and rdline::status.