Lines Matching +full:column +full:- +full:inversion
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
46 #define VTBUF_LOCK(vb) mtx_lock_spin(&(vb)->vb_lock)
47 #define VTBUF_UNLOCK(vb) mtx_unlock_spin(&(vb)->vb_lock)
63 * line5 <--- curroffset (terminal output to that line)
65 * line1 <--- roffset (history display from that point)
75 if ((vb->vb_flags & VBF_SCROLL) == 0) { in vthistory_seek()
76 if (vb->vb_roffset != vb->vb_curroffset) { in vthistory_seek()
77 vb->vb_roffset = vb->vb_curroffset; in vthistory_seek()
84 bottom = vb->vb_curroffset; in vthistory_seek()
85 top = (vb->vb_flags & VBF_HISTORY_FULL) ? in vthistory_seek()
86 bottom + vb->vb_scr_size.tp_row - vb->vb_history_size : in vthistory_seek()
101 roffset = vb->vb_roffset; in vthistory_seek()
102 if (roffset >= bottom + vb->vb_scr_size.tp_row) in vthistory_seek()
103 roffset -= vb->vb_history_size; in vthistory_seek()
110 roffset = vb->vb_history_size + roffset; in vthistory_seek()
115 roffset = vb->vb_curroffset; in vthistory_seek()
119 diff = vb->vb_roffset != roffset; in vthistory_seek()
120 vb->vb_roffset = roffset; in vthistory_seek()
132 vb->vb_curroffset += offset; in vthistory_addlines()
133 if (vb->vb_curroffset + vb->vb_scr_size.tp_row >= vb->vb_history_size) { in vthistory_addlines()
134 vb->vb_flags |= VBF_HISTORY_FULL; in vthistory_addlines()
135 vb->vb_curroffset %= vb->vb_history_size; in vthistory_addlines()
137 if ((vb->vb_flags & VBF_SCROLL) == 0) { in vthistory_addlines()
138 vb->vb_roffset = vb->vb_curroffset; in vthistory_addlines()
142 sz = vb->vb_history_size; in vthistory_addlines()
143 cur = vb->vb_roffset + vb->vb_scr_size.tp_row + sz - 1; in vthistory_addlines()
144 if (vtbuf_in_this_range(cur, vb->vb_mark_start.tp_row, cur + offset, sz) || in vthistory_addlines()
145 vtbuf_in_this_range(cur, vb->vb_mark_end.tp_row, cur + offset, sz)) { in vthistory_addlines()
147 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row; in vthistory_addlines()
148 vb->vb_mark_start.tp_col = vb->vb_mark_end.tp_col; in vthistory_addlines()
157 *offset = vb->vb_roffset; in vthistory_getpos()
169 * 205 200 ((205 - 200 + 1000) % 1000) = 5 in vtbuf_htw()
170 * 90 990 ((90 - 990 + 1000) % 1000) = 100 in vtbuf_htw()
172 return ((row - vb->vb_roffset + vb->vb_history_size) % in vtbuf_htw()
173 vb->vb_history_size); in vtbuf_htw()
181 return ((vb->vb_roffset + row) % vb->vb_history_size); in vtbuf_wth()
187 * begin - start index
188 * end - end index
189 * test - test index
190 * sz - size of circular buffer when it turns over
199 /* check for inversion */ in vtbuf_in_this_range()
214 if ((vb->vb_flags & (VBF_CURSOR|VBF_SCROLL)) == VBF_CURSOR && in vtbuf_iscursor()
215 (vb->vb_cursor.tp_row == row) && (vb->vb_cursor.tp_col == col)) in vtbuf_iscursor()
220 if (vb->vb_mark_start.tp_col == vb->vb_mark_end.tp_col && in vtbuf_iscursor()
221 vb->vb_mark_start.tp_row == vb->vb_mark_end.tp_row) in vtbuf_iscursor()
224 sc = vb->vb_mark_start.tp_col; in vtbuf_iscursor()
225 sr = vb->vb_mark_start.tp_row; in vtbuf_iscursor()
226 ec = vb->vb_mark_end.tp_col; in vtbuf_iscursor()
227 er = vb->vb_mark_end.tp_row; in vtbuf_iscursor()
230 * Information about if the selection was made bottom-top or in vtbuf_iscursor()
231 * top-bottom is lost due to modulo arithmetics and needs to in vtbuf_iscursor()
234 sz = vb->vb_history_size; in vtbuf_iscursor()
235 tmp = (sz + er - sr) % sz; in vtbuf_iscursor()
270 if (vb->vb_dirtyrect.tr_begin.tp_row > area->tr_begin.tp_row) in vtbuf_dirty()
271 vb->vb_dirtyrect.tr_begin.tp_row = area->tr_begin.tp_row; in vtbuf_dirty()
272 if (vb->vb_dirtyrect.tr_begin.tp_col > area->tr_begin.tp_col) in vtbuf_dirty()
273 vb->vb_dirtyrect.tr_begin.tp_col = area->tr_begin.tp_col; in vtbuf_dirty()
274 if (vb->vb_dirtyrect.tr_end.tp_row < area->tr_end.tp_row) in vtbuf_dirty()
275 vb->vb_dirtyrect.tr_end.tp_row = area->tr_end.tp_row; in vtbuf_dirty()
276 if (vb->vb_dirtyrect.tr_end.tp_col < area->tr_end.tp_col) in vtbuf_dirty()
277 vb->vb_dirtyrect.tr_end.tp_col = area->tr_end.tp_col; in vtbuf_dirty()
286 area.tr_end.tp_row = p->tp_row + 1; in vtbuf_dirty_cell()
287 area.tr_end.tp_col = p->tp_col + 1; in vtbuf_dirty_cell()
295 vb->vb_dirtyrect.tr_begin = vb->vb_scr_size; in vtbuf_make_undirty()
296 vb->vb_dirtyrect.tr_end.tp_row = vb->vb_dirtyrect.tr_end.tp_col = 0; in vtbuf_make_undirty()
303 *r = vb->vb_dirtyrect; in vtbuf_undirty()
310 const term_pos_t *p1 = &r->tr_begin; in vtbuf_copy()
315 KASSERT(r->tr_begin.tp_row < vb->vb_scr_size.tp_row, in vtbuf_copy()
317 r->tr_begin.tp_row, vb->vb_scr_size.tp_row)); in vtbuf_copy()
318 KASSERT(r->tr_begin.tp_col < vb->vb_scr_size.tp_col, in vtbuf_copy()
320 r->tr_begin.tp_col, vb->vb_scr_size.tp_col)); in vtbuf_copy()
322 KASSERT(r->tr_end.tp_row <= vb->vb_scr_size.tp_row, in vtbuf_copy()
324 r->tr_end.tp_row, vb->vb_scr_size.tp_row)); in vtbuf_copy()
325 KASSERT(r->tr_end.tp_col <= vb->vb_scr_size.tp_col, in vtbuf_copy()
327 r->tr_end.tp_col, vb->vb_scr_size.tp_col)); in vtbuf_copy()
329 KASSERT(p2->tp_row < vb->vb_scr_size.tp_row, in vtbuf_copy()
331 p2->tp_row, vb->vb_scr_size.tp_row)); in vtbuf_copy()
332 KASSERT(p2->tp_col < vb->vb_scr_size.tp_col, in vtbuf_copy()
334 p2->tp_col, vb->vb_scr_size.tp_col)); in vtbuf_copy()
336 rows = r->tr_end.tp_row - r->tr_begin.tp_row; in vtbuf_copy()
337 rdiff = r->tr_begin.tp_row - p2->tp_row; in vtbuf_copy()
338 cols = r->tr_end.tp_col - r->tr_begin.tp_col; in vtbuf_copy()
339 if (r->tr_begin.tp_row > p2->tp_row && r->tr_begin.tp_col == 0 && in vtbuf_copy()
340 r->tr_end.tp_col == vb->vb_scr_size.tp_col && /* Full row. */ in vtbuf_copy()
341 (rows + rdiff) == vb->vb_scr_size.tp_row && /* Whole screen. */ in vtbuf_copy()
344 } else if (p2->tp_row < p1->tp_row) { in vtbuf_copy()
349 &VTBUF_FIELD(vb, p2->tp_row + pr, p2->tp_col), in vtbuf_copy()
350 &VTBUF_FIELD(vb, p1->tp_row + pr, p1->tp_col), in vtbuf_copy()
354 for (pr = rows - 1; pr >= 0; pr--) in vtbuf_copy()
356 &VTBUF_FIELD(vb, p2->tp_row + pr, p2->tp_col), in vtbuf_copy()
357 &VTBUF_FIELD(vb, p1->tp_row + pr, p1->tp_col), in vtbuf_copy()
362 area.tr_end.tp_row = MIN(p2->tp_row + rows, vb->vb_scr_size.tp_row); in vtbuf_copy()
363 area.tr_end.tp_col = MIN(p2->tp_col + cols, vb->vb_scr_size.tp_col); in vtbuf_copy()
373 for (pr = r->tr_begin.tp_row; pr < r->tr_end.tp_row; pr++) { in vtbuf_do_fill()
374 row = vb->vb_rows[(vb->vb_curroffset + pr) % in vtbuf_do_fill()
376 for (pc = r->tr_begin.tp_col; pc < r->tr_end.tp_col; pc++) { in vtbuf_do_fill()
386 KASSERT(r->tr_begin.tp_row < vb->vb_scr_size.tp_row, in vtbuf_fill()
388 r->tr_begin.tp_row, vb->vb_scr_size.tp_row)); in vtbuf_fill()
389 KASSERT(r->tr_begin.tp_col < vb->vb_scr_size.tp_col, in vtbuf_fill()
391 r->tr_begin.tp_col, vb->vb_scr_size.tp_col)); in vtbuf_fill()
393 KASSERT(r->tr_end.tp_row <= vb->vb_scr_size.tp_row, in vtbuf_fill()
395 r->tr_end.tp_row, vb->vb_scr_size.tp_row)); in vtbuf_fill()
396 KASSERT(r->tr_end.tp_col <= vb->vb_scr_size.tp_col, in vtbuf_fill()
398 r->tr_end.tp_col, vb->vb_scr_size.tp_col)); in vtbuf_fill()
409 vb->vb_history_size = MAX(vb->vb_history_size, vb->vb_scr_size.tp_row); in vtbuf_init_rows()
411 for (r = 0; r < vb->vb_history_size; r++) in vtbuf_init_rows()
412 vb->vb_rows[r] = &vb->vb_buffer[r * vb->vb_scr_size.tp_col]; in vtbuf_init_rows()
422 a = teken_get_curattr(&vb->vb_terminal->tm_emulator); in vtbuf_do_clearhistory()
423 ch = TCOLOR_FG(a->ta_fgcolor) | TCOLOR_BG(a->ta_bgcolor); in vtbuf_do_clearhistory()
426 rect.tr_end.tp_col = vb->vb_scr_size.tp_col; in vtbuf_do_clearhistory()
427 rect.tr_end.tp_row = vb->vb_history_size; in vtbuf_do_clearhistory()
435 vb->vb_roffset = 0; in vtbuf_reset_scrollback()
436 vb->vb_curroffset = 0; in vtbuf_reset_scrollback()
437 vb->vb_mark_start.tp_row = 0; in vtbuf_reset_scrollback()
438 vb->vb_mark_start.tp_col = 0; in vtbuf_reset_scrollback()
439 vb->vb_mark_end.tp_row = 0; in vtbuf_reset_scrollback()
440 vb->vb_mark_end.tp_col = 0; in vtbuf_reset_scrollback()
446 vb->vb_flags |= VBF_CURSOR; in vtbuf_init_early()
451 if ((vb->vb_flags & VBF_MTX_INIT) == 0) { in vtbuf_init_early()
452 mtx_init(&vb->vb_lock, "vtbuf", NULL, MTX_SPIN); in vtbuf_init_early()
453 vb->vb_flags |= VBF_MTX_INIT; in vtbuf_init_early()
462 vb->vb_scr_size = *p; in vtbuf_init()
463 vb->vb_history_size = VBF_DEFAULT_HISTORY_SIZE; in vtbuf_init()
465 if ((vb->vb_flags & VBF_STATIC) == 0) { in vtbuf_init()
466 sz = vb->vb_history_size * p->tp_col * sizeof(term_char_t); in vtbuf_init()
467 vb->vb_buffer = malloc(sz, M_VTBUF, M_WAITOK | M_ZERO); in vtbuf_init()
469 sz = vb->vb_history_size * sizeof(term_char_t *); in vtbuf_init()
470 vb->vb_rows = malloc(sz, M_VTBUF, M_WAITOK | M_ZERO); in vtbuf_init()
482 vb->vb_flags &= ~VBF_HISTORY_FULL; in vtbuf_clearhistory()
492 p.tp_row = vb->vb_scr_size.tp_row; in vtbuf_sethistory_size()
493 p.tp_col = vb->vb_scr_size.tp_col; in vtbuf_sethistory_size()
507 a = teken_get_curattr(&vb->vb_terminal->tm_emulator); in vtbuf_grow()
508 ch = TCOLOR_FG(a->ta_fgcolor) | TCOLOR_BG(a->ta_bgcolor); in vtbuf_grow()
510 history_size = MAX(history_size, p->tp_row); in vtbuf_grow()
513 bufsize = history_size * p->tp_col * sizeof(term_char_t); in vtbuf_grow()
520 old = vb->vb_flags & VBF_STATIC ? NULL : vb->vb_buffer; in vtbuf_grow()
521 oldrows = vb->vb_flags & VBF_STATIC ? NULL : vb->vb_rows; in vtbuf_grow()
522 copyrows = vb->vb_rows; in vtbuf_grow()
524 w = vb->vb_scr_size.tp_col; in vtbuf_grow()
525 h = vb->vb_scr_size.tp_row; in vtbuf_grow()
526 old_history_size = vb->vb_history_size; in vtbuf_grow()
527 history_full = vb->vb_flags & VBF_HISTORY_FULL || in vtbuf_grow()
528 vb->vb_curroffset + h >= history_size; in vtbuf_grow()
530 vb->vb_history_size = history_size; in vtbuf_grow()
531 vb->vb_buffer = new; in vtbuf_grow()
532 vb->vb_rows = rows; in vtbuf_grow()
533 vb->vb_flags &= ~VBF_STATIC; in vtbuf_grow()
534 vb->vb_scr_size = *p; in vtbuf_grow()
555 (vb->vb_curroffset + h + r) % in vtbuf_grow()
567 MIN(p->tp_col, w) * sizeof(term_char_t)); in vtbuf_grow()
574 for (c = MIN(p->tp_col, w); c < p->tp_col; c++) { in vtbuf_grow()
582 for (c = MIN(p->tp_col, w); c < p->tp_col; c++) { in vtbuf_grow()
587 vb->vb_flags &= ~VBF_HISTORY_FULL; in vtbuf_grow()
590 * If the screen is already filled (there are non-visible lines in vtbuf_grow()
595 * <h>th most recent line of history in the new, non-cycled in vtbuf_grow()
600 vb->vb_curroffset = old_history_size - h; in vtbuf_grow()
603 * (old_history_size - history_size) lines of history are in vtbuf_grow()
617 (vb->vb_curroffset + h + r + in vtbuf_grow()
618 (old_history_size - history_size)) % in vtbuf_grow()
624 MIN(p->tp_col, w) * sizeof(term_char_t)); in vtbuf_grow()
631 for (c = MIN(p->tp_col, w); c < p->tp_col; c++) { in vtbuf_grow()
637 vb->vb_curroffset = history_size - h; in vtbuf_grow()
638 vb->vb_flags |= VBF_HISTORY_FULL; in vtbuf_grow()
642 vb->vb_roffset = vb->vb_curroffset; in vtbuf_grow()
645 if (vb->vb_cursor.tp_col > p->tp_col - 1) in vtbuf_grow()
647 * Move cursor to the last column, in case its previous in vtbuf_grow()
650 vb->vb_cursor.tp_col = p->tp_col - 1; in vtbuf_grow()
652 if (vb->vb_curroffset > 0 || vb->vb_cursor.tp_row > p->tp_row - 1) in vtbuf_grow()
654 vb->vb_cursor.tp_row = p->tp_row - 1; in vtbuf_grow()
668 KASSERT(p->tp_row < vb->vb_scr_size.tp_row, in vtbuf_putchar()
670 p->tp_row, vb->vb_scr_size.tp_row)); in vtbuf_putchar()
671 KASSERT(p->tp_col < vb->vb_scr_size.tp_col, in vtbuf_putchar()
673 p->tp_col, vb->vb_scr_size.tp_col)); in vtbuf_putchar()
675 row = vb->vb_rows[(vb->vb_curroffset + p->tp_row) % in vtbuf_putchar()
677 if (row[p->tp_col] != c) { in vtbuf_putchar()
678 row[p->tp_col] = c; in vtbuf_putchar()
686 if (vb->vb_flags & VBF_CURSOR) { in vtbuf_cursor_position()
687 vtbuf_dirty_cell(vb, &vb->vb_cursor); in vtbuf_cursor_position()
688 vb->vb_cursor = *p; in vtbuf_cursor_position()
689 vtbuf_dirty_cell(vb, &vb->vb_cursor); in vtbuf_cursor_position()
691 vb->vb_cursor = *p; in vtbuf_cursor_position()
703 if ((vb->vb_mark_start.tp_col != vb->vb_mark_end.tp_col) || in vtbuf_flush_mark()
704 (vb->vb_mark_start.tp_row != vb->vb_mark_end.tp_row)) { in vtbuf_flush_mark()
705 s = vtbuf_htw(vb, vb->vb_mark_start.tp_row); in vtbuf_flush_mark()
706 e = vtbuf_htw(vb, vb->vb_mark_end.tp_row); in vtbuf_flush_mark()
711 area.tr_end.tp_col = vb->vb_scr_size.tp_col; in vtbuf_flush_mark()
727 if (POS_INDEX(vtbuf_htw(vb, vb->vb_mark_start.tp_row), in vtbuf_get_marked_len()
728 vb->vb_mark_start.tp_col) > in vtbuf_get_marked_len()
729 POS_INDEX(vtbuf_htw(vb, vb->vb_mark_end.tp_row), in vtbuf_get_marked_len()
730 vb->vb_mark_end.tp_col)) { in vtbuf_get_marked_len()
731 POS_COPY(e, vb->vb_mark_start); in vtbuf_get_marked_len()
732 POS_COPY(s, vb->vb_mark_end); in vtbuf_get_marked_len()
734 POS_COPY(s, vb->vb_mark_start); in vtbuf_get_marked_len()
735 POS_COPY(e, vb->vb_mark_end); in vtbuf_get_marked_len()
738 si = s.tp_row * vb->vb_scr_size.tp_col + s.tp_col; in vtbuf_get_marked_len()
739 ei = e.tp_row * vb->vb_scr_size.tp_col + e.tp_col; in vtbuf_get_marked_len()
742 sz = ei - si + (1 + e.tp_row - s.tp_row); in vtbuf_get_marked_len()
756 case 0x2004: /* THREE-PER-EM SPACE (thick space) */ in tchar_is_word_separator()
757 case 0x2005: /* FOUR-PER-EM SPACE (mid space) */ in tchar_is_word_separator()
758 case 0x2006: /* SIX-PER-EM SPACE */ in tchar_is_word_separator()
777 if (POS_INDEX(vtbuf_htw(vb, vb->vb_mark_start.tp_row), in vtbuf_extract_marked()
778 vb->vb_mark_start.tp_col) > in vtbuf_extract_marked()
779 POS_INDEX(vtbuf_htw(vb, vb->vb_mark_end.tp_row), in vtbuf_extract_marked()
780 vb->vb_mark_end.tp_col)) { in vtbuf_extract_marked()
781 POS_COPY(e, vb->vb_mark_start); in vtbuf_extract_marked()
782 POS_COPY(s, vb->vb_mark_end); in vtbuf_extract_marked()
784 POS_COPY(s, vb->vb_mark_start); in vtbuf_extract_marked()
785 POS_COPY(e, vb->vb_mark_end); in vtbuf_extract_marked()
791 ce = (r == e.tp_row)?e.tp_col:vb->vb_scr_size.tp_col; in vtbuf_extract_marked()
796 buf[i++] = vb->vb_rows[r][c]; in vtbuf_extract_marked()
801 for (; i != j; i--) { in vtbuf_extract_marked()
802 if (!tchar_is_word_separator(buf[i - 1])) in vtbuf_extract_marked()
824 if (vb->vb_mark_last != VTB_MARK_MOVE) in vtbuf_set_mark()
830 vb->vb_mark_end.tp_col = col; in vtbuf_set_mark()
831 vb->vb_mark_end.tp_row = vtbuf_wth(vb, row); in vtbuf_set_mark()
835 vb->vb_mark_start.tp_col = col; in vtbuf_set_mark()
836 vb->vb_mark_start.tp_row = vtbuf_wth(vb, row); in vtbuf_set_mark()
838 vb->vb_mark_end.tp_col = col; in vtbuf_set_mark()
839 vb->vb_mark_end.tp_row = vtbuf_wth(vb, row); in vtbuf_set_mark()
843 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row = in vtbuf_set_mark()
845 r = vb->vb_rows[vb->vb_mark_start.tp_row]; in vtbuf_set_mark()
846 for (i = col; i >= 0; i --) { in vtbuf_set_mark()
848 vb->vb_mark_start.tp_col = i + 1; in vtbuf_set_mark()
852 /* No space - word extends to beginning of line. */ in vtbuf_set_mark()
853 if (i == -1) in vtbuf_set_mark()
854 vb->vb_mark_start.tp_col = 0; in vtbuf_set_mark()
855 for (i = col; i < vb->vb_scr_size.tp_col; i++) { in vtbuf_set_mark()
857 vb->vb_mark_end.tp_col = i; in vtbuf_set_mark()
861 /* No space - word extends to end of line. */ in vtbuf_set_mark()
862 if (i == vb->vb_scr_size.tp_col) in vtbuf_set_mark()
863 vb->vb_mark_end.tp_col = i; in vtbuf_set_mark()
865 if (vb->vb_mark_start.tp_col > vb->vb_mark_end.tp_col) in vtbuf_set_mark()
866 vb->vb_mark_start.tp_col = vb->vb_mark_end.tp_col; in vtbuf_set_mark()
870 vb->vb_mark_start.tp_col = 0; in vtbuf_set_mark()
871 vb->vb_mark_end.tp_col = vb->vb_scr_size.tp_col; in vtbuf_set_mark()
872 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row = in vtbuf_set_mark()
876 vb->vb_mark_last = type; in vtbuf_set_mark()
883 vb->vb_mark_last = type; in vtbuf_set_mark()
895 oflags = vb->vb_flags; in vtbuf_cursor_visibility()
897 vb->vb_flags |= VBF_CURSOR; in vtbuf_cursor_visibility()
899 vb->vb_flags &= ~VBF_CURSOR; in vtbuf_cursor_visibility()
900 nflags = vb->vb_flags; in vtbuf_cursor_visibility()
903 vtbuf_dirty_cell(vb, &vb->vb_cursor); in vtbuf_cursor_visibility()
912 oflags = vb->vb_flags; in vtbuf_scroll_mode()
914 vb->vb_flags |= VBF_SCROLL; in vtbuf_scroll_mode()
916 vb->vb_flags &= ~VBF_SCROLL; in vtbuf_scroll_mode()
917 nflags = vb->vb_flags; in vtbuf_scroll_mode()
920 vtbuf_dirty_cell(vb, &vb->vb_cursor); in vtbuf_scroll_mode()