aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1 | #ifndef READLINE_H |
| 2 | #define READLINE_H |
| 3 | |
| 4 | #include "qemu-common.h" |
| 5 | |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 6 | #define READLINE_CMD_BUF_SIZE 4095 |
| 7 | #define READLINE_MAX_CMDS 64 |
| 8 | #define READLINE_MAX_COMPLETIONS 256 |
| 9 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 10 | typedef void ReadLineFunc(Monitor *mon, const char *str, void *opaque); |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 11 | typedef void ReadLineCompletionFunc(const char *cmdline); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 12 | |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 13 | typedef struct ReadLineState { |
| 14 | char cmd_buf[READLINE_CMD_BUF_SIZE + 1]; |
| 15 | int cmd_buf_index; |
| 16 | int cmd_buf_size; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 17 | |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 18 | char last_cmd_buf[READLINE_CMD_BUF_SIZE + 1]; |
| 19 | int last_cmd_buf_index; |
| 20 | int last_cmd_buf_size; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 21 | |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 22 | int esc_state; |
| 23 | int esc_param; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 24 | |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 25 | char *history[READLINE_MAX_CMDS]; |
| 26 | int hist_entry; |
| 27 | |
| 28 | ReadLineCompletionFunc *completion_finder; |
| 29 | char *completions[READLINE_MAX_COMPLETIONS]; |
| 30 | int nb_completions; |
| 31 | int completion_index; |
| 32 | |
| 33 | ReadLineFunc *readline_func; |
| 34 | void *readline_opaque; |
| 35 | int read_password; |
| 36 | char prompt[256]; |
| 37 | Monitor *mon; |
| 38 | } ReadLineState; |
| 39 | |
| 40 | void readline_add_completion(ReadLineState *rs, const char *str); |
| 41 | void readline_set_completion_index(ReadLineState *rs, int completion_index); |
| 42 | |
| 43 | const char *readline_get_history(ReadLineState *rs, unsigned int index); |
| 44 | |
| 45 | void readline_handle_byte(ReadLineState *rs, int ch); |
| 46 | |
| 47 | void readline_start(ReadLineState *rs, const char *prompt, int read_password, |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 48 | ReadLineFunc *readline_func, void *opaque); |
aliguori | 2724b18 | 2009-03-05 23:01:47 +0000 | [diff] [blame] | 49 | void readline_restart(ReadLineState *rs); |
aliguori | 4c36ba3 | 2009-03-05 23:01:37 +0000 | [diff] [blame] | 50 | void readline_show_prompt(ReadLineState *rs); |
| 51 | |
| 52 | ReadLineState *readline_init(Monitor *mon, |
| 53 | ReadLineCompletionFunc *completion_finder); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 54 | |
| 55 | #endif /* !READLINE_H */ |