make C-s and C-q available in key mappings
[vis/gkirilov.git] / ui.h
blob45b6065eb934e1c2190cd755cebd8adea8cbe2f9
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;
57 #else
58 typedef uint8_t CellAttr;
59 typedef struct {
60 uint8_t r, g, b;
61 uint8_t index;
62 } CellColor;
63 #endif
65 typedef struct {
66 CellAttr attr;
67 CellColor fg, bg;
68 } CellStyle;
70 #include "vis.h"
71 #include "text.h"
72 #include "view.h"
74 struct Ui {
75 bool (*init)(Ui*, Vis*);
76 void (*free)(Ui*);
77 void (*resize)(Ui*);
78 UiWin* (*window_new)(Ui*, Win*, enum UiOption);
79 void (*window_free)(UiWin*);
80 void (*window_focus)(UiWin*);
81 void (*window_swap)(UiWin*, UiWin*);
82 void (*die)(Ui*, const char *msg, va_list ap) __attribute__((noreturn));
83 void (*info)(Ui*, const char *msg, va_list ap);
84 void (*info_hide)(Ui*);
85 void (*arrange)(Ui*, enum UiLayout);
86 void (*draw)(Ui*);
87 void (*redraw)(Ui*);
88 void (*suspend)(Ui*);
89 void (*resume)(Ui*);
90 void (*doupdates)(Ui*, bool);
91 bool (*getkey)(Ui*, TermKeyKey*);
92 void (*terminal_save)(Ui*, bool fscr);
93 void (*terminal_restore)(Ui*);
94 TermKey* (*termkey_get)(Ui*);
95 int (*colors)(Ui*);
98 struct UiWin {
99 void (*style_set)(UiWin*, Cell*, enum UiStyle);
100 bool (*style_set_pos)(UiWin*, int x, int y, enum UiStyle);
101 void (*status)(UiWin*, const char *txt);
102 void (*options_set)(UiWin*, enum UiOption);
103 enum UiOption (*options_get)(UiWin*);
104 bool (*style_define)(UiWin*, int id, const char *style);
105 int (*window_width)(UiWin*);
106 int (*window_height)(UiWin*);
109 enum UiLayout ui_layout_get(Ui *ui);
111 #endif