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_ #ifndef EDITOR_H_
#define EDITOR_H_ #define EDITOR_H_
void refresh_screen();
void move_cursor(int key);
void scroll();
void insert_char(int c); void insert_char(int c);
void insert_new_line(); void insert_new_line();
void shift_new_line(); void shift_new_line();
void del_char(); void del_char();
void init_editor();
void open_editor(char *filename); void open_editor(char *filename);
char *prompt_editor(char *prompt, void (*callback)(char *, int)); char *prompt_editor(char *prompt, void (*callback)(char *, int));
void find_editor(); 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_ #ifndef ROW_H_
#define 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_cx_to_rx(row *row, int cx);
int row_rx_to_cx(row *row, int rx); int row_rx_to_cx(row *row, int rx);
void update_row(row *row); void update_row(row *row);

View file

@ -1,7 +1,26 @@
#ifndef SYNTAX_H_ #ifndef SYNTAX_H_
#define 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); void update_highlight(row *row);
char *syntax_to_color(int hl, size_t *len); char *syntax_to_color(int hl, size_t *len);
void select_syntax_highlight();
#endif #endif

View file

@ -1,6 +1,8 @@
#ifndef TERM_H_ #ifndef TERM_H_
#define TERM_H_ #define TERM_H_
#define CTRL_KEY(k) ((k) & 0x1f)
void die(const char *s); void die(const char *s);
void reset_term(); void reset_term();
void setup_term(); void setup_term();

View file

@ -4,35 +4,10 @@
#include <termios.h> #include <termios.h>
#include <time.h> #include <time.h>
/* CONFIG */
#define TAB_SIZE 4
#define VERSION "0.0.1" #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 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 { enum keys {
BACKSPACE = 127, BACKSPACE = 127,
ARROW_LEFT = 1000, ARROW_LEFT = 1000,
@ -54,19 +29,20 @@ enum modes {
}; };
enum highlight { enum highlight {
HL_NORMAL = 0, DEFAULT = 0,
HL_NUMBER, COMMENT,
HL_MATCH, MLCOMMENT,
HL_RESET KEYWORD1, /* default */
KEYWORD2, /* types */
STRING,
NUMBER,
MATCH,
RESET
}; };
typedef struct row { #include "row.h"
int size; #include "syntax.h"
int render_size; #include "config.h"
char *chars;
char *render;
unsigned char *hl;
} row;
typedef struct editor { typedef struct editor {
int cx, cy; /* chars x, y */ int cx, cy; /* chars x, y */
@ -81,6 +57,7 @@ typedef struct editor {
char *filename; char *filename;
char statusmsg[80]; char statusmsg[80];
time_t statusmsg_time; time_t statusmsg_time;
language *syntax;
struct termios termios; struct termios termios;
} editor; } editor;
@ -90,14 +67,8 @@ struct abuf {
}; };
#define ABUF_INIT { NULL, 0 } #define ABUF_INIT { NULL, 0 }
void abAppend(struct abuf *ab, const char *s, int len); void abAppend(struct abuf *ab, const char *s, int len);
void abFree(struct abuf *ab);
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);
extern editor vip; extern editor vip;