commit f4724e668c102b0cb6e0561d2f4db0ebf9518c9b
parent d31914433fd4fbf651b1e8cbe79465c249876c50
Author: night0721 <[email protected]>
Date: Thu, 4 Jul 2024 17:00:13 +0100
Refactor header files
Diffstat:
6 files changed, 58 insertions(+), 43 deletions(-)
diff --git a/include/editor.h b/include/editor.h
@@ -1,10 +1,14 @@
#ifndef EDITOR_H_
#define EDITOR_H_
+void refresh_screen();
+void move_cursor(int key);
+void scroll();
void insert_char(int c);
void insert_new_line();
void shift_new_line();
void del_char();
+void init_editor();
void open_editor(char *filename);
char *prompt_editor(char *prompt, void (*callback)(char *, int));
void find_editor();
diff --git a/include/io.h b/include/io.h
@@ -0,0 +1,9 @@
+#ifndef IO_H_
+#define IO_H_
+
+int read_key();
+void save_file();
+void process_key();
+void draw_rows(struct abuf *ab);
+
+#endif
diff --git a/include/row.h b/include/row.h
@@ -1,6 +1,16 @@
#ifndef ROW_H_
#define ROW_H_
+typedef struct row {
+ int idx;
+ int size;
+ int render_size;
+ char *chars;
+ char *render;
+ unsigned char *hl;
+ int opened_comment;
+} row;
+
int row_cx_to_rx(row *row, int cx);
int row_rx_to_cx(row *row, int rx);
void update_row(row *row);
diff --git a/include/syntax.h b/include/syntax.h
@@ -1,7 +1,26 @@
#ifndef SYNTAX_H_
#define SYNTAX_H_
+#include <stdio.h>
+
+#include "row.h"
+
+#define HL_NUMBERS (1 << 0)
+#define HL_STRINGS (1 << 1)
+
+typedef struct language {
+ char *filetype;
+ int flags;
+ char *singleline_comment_start;
+ char *multiline_comment_start;
+ char *multiline_comment_end;
+ char **keywords;
+ char **extensions;
+} language;
+
+int is_separator(int c);
void update_highlight(row *row);
char *syntax_to_color(int hl, size_t *len);
+void select_syntax_highlight();
#endif
diff --git a/include/term.h b/include/term.h
@@ -1,6 +1,8 @@
#ifndef TERM_H_
#define TERM_H_
+#define CTRL_KEY(k) ((k) & 0x1f)
+
void die(const char *s);
void reset_term();
void setup_term();
diff --git a/include/vip.h b/include/vip.h
@@ -4,35 +4,10 @@
#include <termios.h>
#include <time.h>
-/* CONFIG */
-#define TAB_SIZE 4
-
#define VERSION "0.0.1"
-/* number of times of warning before quitting when there is modified text */
-#define QUIT_CONFIRM 1
-
-/* THEME */
-/* 38 and 48 is reversed as bar's color is reversed */
-
#define COLOR_LEN 19
-#define SURFACE_1_BG "\x1b[38;2;049;050;068m"
-#define BLACK_FG "\x1b[48;2;000;000;000m"
-#define BLACK_BG "\x1b[38;2;000;000;000m"
-#define WHITE_FG "\x1b[48;2;205;214;244m"
-#define WHITE_BG "\x1b[38;2;205;214;244m"
-#define BLUE_FG "\x1b[48;2;137;180;250m"
-#define BLUE_BG "\x1b[38;2;137;180;250m"
-#define GREEN_FG "\x1b[48;2;166;227;161m"
-#define GREEN_BG "\x1b[38;2;166;227;161m"
-#define PEACH_FG "\x1b[48;2;250;179;135m"
-#define PEACH_BG "\x1b[38;2;250;179;135m"
-#define SKY_FG "\x1b[48;2;137;220;235m"
-#define SKY_BG "\x1b[38;2;137;220;235m"
-
-#define CTRL_KEY(k) ((k) & 0x1f)
-
enum keys {
BACKSPACE = 127,
ARROW_LEFT = 1000,
@@ -54,19 +29,20 @@ enum modes {
};
enum highlight {
- HL_NORMAL = 0,
- HL_NUMBER,
- HL_MATCH,
- HL_RESET
+ DEFAULT = 0,
+ COMMENT,
+ MLCOMMENT,
+ KEYWORD1, /* default */
+ KEYWORD2, /* types */
+ STRING,
+ NUMBER,
+ MATCH,
+ RESET
};
-typedef struct row {
- int size;
- int render_size;
- char *chars;
- char *render;
- unsigned char *hl;
-} row;
+#include "row.h"
+#include "syntax.h"
+#include "config.h"
typedef struct editor {
int cx, cy; /* chars x, y */
@@ -81,6 +57,7 @@ typedef struct editor {
char *filename;
char statusmsg[80];
time_t statusmsg_time;
+ language *syntax;
struct termios termios;
} editor;
@@ -90,14 +67,8 @@ struct abuf {
};
#define ABUF_INIT { NULL, 0 }
-
void abAppend(struct abuf *ab, const char *s, int len);
-
-int read_key();
-void refresh_screen();
-void append_row(char *s, size_t len);
-void row_insert_char(row *row, int at, int c);
-void row_del_char(row *row, int at);
+void abFree(struct abuf *ab);
extern editor vip;