erebus

annotate src/console.h @ 48:9971a08f4104

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 24 Feb 2016 00:29:31 +0200
parents 2e817711d0f6
children
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@41 20 std::string prompt;
nuclear@37 21 std::string input; // current input line
nuclear@37 22 int cursor;
nuclear@41 23 int input_win; // first character to show in the input "window"
nuclear@37 24
nuclear@37 25 // input history
nuclear@37 26 int max_hist_lines;
nuclear@37 27 std::list<std::string> hist;
nuclear@42 28 bool hist_iter_valid;
nuclear@42 29 std::list<std::string>::const_reverse_iterator hist_iter;
nuclear@37 30
nuclear@37 31 // console output
nuclear@37 32 int max_output_lines;
nuclear@37 33 std::vector<std::string> output;
nuclear@37 34 bool echo;
nuclear@37 35
nuclear@37 36 std::function<void (const char*)> cmd_handler;
nuclear@37 37
nuclear@37 38 int font_size;
nuclear@37 39 dtx_font *font;
nuclear@37 40
nuclear@41 41 void set_cursor(int x);
nuclear@41 42 int get_cursor() const;
nuclear@41 43
nuclear@37 44 public:
nuclear@37 45 enum {
nuclear@37 46 KEY_LEFT = 256,
nuclear@37 47 KEY_RIGHT,
nuclear@37 48 KEY_UP, KEY_DOWN,
nuclear@37 49 KEY_INS,
nuclear@37 50 KEY_DEL,
nuclear@37 51 KEY_HOME,
nuclear@37 52 KEY_END,
nuclear@37 53 KEY_PGUP,
nuclear@37 54 KEY_PGDOWN
nuclear@37 55 };
nuclear@37 56
nuclear@37 57 Console();
nuclear@37 58
nuclear@37 59 void set_font(dtx_font *font, int sz);
nuclear@37 60 void set_history_size(int hsz);
nuclear@37 61 void set_output_buffer_size(int sz);
nuclear@37 62 void set_command_func(std::function<void (const char*)> func);
nuclear@37 63
nuclear@37 64 void set_echo(bool echo);
nuclear@37 65 bool get_echo() const;
nuclear@37 66
nuclear@37 67 void show() { set_visible(true); }
nuclear@37 68 void hide() { set_visible(false); }
nuclear@37 69 void set_visible(bool v);
nuclear@37 70 bool is_visible() const;
nuclear@37 71
nuclear@37 72 void set_size(int lines, int columns = 80);
nuclear@37 73 int get_size_lines() const;
nuclear@37 74 int get_size_columns() const;
nuclear@37 75
nuclear@37 76 // update returns true if what it did makes a redraw necessary
nuclear@37 77 bool update();
nuclear@37 78 void draw() const;
nuclear@37 79
nuclear@37 80 void input_key(int key); // send a keystroke to the console
nuclear@37 81
nuclear@37 82 void putchar(char c);
nuclear@37 83 void puts(const char *str);
nuclear@37 84 void printf(const char *fmt, ...);
nuclear@37 85
nuclear@37 86 void debug();
nuclear@37 87 };
nuclear@37 88
nuclear@37 89 #endif // CONSOLE_H_