blob: 27b7a906bbb23e4563018a5e101d82a9c5a4dbdc (
plain)
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
|
/* reader.h */
#define CTRL_KEY(k) ((k) & 0x1f)
#include <asm-generic/ioctls.h>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
#include <vector>
#include <cstdlib>
using editor_cfg = struct editor_cfg {
int screenrows;
int screencols;
termios termios_inst {};
};
class append_buffer {
private:
char *m_b{nullptr};
uint32_t m_len{0};
public:
append_buffer() {}
~append_buffer() = default;
void append(const char *s, int len) {
char *n = (char *)realloc(m_b, m_len + len);
if (n == nullptr)
return;
memcpy(&n[m_len], s, len);
m_b = n;
m_len += len;
}
static append_buffer &instance() {
static append_buffer obj;
return obj;
}
void remove() {
free(m_b);
m_b = nullptr;
m_len = 0;
}
void write_output() {
write(STDOUT_FILENO, m_b, m_len);
}
};
void init_editor(editor_cfg *cfg);
void die(const char *s);
void disable_raw(editor_cfg *cfg);
void enable_raw(editor_cfg *cfg);
void editor_refresh_scrn(editor_cfg *cfg);
char editor_readkey();
int get_cursor_pos(int *rows, int *cols);
int get_window_size(int *rows, int *cols);
int is_number(char *strnum);
size_t split(const std::string &txt, std::vector<std::string> &strings, const std::string &delims);
|