build: include dvtm terminfo entries in standalone builds
[vis.git] / ui.h
blobc2e9bf39928d4352f8ce334720294e2998081955
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 fo 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_COLOR_COLUMN,
45 UI_STYLE_STATUS,
46 UI_STYLE_STATUS_FOCUSED,
47 UI_STYLE_SEPARATOR,
48 UI_STYLE_INFO,
49 UI_STYLE_EOF,
50 UI_STYLE_MAX,
53 #if CONFIG_CURSES
54 typedef uint64_t CellAttr;
55 typedef short CellColor;
57 static inline bool cell_color_equal(CellColor c1, CellColor c2) {
58 return c1 == c2;
60 #else
61 typedef uint8_t CellAttr;
62 typedef struct {
63 uint8_t r, g, b;
64 uint8_t index;
65 } CellColor;
67 static inline bool cell_color_equal(CellColor c1, CellColor c2) {
68 if (c1.index != (uint8_t)-1 || c2.index != (uint8_t)-1)
69 return c1.index == c2.index;
70 return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b;
73 #endif
75 typedef struct {
76 CellAttr attr;
77 CellColor fg, bg;
78 } CellStyle;
80 #include "vis.h"
81 #include "text.h"
82 #include "view.h"
84 struct Ui {
85 bool (*init)(Ui*, Vis*);
86 void (*free)(Ui*);
87 void (*resize)(Ui*);
88 UiWin* (*window_new)(Ui*, Win*, enum UiOption);
89 void (*window_free)(UiWin*);
90 void (*window_focus)(UiWin*);
91 void (*window_swap)(UiWin*, UiWin*);
92 void (*die)(Ui*, const char *msg, va_list ap) __attribute__((noreturn));
93 void (*info)(Ui*, const char *msg, va_list ap);
94 void (*info_hide)(Ui*);
95 void (*arrange)(Ui*, enum UiLayout);
96 void (*draw)(Ui*);
97 void (*redraw)(Ui*);
98 void (*suspend)(Ui*);
99 void (*resume)(Ui*);
100 bool (*getkey)(Ui*, TermKeyKey*);
101 void (*terminal_save)(Ui*);
102 void (*terminal_restore)(Ui*);
103 TermKey* (*termkey_get)(Ui*);
104 int (*colors)(Ui*);
107 struct UiWin {
108 CellStyle (*style_get)(UiWin*, enum UiStyle);
109 void (*status)(UiWin*, const char *txt);
110 void (*options_set)(UiWin*, enum UiOption);
111 enum UiOption (*options_get)(UiWin*);
112 bool (*style_define)(UiWin*, int id, const char *style);
113 int (*window_width)(UiWin*);
114 int (*window_height)(UiWin*);
117 #endif