erebus
view 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 |
line source
1 #ifndef CONSOLE_H_
2 #define CONSOLE_H_
4 #include <vector>
5 #include <list>
6 #include <string>
7 #include <functional>
8 #include <drawtext.h>
10 #define INPUTQ_SIZE 64
12 class Console {
13 private:
14 bool visible;
15 int nlines, ncolumns;
17 int inpq_front, inpq_back;
18 int keybuf[INPUTQ_SIZE];
20 std::string prompt;
21 std::string input; // current input line
22 int cursor;
23 int input_win; // first character to show in the input "window"
25 // input history
26 int max_hist_lines;
27 std::list<std::string> hist;
28 bool hist_iter_valid;
29 std::list<std::string>::const_reverse_iterator hist_iter;
31 // console output
32 int max_output_lines;
33 std::vector<std::string> output;
34 bool echo;
36 std::function<void (const char*)> cmd_handler;
38 int font_size;
39 dtx_font *font;
41 void set_cursor(int x);
42 int get_cursor() const;
44 public:
45 enum {
46 KEY_LEFT = 256,
47 KEY_RIGHT,
48 KEY_UP, KEY_DOWN,
49 KEY_INS,
50 KEY_DEL,
51 KEY_HOME,
52 KEY_END,
53 KEY_PGUP,
54 KEY_PGDOWN
55 };
57 Console();
59 void set_font(dtx_font *font, int sz);
60 void set_history_size(int hsz);
61 void set_output_buffer_size(int sz);
62 void set_command_func(std::function<void (const char*)> func);
64 void set_echo(bool echo);
65 bool get_echo() const;
67 void show() { set_visible(true); }
68 void hide() { set_visible(false); }
69 void set_visible(bool v);
70 bool is_visible() const;
72 void set_size(int lines, int columns = 80);
73 int get_size_lines() const;
74 int get_size_columns() const;
76 // update returns true if what it did makes a redraw necessary
77 bool update();
78 void draw() const;
80 void input_key(int key); // send a keystroke to the console
82 void putchar(char c);
83 void puts(const char *str);
84 void printf(const char *fmt, ...);
86 void debug();
87 };
89 #endif // CONSOLE_H_