nuclear@37: #ifndef CONSOLE_H_ nuclear@37: #define CONSOLE_H_ nuclear@37: nuclear@37: #include nuclear@37: #include nuclear@37: #include nuclear@37: #include nuclear@37: #include nuclear@37: nuclear@37: #define INPUTQ_SIZE 64 nuclear@37: nuclear@37: class Console { nuclear@37: private: nuclear@37: bool visible; nuclear@37: int nlines, ncolumns; nuclear@37: nuclear@37: int inpq_front, inpq_back; nuclear@37: int keybuf[INPUTQ_SIZE]; nuclear@37: nuclear@41: std::string prompt; nuclear@37: std::string input; // current input line nuclear@37: int cursor; nuclear@41: int input_win; // first character to show in the input "window" nuclear@37: nuclear@37: // input history nuclear@37: int max_hist_lines; nuclear@37: std::list hist; nuclear@42: bool hist_iter_valid; nuclear@42: std::list::const_reverse_iterator hist_iter; nuclear@37: nuclear@37: // console output nuclear@37: int max_output_lines; nuclear@37: std::vector output; nuclear@37: bool echo; nuclear@37: nuclear@37: std::function cmd_handler; nuclear@37: nuclear@37: int font_size; nuclear@37: dtx_font *font; nuclear@37: nuclear@41: void set_cursor(int x); nuclear@41: int get_cursor() const; nuclear@41: nuclear@37: public: nuclear@37: enum { nuclear@37: KEY_LEFT = 256, nuclear@37: KEY_RIGHT, nuclear@37: KEY_UP, KEY_DOWN, nuclear@37: KEY_INS, nuclear@37: KEY_DEL, nuclear@37: KEY_HOME, nuclear@37: KEY_END, nuclear@37: KEY_PGUP, nuclear@37: KEY_PGDOWN nuclear@37: }; nuclear@37: nuclear@37: Console(); nuclear@37: nuclear@37: void set_font(dtx_font *font, int sz); nuclear@37: void set_history_size(int hsz); nuclear@37: void set_output_buffer_size(int sz); nuclear@37: void set_command_func(std::function func); nuclear@37: nuclear@37: void set_echo(bool echo); nuclear@37: bool get_echo() const; nuclear@37: nuclear@37: void show() { set_visible(true); } nuclear@37: void hide() { set_visible(false); } nuclear@37: void set_visible(bool v); nuclear@37: bool is_visible() const; nuclear@37: nuclear@37: void set_size(int lines, int columns = 80); nuclear@37: int get_size_lines() const; nuclear@37: int get_size_columns() const; nuclear@37: nuclear@37: // update returns true if what it did makes a redraw necessary nuclear@37: bool update(); nuclear@37: void draw() const; nuclear@37: nuclear@37: void input_key(int key); // send a keystroke to the console nuclear@37: nuclear@37: void putchar(char c); nuclear@37: void puts(const char *str); nuclear@37: void printf(const char *fmt, ...); nuclear@37: nuclear@37: void debug(); nuclear@37: }; nuclear@37: nuclear@37: #endif // CONSOLE_H_