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