forked from martanne/vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.h
111 lines (98 loc) · 2.53 KB
/
ui.h
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
#ifndef UI_H
#define UI_H
#include <stdbool.h>
#include <stdarg.h>
#include <termkey.h>
/* enable large file optimization for files larger than: */
#define UI_LARGE_FILE_SIZE (1 << 25)
/* enable large file optimization for files containing lines longer than: */
#define UI_LARGE_FILE_LINE_SIZE (1 << 16)
typedef struct Ui Ui;
typedef struct UiWin UiWin;
enum UiLayout {
UI_LAYOUT_HORIZONTAL,
UI_LAYOUT_VERTICAL,
};
enum UiOption {
UI_OPTION_NONE = 0,
UI_OPTION_LINE_NUMBERS_ABSOLUTE = 1 << 0,
UI_OPTION_LINE_NUMBERS_RELATIVE = 1 << 1,
UI_OPTION_SYMBOL_SPACE = 1 << 2,
UI_OPTION_SYMBOL_TAB = 1 << 3,
UI_OPTION_SYMBOL_TAB_FILL = 1 << 4,
UI_OPTION_SYMBOL_EOL = 1 << 5,
UI_OPTION_SYMBOL_EOF = 1 << 6,
UI_OPTION_CURSOR_LINE = 1 << 7,
UI_OPTION_STATUSBAR = 1 << 8,
UI_OPTION_ONELINE = 1 << 9,
UI_OPTION_LARGE_FILE = 1 << 10,
};
enum UiStyle {
UI_STYLE_LEXER_MAX = 64,
UI_STYLE_DEFAULT,
UI_STYLE_CURSOR,
UI_STYLE_CURSOR_PRIMARY,
UI_STYLE_CURSOR_LINE,
UI_STYLE_SELECTION,
UI_STYLE_LINENUMBER,
UI_STYLE_LINENUMBER_CURSOR,
UI_STYLE_COLOR_COLUMN,
UI_STYLE_STATUS,
UI_STYLE_STATUS_FOCUSED,
UI_STYLE_SEPARATOR,
UI_STYLE_INFO,
UI_STYLE_EOF,
UI_STYLE_MAX,
};
#if CONFIG_CURSES
typedef uint64_t CellAttr;
typedef short CellColor;
#else
typedef uint8_t CellAttr;
typedef struct {
uint8_t r, g, b;
uint8_t index;
} CellColor;
#endif
typedef struct {
CellAttr attr;
CellColor fg, bg;
} CellStyle;
#include "vis.h"
#include "text.h"
#include "view.h"
struct Ui {
bool (*init)(Ui*, Vis*);
void (*free)(Ui*);
void (*resize)(Ui*);
UiWin* (*window_new)(Ui*, Win*, enum UiOption);
void (*window_free)(UiWin*);
void (*window_focus)(UiWin*);
void (*window_swap)(UiWin*, UiWin*);
void (*die)(Ui*, const char *msg, va_list ap) __attribute__((noreturn));
void (*info)(Ui*, const char *msg, va_list ap);
void (*info_hide)(Ui*);
void (*arrange)(Ui*, enum UiLayout);
void (*draw)(Ui*);
void (*redraw)(Ui*);
void (*suspend)(Ui*);
void (*resume)(Ui*);
void (*doupdates)(Ui*, bool);
bool (*getkey)(Ui*, TermKeyKey*);
void (*terminal_save)(Ui*, bool fscr);
void (*terminal_restore)(Ui*);
TermKey* (*termkey_get)(Ui*);
int (*colors)(Ui*);
};
struct UiWin {
void (*style_set)(UiWin*, Cell*, enum UiStyle);
bool (*style_set_pos)(UiWin*, int x, int y, enum UiStyle);
void (*status)(UiWin*, const char *txt);
void (*options_set)(UiWin*, enum UiOption);
enum UiOption (*options_get)(UiWin*);
bool (*style_define)(UiWin*, int id, const char *style);
int (*window_width)(UiWin*);
int (*window_height)(UiWin*);
};
enum UiLayout ui_layout_get(Ui *ui);
#endif