7 typedef struct View View
;
8 typedef struct Selection Selection
;
20 char data
[16]; /* utf8 encoded character displayed in this cell (might be more than
21 one Unicode codepoint. might also not be the same as in the
22 underlying text, for example tabs get expanded */
23 size_t len
; /* number of bytes the character displayed in this cell uses, for
24 characters which use more than 1 column to display, their length
25 is stored in the leftmost cell whereas all following cells
26 occupied by the same character have a length of 0. */
27 int width
; /* display width i.e. number of columns occupied by this character */
28 CellStyle style
; /* colors and attributes used to display this cell */
31 typedef struct Line Line
;
32 struct Line
{ /* a line on the screen, *not* in the file */
33 Line
*prev
, *next
; /* pointer to neighbouring screen lines */
34 size_t len
; /* line length in terms of bytes */
35 size_t lineno
; /* line number from start of file */
36 int width
; /* zero based position of last used column cell */
37 Cell cells
[]; /* win->width cells storing information about the displayed characters */
44 View
*view_new(Text
*);
45 void view_free(View
*);
46 void view_ui(View
*, UiWin
*);
47 Text
*view_text(View
*);
48 void view_reload(View
*, Text
*);
51 * @defgroup view_viewport
54 /** Get the currently displayed text range. */
55 Filerange
view_viewport_get(View
*);
57 * Get window coordinate of text position.
58 * @param pos The position to query.
59 * @param line Will be updated with screen line on which `pos` resides.
60 * @param row Will be updaded with zero based window row on which `pos` resides.
61 * @param line Will be updated with zero based window column which `pos` resides.
62 * @return Whether `pos` is visible. If not, the pointer arguments are left unmodified.
64 bool view_coord_get(View
*, size_t pos
, Line
**line
, int *row
, int *col
);
65 /** Get position at the start ot the `n`-th window line, counting from 1. */
66 size_t view_screenline_goto(View
*, int n
);
67 /** Get first screen line. */
68 Line
*view_lines_first(View
*);
69 /** Get last non-empty screen line. */
70 Line
*view_lines_last(View
*);
71 size_t view_slide_up(View
*, int lines
);
72 size_t view_slide_down(View
*, int lines
);
73 size_t view_scroll_up(View
*, int lines
);
74 size_t view_scroll_down(View
*, int lines
);
75 size_t view_scroll_page_up(View
*);
76 size_t view_scroll_page_down(View
*);
77 size_t view_scroll_halfpage_up(View
*);
78 size_t view_scroll_halfpage_down(View
*);
79 void view_redraw_top(View
*);
80 void view_redraw_center(View
*);
81 void view_redraw_bottom(View
*);
82 void view_scroll_to(View
*, size_t pos
);
88 bool view_resize(View
*, int width
, int height
);
89 int view_height_get(View
*);
90 int view_width_get(View
*);
96 void view_invalidate(View
*);
97 void view_draw(View
*);
98 bool view_update(View
*);
102 * @defgroup view_selnew
106 * Create a new singleton selection at the given position.
108 * .. note:: New selections are created non-anchored.
109 * .. warning:: Fails if position is already covered by a selection.
112 Selection
*view_selections_new(View
*, size_t pos
);
114 * Create a new selection even if position is already covered by an
115 * existing selection.
117 * .. note:: This should only be used if the old selection is eventually
121 Selection
*view_selections_new_force(View
*, size_t pos
);
123 * Dispose an existing selection.
125 * .. warning:: Not applicaple for the last existing selection.
128 bool view_selections_dispose(Selection
*);
130 * Forcefully dispose an existing selection.
132 * If called for the last existing selection, it will be reduced and
133 * marked for destruction. As soon as a new selection is created this one
136 bool view_selections_dispose_force(Selection
*);
138 * Query state of primary selection.
140 * If the primary selection was marked for destruction, return it and
141 * clear descruction flag.
143 Selection
*view_selection_disposed(View
*);
144 /** Dispose all but the primary selection. */
145 void view_selections_dispose_all(View
*);
146 /** Dispose all invalid and merge all overlapping selections. */
147 void view_selections_normalize(View
*);
149 * Replace currently active selections.
150 * @param array The Array of ``Filerange``s.
151 * @param anchored Whether *all* selection should be anchored.
153 void view_selections_set_all(View
*, Array
*, bool anchored
);
154 /** Get array containing a ``Fileranges`` for each selection. */
155 Array
view_selections_get_all(View
*);
158 * @defgroup view_navigate
161 Selection
*view_selections_primary_get(View
*);
162 void view_selections_primary_set(Selection
*);
163 /** Get first selection. */
164 Selection
*view_selections(View
*);
165 /** Get immediate predecessor of selection. */
166 Selection
*view_selections_prev(Selection
*);
167 /** Get immediate successor of selection. */
168 Selection
*view_selections_next(Selection
*);
170 * Get number of existing selections.
172 * .. note:: Is always at least 1.
175 int view_selections_count(View
*);
177 * Get selection index.
179 * .. note:: Is always in range `[0, count-1]`.
180 * .. warning: The relative order is determined during creation and assumed
181 * to remain the same.
184 int view_selections_number(Selection
*);
185 /** Get maximal number of selections on a single line. */
186 int view_selections_column_count(View
*);
188 * Starting from the start of the text, get the `column`-th selection on a line.
189 * @param column The zero based column index.
191 Selection
*view_selections_column(View
*, int column
);
193 * Get the next `column`-th selection on a line.
194 * @param column The zero based column index.
196 Selection
*view_selections_column_next(Selection
*, int column
);
199 * @defgroup view_cover
202 /** Get an inclusive range of the selection cover. */
203 Filerange
view_selections_get(Selection
*);
204 /** Set selection cover. Updates both cursor and anchor. */
205 bool view_selections_set(Selection
*, const Filerange
*);
207 * Reduce selection to character currently covered by the cursor.
209 * .. note:: Sets selection to non-anchored mode.
212 void view_selection_clear(Selection
*);
213 /** Reduce *all* currently active selections. */
214 void view_selections_clear_all(View
*);
216 * Flip selection orientation. Swap cursor and anchor.
218 * .. note:: Has no effect on singleton selections.
221 void view_selections_flip(Selection
*);
224 * @defgroup view_anchor
229 * Further updates will only update the cursor, the anchor will remain fixed.
231 void view_selections_anchor(Selection
*, bool anchored
);
232 /** Check whether selection is anchored. */
233 bool view_selections_anchored(Selection
*);
234 /** Get position of selection cursor. */
237 * @defgroup view_props
240 /** Get position of selection cursor. */
241 size_t view_cursors_pos(Selection
*);
242 /** Get 1-based line number of selection cursor. */
243 size_t view_cursors_line(Selection
*);
245 * Get 1-based column of selection cursor.
247 * .. note:: Counts the number of graphemes on the logical line up to the cursor
251 size_t view_cursors_col(Selection
*);
253 * Get screen line of selection cursor.
255 * .. warning: Is `NULL` for non-visible selections.
258 Line
*view_cursors_line_get(Selection
*);
260 * Get zero based index of screen cell on which selection cursor currently resides.
262 * .. warning:: Returns `-1` if the selection cursor is currently not visible.
265 int view_cursors_cell_get(Selection
*);
268 * @defgroup view_place
272 * Place cursor of selection at `pos`.
274 * .. note:: If the selection is not anchored, both selection endpoints
275 * will be adjusted to form a singleton selection covering one
276 * character starting at `pos`. Otherwise only the selection
277 * cursor will be changed while the anchor remains fixed.
280 void view_cursors_to(Selection
*, size_t pos
);
282 * Adjusts window viewport until the requested position becomes visible.
284 * .. note:: For all but the primary selection this is equivalent to
285 * ``view_selection_to``.
286 * .. warning:: Repeatedly redraws the window content. Should only be used for
287 * short distances between current cursor position and destination.
290 void view_cursors_scroll_to(Selection
*, size_t pos
);
292 * Place cursor on given (line, column) pair.
293 * @param line the 1-based line number
294 * @param col the 1 based column
296 * .. note:: Except for the different addressing format this is equivalent to
297 * `view_selection_to`.
300 void view_cursors_place(Selection
*, size_t line
, size_t col
);
302 * Place selection cursor on zero based window cell index.
304 * .. warning:: Fails if the selection cursor is currently not visible.
307 int view_cursors_cell_set(Selection
*, int cell
);
310 * @defgroup view_motions
313 size_t view_line_down(Selection
*);
314 size_t view_line_up(Selection
*);
315 size_t view_screenline_down(Selection
*);
316 size_t view_screenline_up(Selection
*);
317 size_t view_screenline_begin(Selection
*);
318 size_t view_screenline_middle(Selection
*);
319 size_t view_screenline_end(Selection
*);
322 * @defgroup view_primary
326 * Move primary selection cursor to the given position.
327 * Makes sure that position is visisble.
329 * .. note:: If position was not visible before, we attempt to show
330 * surrounding context. The viewport will be adjusted such
331 * that the line holding the cursor is shown in the middle
335 void view_cursor_to(View
*, size_t pos
);
336 /** Get cursor position of primary selection. */
337 size_t view_cursor_get(View
*);
339 * Get primary selection.
341 * .. note:: Is always a non-empty range.
344 Filerange
view_selection_get(View
*);
347 * @defgroup view_save
350 Filerange
view_regions_restore(View
*, SelectionRegion
*);
351 bool view_regions_save(View
*, Filerange
*, SelectionRegion
*);
354 * @defgroup view_style
357 void view_options_set(View
*, enum UiOption options
);
358 enum UiOption
view_options_get(View
*);
359 void view_colorcolumn_set(View
*, int col
);
360 int view_colorcolumn_get(View
*);
362 /** Set how many spaces are used to display a tab `\t` character. */
363 void view_tabwidth_set(View
*, int tabwidth
);
364 /** Define a display style. */
365 bool view_style_define(View
*, enum UiStyle
, const char *style
);
366 /** Apply a style to a text range. */
367 void view_style(View
*, enum UiStyle
, size_t start
, size_t end
);
369 char *view_symbol_eof_get(View
*);