repl.h 1.02 KB
Newer Older
1
2
3
4
5
6
7
8
/*-----------------------------------------------------------------------------
 *  Author: Nelso G. Jost (nelsojost@gmail.com)
 *  License: GPLv2
 *  Purpose: Read-Eval-Print-Loop functionality
 *---------------------------------------------------------------------------*/
#ifndef REPL_H
#define REPL_H

9
10
#define  HISTORY_MAX  10

11
class REPL;
12
13
14
15

typedef struct
{
    const char *name;
16
    void (*func)(REPL *);
17
18
19
20
21
    const char *prototype;
    const char *help;
} REPL_COMMAND;


22

23
24
25
26
27
28
29
class REPL
{
public:
    REPL(REPL_COMMAND command_map[]);

    String prompt=">";

30
    void update(void);
31
    void print_help(void);
32
    void log(String msg, bool show_buffer=false);
33
    String get_arg(int index);
34
35
36

private:
    REPL_COMMAND * _fp_map;
37
38
39
    String _command_buffer="";
    String _history[HISTORY_MAX];
    int _history_index=-1;
40
41
42

    void _backspace(void);
    void _clear_line(void);
43
    void _complete(void);
44
45
46

    void _history_previous(void);
    void _history_next(void);
47
    void _history_save(void);
48
49
50
51
52

    int _execute_command(void);
};

#endif