aboutsummaryrefslogtreecommitdiff
path: root/vis.h
blob: fe504ab69c4cbdf7be3fc4a392593579a73a1ff1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef VIS_H
#define VIS_H

#include <stddef.h>
#include <regex.h>
#include "text-motions.h"
#include "text-objects.h"
#include "window.h"
#include "register.h"

typedef struct Vis Vis;
typedef struct VisWin VisWin;

struct VisWin {
	Vis *vis;            /* editor instance to which this window belongs */
	Text *text;          /* underlying text management */
	Win *win;            /* vis window for the text area  */
	WINDOW *statuswin;   /* curses window for the statusbar */
	int width, height;   /* window size including the statusbar */
	VisWin *prev, *next; /* neighbouring windows */
};

typedef void (*vis_statusbar_t)(WINDOW *win, bool active, const char *filename, size_t line, size_t col);

enum Reg {
	REG_a,
	REG_b,
	REG_c,
	// ...
	REG_z,
	REG_DEFAULT,
	REG_LAST,
};

enum Mark {
	MARK_a,
	MARK_b,
	MARK_c,
	// ...
	MARK_z,
	MARK_LAST,
};

struct Vis {
	int width, height;             /* terminal size, available for all windows */
	VisWin *windows;               /* list of windows */
	VisWin *win;                   /* currently active window */
	Syntax *syntaxes;              /* NULL terminated array of syntax definitions */
	Register registers[REG_LAST];
	void (*windows_arrange)(Vis*); /* current layout which places the windows */
	vis_statusbar_t statusbar;     /* configurable user hook to draw statusbar */
};


typedef struct {
	short fg, bg;   /* fore and background color */
	int attr;       /* curses attributes */
} Color;

typedef struct {
	char *rule;     /* regex to search for */
	int cflags;     /* compilation flags (REG_*) used when compiling */
	Color color;    /* settings to apply in case of a match */
	regex_t regex;  /* compiled form of the above rule */
} SyntaxRule;

#define SYNTAX_REGEX_RULES 10

typedef struct Syntax Syntax;

struct Syntax {                              /* a syntax definition */
	char *name;                           /* syntax name */
	char *file;                           /* apply to files matching this regex */
	regex_t file_regex;                   /* compiled file name regex */
	SyntaxRule rules[SYNTAX_REGEX_RULES]; /* all rules for this file type */
};

Vis *vis_new(int width, int height);
void vis_free(Vis*); 
void vis_resize(Vis*, int width, int height); 
void vis_snapshot(Vis*);
void vis_undo(Vis*);
void vis_redo(Vis*);
void vis_draw(Vis*);
void vis_update(Vis*);
void vis_insert_key(Vis*, const char *c, size_t len);
void vis_replace_key(Vis*, const char *c, size_t len);
void vis_backspace_key(Vis*);
void vis_delete_key(Vis*);
void vis_insert(Vis*, size_t pos, const char *data, size_t len);
void vis_delete(Vis*, size_t pos, size_t len);

// TODO comment
bool vis_syntax_load(Vis*, Syntax *syntaxes, Color *colors);
void vis_syntax_unload(Vis*);

void vis_search(Vis*, const char *regex, int direction);

bool vis_window_new(Vis*, const char *filename);
void vis_window_split(Vis*, const char *filename);
void vis_window_vsplit(Vis*, const char *filename);
void vis_window_next(Vis*);
void vis_window_prev(Vis*);

void vis_statusbar_set(Vis*, vis_statusbar_t);

/* library initialization code, should be run at startup */
void vis_init(void);
short vis_color_reserve(short fg, short bg);
short vis_color_get(short fg, short bg);

#endif