view: do not highlight matching symbols if selection is active
[vis.git] / view.h
blobf763a21b7d6234551af8739b6ba27426393a08da
1 #ifndef VIEW_H
2 #define VIEW_H
4 #include <stddef.h>
5 #include <stdbool.h>
6 #include <lua.h>
7 #include "register.h"
8 #include "text.h"
9 #include "ui.h"
10 #include "syntax.h"
12 typedef struct View View;
13 typedef struct Cursor Cursor;
14 typedef struct Selection Selection;
16 typedef struct {
17 void *data;
18 void (*selection)(void *data, Filerange*);
19 } ViewEvent;
21 typedef struct {
22 int width; /* display width i.e. number of columns ocupied by this character */
23 size_t len; /* number of bytes the character displayed in this cell uses, for
24 character which use more than 1 column to display, their lenght
25 is stored in the leftmost cell wheras all following cells
26 occupied by the same character have a length of 0. */
27 char data[8]; /* utf8 encoded character displayed in this cell might not be the
28 the same as in the underlying text, for example tabs get expanded */
29 unsigned int attr;
30 bool istab;
31 bool selected; /* whether this cell is part of a selected region */
32 bool cursor; /* whether a cursor is currently locaated on the cell */
33 } Cell;
35 typedef struct Line Line;
36 struct Line { /* a line on the screen, *not* in the file */
37 Line *prev, *next; /* pointer to neighbouring screen lines */
38 size_t len; /* line length in terms of bytes */
39 size_t lineno; /* line number from start of file */
40 int width; /* zero based position of last used column cell */
41 Cell cells[]; /* win->width cells storing information about the displayed characters */
44 typedef struct {
45 size_t line;
46 size_t col;
47 } CursorPos;
49 View *view_new(Text*, lua_State*, ViewEvent*);
50 void view_ui(View*, UiWin*);
51 /* change associated text displayed in this window */
52 void view_reload(View*, Text*);
53 void view_free(View*);
55 bool view_resize(View*, int width, int height);
56 int view_height_get(View*);
57 int view_width_get(View*);
58 void view_draw(View*);
59 void view_update(View*);
60 /* changes how many spaces are used for one tab (must be >0), redraws the window */
61 void view_tabwidth_set(View*, int tabwidth);
63 /* cursor movements which also update selection if one is active.
64 * they return new cursor postion */
65 size_t view_line_down(Cursor*);
66 size_t view_line_up(Cursor*);
67 size_t view_screenline_down(Cursor*);
68 size_t view_screenline_up(Cursor*);
69 size_t view_screenline_begin(Cursor*);
70 size_t view_screenline_middle(Cursor*);
71 size_t view_screenline_end(Cursor*);
72 /* move window content up/down, but keep cursor position unchanged unless it is
73 * on a now invisible line in which case we try to preserve the column position */
74 size_t view_slide_up(View*, int lines);
75 size_t view_slide_down(View*, int lines);
76 /* scroll window contents up/down by lines, place the cursor on the newly
77 * visible line, try to preserve the column position */
78 size_t view_scroll_up(View*, int lines);
79 size_t view_scroll_down(View*, int lines);
80 /* place the cursor at the start ot the n-th window line, counting from 1 */
81 size_t view_screenline_goto(View*, int n);
83 const Line *view_lines_get(View*);
84 /* redraw current cursor line at top/center/bottom of window */
85 void view_redraw_top(View*);
86 void view_redraw_center(View*);
87 void view_redraw_bottom(View*);
88 /* get the currently displayed area in bytes from the start of the file */
89 Filerange view_viewport_get(View*);
90 /* move visible viewport n-lines up/down, redraws the view but does not change
91 * cursor position which becomes invalid and should be corrected by calling
92 * view_cursor_to. the return value indicates wether the visible area changed.
94 bool view_viewport_up(View *view, int n);
95 bool view_viewport_down(View *view, int n);
96 /* associate a set of syntax highlighting rules to this window. */
97 bool view_syntax_set(View*, const char *name);
98 const char *view_syntax_get(View*);
100 void view_options_set(View*, enum UiOption options);
101 enum UiOption view_options_get(View*);
102 void view_colorcolumn_set(View*, int col);
103 int view_colorcolumn_get(View*);
105 /* A view can manage multiple cursors, one of which (the main cursor) is always
106 * placed within the visible viewport. All functions named view_cursor_* operate
107 * on this cursor. Additional cursor can be created and manipulated using the
108 * functions named view_cursors_* */
110 /* get main cursor position in terms of screen coordinates */
111 CursorPos view_cursor_getpos(View*);
112 /* get main cursor position in bytes from start of the file */
113 size_t view_cursor_get(View*);
114 /* moves window viewport in direction until pos is visible. should only be
115 * used for short distances between current cursor position and destination */
116 void view_scroll_to(View*, size_t pos);
117 /* move cursor to a given position. changes the viewport to make sure that
118 * position is visible. if the position is in the middle of a line, try to
119 * adjust the viewport in such a way that the whole line is displayed */
120 void view_cursor_to(View*, size_t pos);
121 /* create a new cursor */
122 Cursor *view_cursors_new(View*);
123 /* get number of active cursors */
124 int view_cursors_count(View*);
125 /* dispose an existing cursor with its associated selection (if any),
126 * not applicaple for the last existing cursor */
127 void view_cursors_dispose(Cursor*);
128 /* only keep the main cursor, release all others together with their
129 * selections (if any) */
130 void view_cursors_clear(View*);
131 /* get the main cursor which is always in the visible viewport */
132 Cursor *view_cursor(View*);
133 /* get the first cursor */
134 Cursor *view_cursors(View*);
135 Cursor *view_cursors_prev(Cursor*);
136 Cursor *view_cursors_next(Cursor*);
137 /* get current position of cursor in bytes from the start of the file */
138 size_t view_cursors_pos(Cursor*);
139 /* place cursor at `pos' which should be in the interval [0, text-size] */
140 void view_cursors_to(Cursor*, size_t pos);
141 void view_cursors_scroll_to(Cursor*, size_t pos);
142 /* get register associated with this register */
143 Register *view_cursors_register(Cursor*);
144 /* start selected area at current cursor position. further cursor movements
145 * will affect the selected region. */
146 void view_cursors_selection_start(Cursor*);
147 /* detach cursor from selection, further cursor movements will not affect
148 * the selected region. */
149 void view_cursors_selection_stop(Cursor*);
150 /* clear selection associated with this cursor (if any) */
151 void view_cursors_selection_clear(Cursor*);
152 /* move cursor position from one end of the selection to the other */
153 void view_cursors_selection_swap(Cursor*);
154 /* move cursor to the end/boundary of the associated selection */
155 void view_cursors_selection_sync(Cursor*);
156 /* restore previous used selection of this cursor */
157 void view_cursors_selection_restore(Cursor*);
158 /* get/set the selected region associated with this cursor */
159 Filerange view_cursors_selection_get(Cursor*);
160 void view_cursors_selection_set(Cursor*, Filerange*);
162 Selection *view_selections_new(View*);
163 void view_selections_free(Selection*);
164 void view_selections_clear(View*);
165 void view_selections_swap(Selection*);
166 Selection *view_selections(View*);
167 Selection *view_selections_prev(Selection*);
168 Selection *view_selections_next(Selection*);
169 Filerange view_selections_get(Selection*);
170 void view_selections_set(Selection*, Filerange*);
172 #endif