erebus
annotate src/console.h @ 39:fd45cf0fc912
load console command
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 09 Jun 2014 23:57:24 +0300 |
parents | |
children | 2e817711d0f6 |
rev | line source |
---|---|
nuclear@37 | 1 #ifndef CONSOLE_H_ |
nuclear@37 | 2 #define CONSOLE_H_ |
nuclear@37 | 3 |
nuclear@37 | 4 #include <vector> |
nuclear@37 | 5 #include <list> |
nuclear@37 | 6 #include <string> |
nuclear@37 | 7 #include <functional> |
nuclear@37 | 8 #include <drawtext.h> |
nuclear@37 | 9 |
nuclear@37 | 10 #define INPUTQ_SIZE 64 |
nuclear@37 | 11 |
nuclear@37 | 12 class Console { |
nuclear@37 | 13 private: |
nuclear@37 | 14 bool visible; |
nuclear@37 | 15 int nlines, ncolumns; |
nuclear@37 | 16 |
nuclear@37 | 17 int inpq_front, inpq_back; |
nuclear@37 | 18 int keybuf[INPUTQ_SIZE]; |
nuclear@37 | 19 |
nuclear@37 | 20 std::string input; // current input line |
nuclear@37 | 21 int cursor; |
nuclear@37 | 22 |
nuclear@37 | 23 // input history |
nuclear@37 | 24 int max_hist_lines; |
nuclear@37 | 25 std::list<std::string> hist; |
nuclear@37 | 26 |
nuclear@37 | 27 // console output |
nuclear@37 | 28 int max_output_lines; |
nuclear@37 | 29 std::vector<std::string> output; |
nuclear@37 | 30 bool echo; |
nuclear@37 | 31 |
nuclear@37 | 32 std::function<void (const char*)> cmd_handler; |
nuclear@37 | 33 |
nuclear@37 | 34 int font_size; |
nuclear@37 | 35 dtx_font *font; |
nuclear@37 | 36 |
nuclear@37 | 37 public: |
nuclear@37 | 38 enum { |
nuclear@37 | 39 KEY_LEFT = 256, |
nuclear@37 | 40 KEY_RIGHT, |
nuclear@37 | 41 KEY_UP, KEY_DOWN, |
nuclear@37 | 42 KEY_INS, |
nuclear@37 | 43 KEY_DEL, |
nuclear@37 | 44 KEY_HOME, |
nuclear@37 | 45 KEY_END, |
nuclear@37 | 46 KEY_PGUP, |
nuclear@37 | 47 KEY_PGDOWN |
nuclear@37 | 48 }; |
nuclear@37 | 49 |
nuclear@37 | 50 Console(); |
nuclear@37 | 51 |
nuclear@37 | 52 void set_font(dtx_font *font, int sz); |
nuclear@37 | 53 void set_history_size(int hsz); |
nuclear@37 | 54 void set_output_buffer_size(int sz); |
nuclear@37 | 55 void set_command_func(std::function<void (const char*)> func); |
nuclear@37 | 56 |
nuclear@37 | 57 void set_echo(bool echo); |
nuclear@37 | 58 bool get_echo() const; |
nuclear@37 | 59 |
nuclear@37 | 60 void show() { set_visible(true); } |
nuclear@37 | 61 void hide() { set_visible(false); } |
nuclear@37 | 62 void set_visible(bool v); |
nuclear@37 | 63 bool is_visible() const; |
nuclear@37 | 64 |
nuclear@37 | 65 void set_size(int lines, int columns = 80); |
nuclear@37 | 66 int get_size_lines() const; |
nuclear@37 | 67 int get_size_columns() const; |
nuclear@37 | 68 |
nuclear@37 | 69 // update returns true if what it did makes a redraw necessary |
nuclear@37 | 70 bool update(); |
nuclear@37 | 71 void draw() const; |
nuclear@37 | 72 |
nuclear@37 | 73 void input_key(int key); // send a keystroke to the console |
nuclear@37 | 74 |
nuclear@37 | 75 void putchar(char c); |
nuclear@37 | 76 void puts(const char *str); |
nuclear@37 | 77 void printf(const char *fmt, ...); |
nuclear@37 | 78 |
nuclear@37 | 79 void debug(); |
nuclear@37 | 80 }; |
nuclear@37 | 81 |
nuclear@37 | 82 #endif // CONSOLE_H_ |