aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorseivarya <[email protected]>2026-06-20 18:25:02 +0530
committerseivarya <[email protected]>2026-06-20 18:25:02 +0530
commit8798eafd4cc4b32c590a40c276c09b830c5d62da (patch)
treee39a1ca656c893fc0280456a26947e7fdaf7aa59 /include
parent02a1bdae9780c1f08818d1a5039bdfb055372723 (diff)
[refactor]: restructured the project
Diffstat (limited to 'include')
-rw-r--r--include/reader.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/include/reader.h b/include/reader.h
new file mode 100644
index 0000000..8b61e6c
--- /dev/null
+++ b/include/reader.h
@@ -0,0 +1,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, char ch);
+
+