/*----------------------------------------------------------------------------- * Author: Nelso G. Jost (nelsojost@gmail.com) * License: GPLv2 * Purpose: Read-Eval-Print-Loop functionality *---------------------------------------------------------------------------*/ #ifndef REPL_H #define REPL_H #define HISTORY_MAX 10 class REPL; typedef struct { const char *name; void (*func)(REPL *); const char *prototype; const char *help; } REPL_COMMAND; class REPL { public: REPL(REPL_COMMAND command_map[]); String prompt=">"; void update(void); void print_help(void); void log(String msg, bool show_buffer=false); String get_arg(int index); private: REPL_COMMAND * _fp_map; String _command_buffer=""; String _history[HISTORY_MAX]; int _history_index=-1; void _backspace(void); void _clear_line(void); void _complete(void); void _history_previous(void); void _history_next(void); void _history_save(void); int _execute_command(void); }; #endif