2024-06-30 20:55:59 +02:00
|
|
|
#ifndef VIP_H_
|
|
|
|
#define VIP_H_
|
|
|
|
|
|
|
|
#include <termios.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
/* CONFIG */
|
|
|
|
#define TAB_SIZE 4
|
|
|
|
|
2024-07-03 03:41:28 +02:00
|
|
|
#define VERSION "0.0.1"
|
|
|
|
|
2024-07-02 23:56:09 +02:00
|
|
|
/* number of times of warning before quitting when there is modified text */
|
2024-07-03 10:58:51 +02:00
|
|
|
#define QUIT_CONFIRM 1
|
2024-07-02 23:56:09 +02:00
|
|
|
|
|
|
|
/* THEME */
|
|
|
|
/* 38 and 48 is reversed as bar's color is reversed */
|
2024-07-03 14:12:41 +02:00
|
|
|
|
|
|
|
#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"
|
2024-06-30 20:55:59 +02:00
|
|
|
|
2024-07-03 12:11:48 +02:00
|
|
|
#define CTRL_KEY(k) ((k) & 0x1f)
|
|
|
|
|
|
|
|
enum keys {
|
|
|
|
BACKSPACE = 127,
|
|
|
|
ARROW_LEFT = 1000,
|
|
|
|
ARROW_RIGHT,
|
|
|
|
ARROW_UP,
|
|
|
|
ARROW_DOWN,
|
|
|
|
DEL_KEY,
|
|
|
|
HOME_KEY,
|
|
|
|
END_KEY,
|
|
|
|
PAGE_UP,
|
|
|
|
PAGE_DOWN
|
|
|
|
};
|
|
|
|
|
2024-07-03 14:12:41 +02:00
|
|
|
enum modes {
|
|
|
|
NORMAL,
|
|
|
|
INSERT,
|
|
|
|
VISUAL,
|
|
|
|
COMMAND
|
|
|
|
};
|
|
|
|
|
|
|
|
enum highlight {
|
|
|
|
HL_NORMAL = 0,
|
|
|
|
HL_NUMBER,
|
|
|
|
HL_MATCH,
|
|
|
|
HL_RESET
|
|
|
|
};
|
|
|
|
|
2024-06-30 20:55:59 +02:00
|
|
|
typedef struct row {
|
|
|
|
int size;
|
|
|
|
int render_size;
|
|
|
|
char *chars;
|
|
|
|
char *render;
|
2024-07-03 14:12:41 +02:00
|
|
|
unsigned char *hl;
|
2024-06-30 20:55:59 +02:00
|
|
|
} row;
|
|
|
|
|
|
|
|
typedef struct editor {
|
|
|
|
int cx, cy; /* chars x, y */
|
2024-07-03 14:12:41 +02:00
|
|
|
int rx; /* render x */
|
2024-06-30 20:55:59 +02:00
|
|
|
int rowoff;
|
|
|
|
int coloff;
|
|
|
|
int screenrows, screencols;
|
|
|
|
int rows;
|
|
|
|
row *row;
|
2024-07-02 23:56:09 +02:00
|
|
|
int dirty;
|
2024-07-03 03:41:28 +02:00
|
|
|
int mode;
|
2024-06-30 20:55:59 +02:00
|
|
|
char *filename;
|
|
|
|
char statusmsg[80];
|
|
|
|
time_t statusmsg_time;
|
|
|
|
struct termios termios;
|
|
|
|
} editor;
|
|
|
|
|
|
|
|
struct abuf {
|
|
|
|
char *b;
|
|
|
|
int len;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ABUF_INIT { NULL, 0 }
|
|
|
|
|
|
|
|
void abAppend(struct abuf *ab, const char *s, int len);
|
|
|
|
|
2024-07-03 12:11:48 +02:00
|
|
|
int read_key();
|
|
|
|
void refresh_screen();
|
2024-07-01 21:40:07 +02:00
|
|
|
void append_row(char *s, size_t len);
|
|
|
|
void row_insert_char(row *row, int at, int c);
|
2024-07-03 03:41:28 +02:00
|
|
|
void row_del_char(row *row, int at);
|
2024-07-01 21:40:07 +02:00
|
|
|
|
2024-06-30 20:55:59 +02:00
|
|
|
extern editor vip;
|
|
|
|
|
|
|
|
#endif
|