erebus

view src/console.h @ 41:2e817711d0f6

console: proper input line windowing and clipping
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 10 Jun 2014 12:28:56 +0300
parents db8a90307386
children b9294cd6b9dc
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;
29 // console output
30 int max_output_lines;
31 std::vector<std::string> output;
32 bool echo;
34 std::function<void (const char*)> cmd_handler;
36 int font_size;
37 dtx_font *font;
39 void set_cursor(int x);
40 int get_cursor() const;
42 public:
43 enum {
44 KEY_LEFT = 256,
45 KEY_RIGHT,
46 KEY_UP, KEY_DOWN,
47 KEY_INS,
48 KEY_DEL,
49 KEY_HOME,
50 KEY_END,
51 KEY_PGUP,
52 KEY_PGDOWN
53 };
55 Console();
57 void set_font(dtx_font *font, int sz);
58 void set_history_size(int hsz);
59 void set_output_buffer_size(int sz);
60 void set_command_func(std::function<void (const char*)> func);
62 void set_echo(bool echo);
63 bool get_echo() const;
65 void show() { set_visible(true); }
66 void hide() { set_visible(false); }
67 void set_visible(bool v);
68 bool is_visible() const;
70 void set_size(int lines, int columns = 80);
71 int get_size_lines() const;
72 int get_size_columns() const;
74 // update returns true if what it did makes a redraw necessary
75 bool update();
76 void draw() const;
78 void input_key(int key); // send a keystroke to the console
80 void putchar(char c);
81 void puts(const char *str);
82 void printf(const char *fmt, ...);
84 void debug();
85 };
87 #endif // CONSOLE_H_