filetype: Set "groovy" for Jenkinsfile
[vis.git] / ui.h
blobd87384ae645bc25c3c4f4908e468ec45cf1deda6
1 #ifndef UI_H
2 #define UI_H
4 #include <stdbool.h>
5 #include <stdarg.h>
6 #include <termkey.h>
8 /* enable large file optimization for files larger than: */
9 #define UI_LARGE_FILE_SIZE (1 << 25)
10 /* enable large file optimization for files containing lines longer than: */
11 #define UI_LARGE_FILE_LINE_SIZE (1 << 16)
13 typedef struct Ui Ui;
14 typedef struct UiWin UiWin;
16 enum UiLayout {
17 UI_LAYOUT_HORIZONTAL,
18 UI_LAYOUT_VERTICAL,
21 enum UiOption {
22 UI_OPTION_NONE = 0,
23 UI_OPTION_LINE_NUMBERS_ABSOLUTE = 1 << 0,
24 UI_OPTION_LINE_NUMBERS_RELATIVE = 1 << 1,
25 UI_OPTION_SYMBOL_SPACE = 1 << 2,
26 UI_OPTION_SYMBOL_TAB = 1 << 3,
27 UI_OPTION_SYMBOL_TAB_FILL = 1 << 4,
28 UI_OPTION_SYMBOL_EOL = 1 << 5,
29 UI_OPTION_SYMBOL_EOF = 1 << 6,
30 UI_OPTION_CURSOR_LINE = 1 << 7,
31 UI_OPTION_STATUSBAR = 1 << 8,
32 UI_OPTION_ONELINE = 1 << 9,
33 UI_OPTION_LARGE_FILE = 1 << 10,
36 enum UiStyle {
37 UI_STYLE_LEXER_MAX = 64,
38 UI_STYLE_DEFAULT,
39 UI_STYLE_CURSOR,
40 UI_STYLE_CURSOR_PRIMARY,
41 UI_STYLE_CURSOR_LINE,
42 UI_STYLE_SELECTION,
43 UI_STYLE_LINENUMBER,
44 UI_STYLE_LINENUMBER_CURSOR,
45 UI_STYLE_COLOR_COLUMN,
46 UI_STYLE_STATUS,
47 UI_STYLE_STATUS_FOCUSED,
48 UI_STYLE_SEPARATOR,
49 UI_STYLE_INFO,
50 UI_STYLE_EOF,
51 UI_STYLE_MAX,
54 #if CONFIG_CURSES
55 typedef uint64_t CellAttr;
56 typedef short CellColor;
58 static inline bool cell_color_equal(CellColor c1, CellColor c2) {
59 return c1 == c2;
61 #else
62 typedef uint8_t CellAttr;
63 typedef struct {
64 uint8_t r, g, b;
65 uint8_t index;
66 } CellColor;
68 static inline bool cell_color_equal(CellColor c1, CellColor c2) {
69 if (c1.index != (uint8_t)-1 || c2.index != (uint8_t)-1)
70 return c1.index == c2.index;
71 return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b;
74 #endif
76 typedef struct {
77 CellAttr attr;
78 CellColor fg, bg;
79 } CellStyle;
81 #include "vis.h"
82 #include "text.h"
83 #include "view.h"
85 struct Ui {
86 bool (*init)(Ui*, Vis*);
87 void (*free)(Ui*);
88 void (*resize)(Ui*);
89 UiWin* (*window_new)(Ui*, Win*, enum UiOption);
90 void (*window_free)(UiWin*);
91 void (*window_focus)(UiWin*);
92 void (*window_swap)(UiWin*, UiWin*);
93 void (*die)(Ui*, const char *msg, va_list ap) __attribute__((noreturn));
94 void (*info)(Ui*, const char *msg, va_list ap);
95 void (*info_hide)(Ui*);
96 void (*arrange)(Ui*, enum UiLayout);
97 void (*draw)(Ui*);
98 void (*redraw)(Ui*);
99 void (*suspend)(Ui*);
100 void (*resume)(Ui*);
101 bool (*getkey)(Ui*, TermKeyKey*);
102 void (*terminal_save)(Ui*);
103 void (*terminal_restore)(Ui*);
104 TermKey* (*termkey_get)(Ui*);
105 int (*colors)(Ui*);
108 struct UiWin {
109 CellStyle (*style_get)(UiWin*, enum UiStyle);
110 void (*status)(UiWin*, const char *txt);
111 void (*options_set)(UiWin*, enum UiOption);
112 enum UiOption (*options_get)(UiWin*);
113 bool (*style_define)(UiWin*, int id, const char *style);
114 int (*window_width)(UiWin*);
115 int (*window_height)(UiWin*);
118 bool is_default_color(CellColor c);
120 #endif