erebus

view src/console.h @ 40:9d6368850fe1

minor enhancements and bugfixes to the console stuff
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 10 Jun 2014 10:53:19 +0300
parents
children 2e817711d0f6
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 input; // current input line
21 int cursor;
23 // input history
24 int max_hist_lines;
25 std::list<std::string> hist;
27 // console output
28 int max_output_lines;
29 std::vector<std::string> output;
30 bool echo;
32 std::function<void (const char*)> cmd_handler;
34 int font_size;
35 dtx_font *font;
37 public:
38 enum {
39 KEY_LEFT = 256,
40 KEY_RIGHT,
41 KEY_UP, KEY_DOWN,
42 KEY_INS,
43 KEY_DEL,
44 KEY_HOME,
45 KEY_END,
46 KEY_PGUP,
47 KEY_PGDOWN
48 };
50 Console();
52 void set_font(dtx_font *font, int sz);
53 void set_history_size(int hsz);
54 void set_output_buffer_size(int sz);
55 void set_command_func(std::function<void (const char*)> func);
57 void set_echo(bool echo);
58 bool get_echo() const;
60 void show() { set_visible(true); }
61 void hide() { set_visible(false); }
62 void set_visible(bool v);
63 bool is_visible() const;
65 void set_size(int lines, int columns = 80);
66 int get_size_lines() const;
67 int get_size_columns() const;
69 // update returns true if what it did makes a redraw necessary
70 bool update();
71 void draw() const;
73 void input_key(int key); // send a keystroke to the console
75 void putchar(char c);
76 void puts(const char *str);
77 void printf(const char *fmt, ...);
79 void debug();
80 };
82 #endif // CONSOLE_H_