readline.h 1.6 KB
Newer Older
A
aliguori 已提交
1 2 3 4 5
#ifndef READLINE_H
#define READLINE_H

#include "qemu-common.h"

6 7 8 9
#define READLINE_CMD_BUF_SIZE 4095
#define READLINE_MAX_CMDS 64
#define READLINE_MAX_COMPLETIONS 256

A
aliguori 已提交
10
typedef void ReadLineFunc(Monitor *mon, const char *str, void *opaque);
11 12
typedef void ReadLineCompletionFunc(Monitor *mon,
                                    const char *cmdline);
13 14 15 16 17 18 19 20 21 22 23 24

typedef struct ReadLineState {
    char cmd_buf[READLINE_CMD_BUF_SIZE + 1];
    int cmd_buf_index;
    int cmd_buf_size;

    char last_cmd_buf[READLINE_CMD_BUF_SIZE + 1];
    int last_cmd_buf_index;
    int last_cmd_buf_size;

    int esc_state;
    int esc_param;
A
aliguori 已提交
25

26 27
    char *history[READLINE_MAX_CMDS];
    int hist_entry;
A
aliguori 已提交
28

29 30 31 32
    ReadLineCompletionFunc *completion_finder;
    char *completions[READLINE_MAX_COMPLETIONS];
    int nb_completions;
    int completion_index;
A
aliguori 已提交
33

34 35 36 37 38 39
    ReadLineFunc *readline_func;
    void *readline_opaque;
    int read_password;
    char prompt[256];
    Monitor *mon;
} ReadLineState;
A
aliguori 已提交
40

41 42 43 44 45 46 47 48
void readline_add_completion(ReadLineState *rs, const char *str);
void readline_set_completion_index(ReadLineState *rs, int completion_index);

const char *readline_get_history(ReadLineState *rs, unsigned int index);

void readline_handle_byte(ReadLineState *rs, int ch);

void readline_start(ReadLineState *rs, const char *prompt, int read_password,
A
aliguori 已提交
49
                    ReadLineFunc *readline_func, void *opaque);
50
void readline_restart(ReadLineState *rs);
51 52 53 54
void readline_show_prompt(ReadLineState *rs);

ReadLineState *readline_init(Monitor *mon,
                             ReadLineCompletionFunc *completion_finder);
A
aliguori 已提交
55 56

#endif /* !READLINE_H */