1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
#ifndef terminal_hh_INCLUDED
#define terminal_hh_INCLUDED
#include "array_view.hh"
#include "coord.hh"
#include "display_buffer.hh"
#include "event_manager.hh"
#include "face.hh"
#include "optional.hh"
#include "string.hh"
#include "user_interface.hh"
#include <termios.h>
namespace Kakoune
{
struct DisplayAtom;
struct Writer;
class TerminalUI : public UserInterface, public Singleton<TerminalUI>
{
public:
TerminalUI();
~TerminalUI() override;
TerminalUI(const TerminalUI&) = delete;
TerminalUI& operator=(const TerminalUI&) = delete;
bool is_ok() const override { return (bool)m_window; }
void draw(const DisplayBuffer& display_buffer,
const Face& default_face,
const Face& padding_face) override;
void draw_status(const DisplayLine& status_line,
const DisplayLine& mode_line,
const Face& default_face) override;
void menu_show(ConstArrayView<DisplayLine> items,
DisplayCoord anchor, Face fg, Face bg,
MenuStyle style) override;
void menu_select(int selected) override;
void menu_hide() override;
void info_show(const DisplayLine& title, const DisplayLineList& content,
DisplayCoord anchor, Face face,
InfoStyle style) override;
void info_hide() override;
void set_cursor(CursorMode mode, DisplayCoord coord) override;
void refresh(bool force) override;
DisplayCoord dimensions() override;
void set_on_key(OnKeyCallback callback) override;
void set_on_paste(OnPasteCallback callback) override;
void set_ui_options(const Options& options) override;
static void setup_terminal();
static void restore_terminal();
void suspend();
struct Rect
{
DisplayCoord pos;
DisplayCoord size;
};
private:
void check_resize(bool force = false);
void redraw(bool force);
Optional<Key> get_next_key();
struct Window : Rect
{
void create(const DisplayCoord& pos, const DisplayCoord& size);
void destroy();
void blit(Window& target);
void draw(DisplayCoord pos, ConstArrayView<DisplayAtom> atoms, const Face& default_face);
explicit operator bool() const { return (bool)lines; }
struct Line;
UniquePtr<Line[]> lines;
};
struct Screen : Window
{
void output(bool force, bool synchronized, Writer& writer);
void set_face(const Face& face, Writer& writer);
UniquePtr<size_t[]> hashes;
Face m_active_face;
};
Window m_window;
Screen m_screen;
DisplayCoord m_dimensions;
termios m_original_termios{};
void set_raw_mode() const;
struct Menu : Window
{
Vector<DisplayLine, MemoryDomain::Display> items;
Face fg;
Face bg;
DisplayCoord anchor;
MenuStyle style;
int selected_item = 0;
int first_item = 0;
int columns = 1;
} m_menu;
void draw_menu();
LineCount content_line_offset() const;
struct Info : Window
{
DisplayLine title;
DisplayLineList content;
Face face;
DisplayCoord anchor;
InfoStyle style;
} m_info;
struct Cursor
{
CursorMode mode;
DisplayCoord coord;
} m_cursor;
FDWatcher m_stdin_watcher;
OnKeyCallback m_on_key;
OnPasteCallback m_on_paste;
Optional<String> m_paste_buffer;
bool m_status_on_top = false;
ConstArrayView<StringView> m_assistant;
void enable_mouse(bool enabled);
bool m_mouse_enabled = false;
int m_wheel_scroll_amount = 3;
int m_mouse_state = 0;
static constexpr int default_shift_function_key = 12;
int m_shift_function_key = default_shift_function_key;
bool m_set_title = true;
Optional<String> m_title;
struct Synchronized
{
bool queried : 1;
bool supported : 1;
bool set : 1;
bool requested : 1;
explicit operator bool() const { return set ? requested : supported; }
} m_synchronized{};
Codepoint m_padding_char = '~';
bool m_padding_fill = false;
bool m_cursor_native = false;
bool m_dirty = false;
bool m_resize_pending = false;
void set_resize_pending();
ColumnCount m_status_len = 0;
ColumnCount m_info_max_width = 0;
};
}
#endif // terminal_hh_INCLUDED
|