aboutsummaryrefslogtreecommitdiff
path: root/include/reader.h
diff options
context:
space:
mode:
authorAakarsh Kashyap <[email protected]>2026-06-29 12:57:24 +0530
committerAakarsh Kashyap <[email protected]>2026-06-29 12:57:24 +0530
commit53a8f41171179663cebdb9afbee5de88f8b6bbd4 (patch)
tree1e8eb841e8bb637b97c33670e71875431c16021b /include/reader.h
parent119e47338ef9b0adea7b584239f9f6911e4da5cb (diff)
Refactored the codebase so it becomes mine
Diffstat (limited to 'include/reader.h')
-rw-r--r--include/reader.h80
1 files changed, 28 insertions, 52 deletions
diff --git a/include/reader.h b/include/reader.h
index 365500c..cad8bf3 100644
--- a/include/reader.h
+++ b/include/reader.h
@@ -1,73 +1,49 @@
-/* reader.h */
+/* reader.h - terminal word reader declarations */
-#define CTRL_KEY(k) ((k) & 0x1f)
+#define _POSIX_C_SOURCE 200809L
#include <asm-generic/ioctls.h>
-#include <cstdint>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <string>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
+
+#include <string>
#include <vector>
-#include <cstdlib>
+#define CTRL_KEY(k) ((k) & 0x1f)
-using editor_cfg = struct editor_cfg {
+typedef struct EditorCfg {
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;
+ struct termios termios_inst;
+} EditorCfg;
- void append(const char *s, int len) {
- char *n = (char *)realloc(m_b, m_len + len);
+typedef struct AppendBuf {
+ char *b;
+ uint32_t len;
+} AppendBuf;
- if (n == nullptr)
- return;
- memcpy(&n[m_len], s, len);
- m_b = n;
- m_len += len;
- }
+void ab_append(AppendBuf *ab, const char *s, int len);
+void ab_write(AppendBuf *ab);
+void ab_free(AppendBuf *ab);
- 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 window_size_callback(editor_cfg *cfg);
-void editor_refresh_scrn(editor_cfg *cfg);
+void disable_raw(EditorCfg *cfg);
+void enable_raw(EditorCfg *cfg);
+void init_editor(EditorCfg *cfg);
+void window_size_callback(EditorCfg *cfg);
+void editor_refresh_scrn(EditorCfg *cfg);
-char editor_readkey();
+char editor_readkey(void);
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);
-
-
+size_t split(const std::string &txt,
+ std::vector<std::string> &strings,
+ const std::string &delims);