Refactor header files

This commit is contained in:
Night Kaly 2024-07-04 17:00:13 +01:00
parent d31914433f
commit f4724e668c
Signed by: night0721
GPG key ID: 957D67B8DB7A119B
6 changed files with 58 additions and 43 deletions

View file

@ -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();

9
include/io.h Normal file
View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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();

View file

@ -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;