Lines Matching refs:vb

48 #define	VTBUF_LOCK(vb)		mtx_lock_spin(&(vb)->vb_lock)
49 #define VTBUF_UNLOCK(vb) mtx_unlock_spin(&(vb)->vb_lock)
58 static int vtbuf_htw(const struct vt_buf *vb, int row);
59 static int vtbuf_wth(const struct vt_buf *vb, int row);
72 vthistory_seek(struct vt_buf *vb, int offset, int whence)
77 if ((vb->vb_flags & VBF_SCROLL) == 0) {
78 if (vb->vb_roffset != vb->vb_curroffset) {
79 vb->vb_roffset = vb->vb_curroffset;
86 bottom = vb->vb_curroffset;
87 top = (vb->vb_flags & VBF_HISTORY_FULL) ?
88 bottom + vb->vb_scr_size.tp_row - vb->vb_history_size :
103 roffset = vb->vb_roffset;
104 if (roffset >= bottom + vb->vb_scr_size.tp_row)
105 roffset -= vb->vb_history_size;
112 roffset = vb->vb_history_size + roffset;
117 roffset = vb->vb_curroffset;
121 diff = vb->vb_roffset != roffset;
122 vb->vb_roffset = roffset;
128 vthistory_addlines(struct vt_buf *vb, int offset)
134 vb->vb_curroffset += offset;
135 if (vb->vb_curroffset + vb->vb_scr_size.tp_row >= vb->vb_history_size) {
136 vb->vb_flags |= VBF_HISTORY_FULL;
137 vb->vb_curroffset %= vb->vb_history_size;
139 if ((vb->vb_flags & VBF_SCROLL) == 0) {
140 vb->vb_roffset = vb->vb_curroffset;
144 sz = vb->vb_history_size;
145 cur = vb->vb_roffset + vb->vb_scr_size.tp_row + sz - 1;
146 if (vtbuf_in_this_range(cur, vb->vb_mark_start.tp_row, cur + offset, sz) ||
147 vtbuf_in_this_range(cur, vb->vb_mark_end.tp_row, cur + offset, sz)) {
149 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row;
150 vb->vb_mark_start.tp_col = vb->vb_mark_end.tp_col;
156 vthistory_getpos(const struct vt_buf *vb, unsigned int *offset)
159 *offset = vb->vb_roffset;
165 vtbuf_htw(const struct vt_buf *vb, int row)
174 return ((row - vb->vb_roffset + vb->vb_history_size) %
175 vb->vb_history_size);
180 vtbuf_wth(const struct vt_buf *vb, int row)
183 return ((vb->vb_roffset + row) % vb->vb_history_size);
210 vtbuf_iscursor(const struct vt_buf *vb, int row, int col)
216 if ((vb->vb_flags & (VBF_CURSOR|VBF_SCROLL)) == VBF_CURSOR &&
217 (vb->vb_cursor.tp_row == row) && (vb->vb_cursor.tp_col == col))
222 if (vb->vb_mark_start.tp_col == vb->vb_mark_end.tp_col &&
223 vb->vb_mark_start.tp_row == vb->vb_mark_end.tp_row)
226 sc = vb->vb_mark_start.tp_col;
227 sr = vb->vb_mark_start.tp_row;
228 ec = vb->vb_mark_end.tp_col;
229 er = vb->vb_mark_end.tp_row;
236 sz = vb->vb_history_size;
238 row = vtbuf_wth(vb, row);
255 vtbuf_dirty_locked(struct vt_buf *vb, const term_rect_t *area)
258 if (vb->vb_dirtyrect.tr_begin.tp_row > area->tr_begin.tp_row)
259 vb->vb_dirtyrect.tr_begin.tp_row = area->tr_begin.tp_row;
260 if (vb->vb_dirtyrect.tr_begin.tp_col > area->tr_begin.tp_col)
261 vb->vb_dirtyrect.tr_begin.tp_col = area->tr_begin.tp_col;
262 if (vb->vb_dirtyrect.tr_end.tp_row < area->tr_end.tp_row)
263 vb->vb_dirtyrect.tr_end.tp_row = area->tr_end.tp_row;
264 if (vb->vb_dirtyrect.tr_end.tp_col < area->tr_end.tp_col)
265 vb->vb_dirtyrect.tr_end.tp_col = area->tr_end.tp_col;
269 vtbuf_dirty(struct vt_buf *vb, const term_rect_t *area)
272 VTBUF_LOCK(vb);
273 vtbuf_dirty_locked(vb, area);
274 VTBUF_UNLOCK(vb);
278 vtbuf_dirty_cell_locked(struct vt_buf *vb, const term_pos_t *p)
285 vtbuf_dirty_locked(vb, &area);
289 vtbuf_make_undirty(struct vt_buf *vb)
292 vb->vb_dirtyrect.tr_begin = vb->vb_scr_size;
293 vb->vb_dirtyrect.tr_end.tp_row = vb->vb_dirtyrect.tr_end.tp_col = 0;
297 vtbuf_undirty(struct vt_buf *vb, term_rect_t *r)
300 VTBUF_LOCK(vb);
301 *r = vb->vb_dirtyrect;
302 vtbuf_make_undirty(vb);
303 VTBUF_UNLOCK(vb);
307 vtbuf_copy(struct vt_buf *vb, const term_rect_t *r, const term_pos_t *p2)
314 KASSERT(r->tr_begin.tp_row < vb->vb_scr_size.tp_row,
316 r->tr_begin.tp_row, vb->vb_scr_size.tp_row));
317 KASSERT(r->tr_begin.tp_col < vb->vb_scr_size.tp_col,
319 r->tr_begin.tp_col, vb->vb_scr_size.tp_col));
321 KASSERT(r->tr_end.tp_row <= vb->vb_scr_size.tp_row,
323 r->tr_end.tp_row, vb->vb_scr_size.tp_row));
324 KASSERT(r->tr_end.tp_col <= vb->vb_scr_size.tp_col,
326 r->tr_end.tp_col, vb->vb_scr_size.tp_col));
328 KASSERT(p2->tp_row < vb->vb_scr_size.tp_row,
330 p2->tp_row, vb->vb_scr_size.tp_row));
331 KASSERT(p2->tp_col < vb->vb_scr_size.tp_col,
333 p2->tp_col, vb->vb_scr_size.tp_col));
339 r->tr_end.tp_col == vb->vb_scr_size.tp_col && /* Full row. */
340 (rows + rdiff) == vb->vb_scr_size.tp_row && /* Whole screen. */
342 vthistory_addlines(vb, rdiff);
348 &VTBUF_FIELD(vb, p2->tp_row + pr, p2->tp_col),
349 &VTBUF_FIELD(vb, p1->tp_row + pr, p1->tp_col),
355 &VTBUF_FIELD(vb, p2->tp_row + pr, p2->tp_col),
356 &VTBUF_FIELD(vb, p1->tp_row + pr, p1->tp_col),
361 area.tr_end.tp_row = MIN(p2->tp_row + rows, vb->vb_scr_size.tp_row);
362 area.tr_end.tp_col = MIN(p2->tp_col + cols, vb->vb_scr_size.tp_col);
363 vtbuf_dirty(vb, &area);
367 vtbuf_fill(struct vt_buf *vb, const term_rect_t *r, term_char_t c)
373 row = vb->vb_rows[(vb->vb_curroffset + pr) %
374 VTBUF_MAX_HEIGHT(vb)];
382 vtbuf_fill_locked(struct vt_buf *vb, const term_rect_t *r, term_char_t c)
384 KASSERT(r->tr_begin.tp_row < vb->vb_scr_size.tp_row,
386 r->tr_begin.tp_row, vb->vb_scr_size.tp_row));
387 KASSERT(r->tr_begin.tp_col < vb->vb_scr_size.tp_col,
389 r->tr_begin.tp_col, vb->vb_scr_size.tp_col));
391 KASSERT(r->tr_end.tp_row <= vb->vb_scr_size.tp_row,
393 r->tr_end.tp_row, vb->vb_scr_size.tp_row));
394 KASSERT(r->tr_end.tp_col <= vb->vb_scr_size.tp_col,
396 r->tr_end.tp_col, vb->vb_scr_size.tp_col));
398 VTBUF_LOCK(vb);
399 vtbuf_fill(vb, r, c);
400 vtbuf_dirty_locked(vb, r);
401 VTBUF_UNLOCK(vb);
405 vtbuf_init_rows(struct vt_buf *vb)
409 vb->vb_history_size = MAX(vb->vb_history_size, vb->vb_scr_size.tp_row);
411 for (r = 0; r < vb->vb_history_size; r++)
412 vb->vb_rows[r] = &vb->vb_buffer[r * vb->vb_scr_size.tp_col];
416 vtbuf_init_early(struct vt_buf *vb)
420 vb->vb_flags |= VBF_CURSOR;
421 vb->vb_roffset = 0;
422 vb->vb_curroffset = 0;
423 vb->vb_mark_start.tp_row = 0;
424 vb->vb_mark_start.tp_col = 0;
425 vb->vb_mark_end.tp_row = 0;
426 vb->vb_mark_end.tp_col = 0;
428 vtbuf_init_rows(vb);
430 rect.tr_end.tp_col = vb->vb_scr_size.tp_col;
431 rect.tr_end.tp_row = vb->vb_history_size;
432 vtbuf_fill(vb, &rect, VTBUF_SPACE_CHAR(TERMINAL_NORM_ATTR));
433 vtbuf_make_undirty(vb);
434 if ((vb->vb_flags & VBF_MTX_INIT) == 0) {
435 mtx_init(&vb->vb_lock, "vtbuf", NULL, MTX_SPIN);
436 vb->vb_flags |= VBF_MTX_INIT;
441 vtbuf_init(struct vt_buf *vb, const term_pos_t *p)
445 vb->vb_scr_size = *p;
446 vb->vb_history_size = VBF_DEFAULT_HISTORY_SIZE;
448 if ((vb->vb_flags & VBF_STATIC) == 0) {
449 sz = vb->vb_history_size * p->tp_col * sizeof(term_char_t);
450 vb->vb_buffer = malloc(sz, M_VTBUF, M_WAITOK | M_ZERO);
452 sz = vb->vb_history_size * sizeof(term_char_t *);
453 vb->vb_rows = malloc(sz, M_VTBUF, M_WAITOK | M_ZERO);
456 vtbuf_init_early(vb);
460 vtbuf_sethistory_size(struct vt_buf *vb, unsigned int size)
465 p.tp_row = vb->vb_scr_size.tp_row;
466 p.tp_col = vb->vb_scr_size.tp_col;
467 vtbuf_grow(vb, &p, size);
471 vtbuf_grow(struct vt_buf *vb, const term_pos_t *p, unsigned int history_size)
487 VTBUF_LOCK(vb);
488 old = vb->vb_flags & VBF_STATIC ? NULL : vb->vb_buffer;
489 oldrows = vb->vb_flags & VBF_STATIC ? NULL : vb->vb_rows;
490 copyrows = vb->vb_rows;
492 w = vb->vb_scr_size.tp_col;
493 h = vb->vb_scr_size.tp_row;
494 old_history_size = vb->vb_history_size;
495 history_full = vb->vb_flags & VBF_HISTORY_FULL ||
496 vb->vb_curroffset + h >= history_size;
498 vb->vb_history_size = history_size;
499 vb->vb_buffer = new;
500 vb->vb_rows = rows;
501 vb->vb_flags &= ~VBF_STATIC;
502 vb->vb_scr_size = *p;
503 vtbuf_init_rows(vb);
523 (vb->vb_curroffset + h + r) %
555 vb->vb_flags &= ~VBF_HISTORY_FULL;
568 vb->vb_curroffset = old_history_size - h;
585 (vb->vb_curroffset + h + r +
605 vb->vb_curroffset = history_size - h;
606 vb->vb_flags |= VBF_HISTORY_FULL;
610 vb->vb_roffset = vb->vb_curroffset;
613 if (vb->vb_cursor.tp_col > p->tp_col - 1)
618 vb->vb_cursor.tp_col = p->tp_col - 1;
620 if (vb->vb_curroffset > 0 || vb->vb_cursor.tp_row > p->tp_row - 1)
622 vb->vb_cursor.tp_row = p->tp_row - 1;
624 VTBUF_UNLOCK(vb);
632 vtbuf_putchar(struct vt_buf *vb, const term_pos_t *p, term_char_t c)
636 KASSERT(p->tp_row < vb->vb_scr_size.tp_row,
638 p->tp_row, vb->vb_scr_size.tp_row));
639 KASSERT(p->tp_col < vb->vb_scr_size.tp_col,
641 p->tp_col, vb->vb_scr_size.tp_col));
643 row = vb->vb_rows[(vb->vb_curroffset + p->tp_row) %
644 VTBUF_MAX_HEIGHT(vb)];
646 VTBUF_LOCK(vb);
648 vtbuf_dirty_cell_locked(vb, p);
649 VTBUF_UNLOCK(vb);
654 vtbuf_cursor_position(struct vt_buf *vb, const term_pos_t *p)
657 if (vb->vb_flags & VBF_CURSOR) {
658 VTBUF_LOCK(vb);
659 vtbuf_dirty_cell_locked(vb, &vb->vb_cursor);
660 vb->vb_cursor = *p;
661 vtbuf_dirty_cell_locked(vb, &vb->vb_cursor);
662 VTBUF_UNLOCK(vb);
664 vb->vb_cursor = *p;
670 vtbuf_flush_mark(struct vt_buf *vb)
676 if ((vb->vb_mark_start.tp_col != vb->vb_mark_end.tp_col) ||
677 (vb->vb_mark_start.tp_row != vb->vb_mark_end.tp_row)) {
679 s = vtbuf_htw(vb, vb->vb_mark_start.tp_row);
680 e = vtbuf_htw(vb, vb->vb_mark_end.tp_row);
685 area.tr_end.tp_col = vb->vb_scr_size.tp_col;
688 vtbuf_dirty(vb, &area);
693 vtbuf_get_marked_len(struct vt_buf *vb)
699 if (POS_INDEX(vtbuf_htw(vb, vb->vb_mark_start.tp_row),
700 vb->vb_mark_start.tp_col) >
701 POS_INDEX(vtbuf_htw(vb, vb->vb_mark_end.tp_row),
702 vb->vb_mark_end.tp_col)) {
703 POS_COPY(e, vb->vb_mark_start);
704 POS_COPY(s, vb->vb_mark_end);
706 POS_COPY(s, vb->vb_mark_start);
707 POS_COPY(e, vb->vb_mark_end);
710 si = s.tp_row * vb->vb_scr_size.tp_col + s.tp_col;
711 ei = e.tp_row * vb->vb_scr_size.tp_col + e.tp_col;
720 vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz)
726 if (POS_INDEX(vtbuf_htw(vb, vb->vb_mark_start.tp_row),
727 vb->vb_mark_start.tp_col) >
728 POS_INDEX(vtbuf_htw(vb, vb->vb_mark_end.tp_row),
729 vb->vb_mark_end.tp_col)) {
730 POS_COPY(e, vb->vb_mark_start);
731 POS_COPY(s, vb->vb_mark_end);
733 POS_COPY(s, vb->vb_mark_start);
734 POS_COPY(e, vb->vb_mark_end);
740 ce = (r == e.tp_row)?e.tp_col:vb->vb_scr_size.tp_col;
742 buf[i++] = vb->vb_rows[r][c];
753 vtbuf_set_mark(struct vt_buf *vb, int type, int col, int row)
760 if (vb->vb_mark_last != VTB_MARK_MOVE)
765 vtbuf_flush_mark(vb); /* Clean old mark. */
766 vb->vb_mark_end.tp_col = col;
767 vb->vb_mark_end.tp_row = vtbuf_wth(vb, row);
770 vtbuf_flush_mark(vb); /* Clean old mark. */
771 vb->vb_mark_start.tp_col = col;
772 vb->vb_mark_start.tp_row = vtbuf_wth(vb, row);
774 vb->vb_mark_end.tp_col = col;
775 vb->vb_mark_end.tp_row = vtbuf_wth(vb, row);
778 vtbuf_flush_mark(vb); /* Clean old mark. */
779 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row =
780 vtbuf_wth(vb, row);
781 r = vb->vb_rows[vb->vb_mark_start.tp_row];
784 vb->vb_mark_start.tp_col = i + 1;
788 for (i = col; i < vb->vb_scr_size.tp_col; i ++) {
790 vb->vb_mark_end.tp_col = i;
794 if (vb->vb_mark_start.tp_col > vb->vb_mark_end.tp_col)
795 vb->vb_mark_start.tp_col = vb->vb_mark_end.tp_col;
798 vtbuf_flush_mark(vb); /* Clean old mark. */
799 vb->vb_mark_start.tp_col = 0;
800 vb->vb_mark_end.tp_col = vb->vb_scr_size.tp_col;
801 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row =
802 vtbuf_wth(vb, row);
805 vb->vb_mark_last = type;
812 vb->vb_mark_last = type;
814 vtbuf_flush_mark(vb);
820 vtbuf_cursor_visibility(struct vt_buf *vb, int yes)
824 VTBUF_LOCK(vb);
825 oflags = vb->vb_flags;
827 vb->vb_flags |= VBF_CURSOR;
829 vb->vb_flags &= ~VBF_CURSOR;
830 nflags = vb->vb_flags;
833 vtbuf_dirty_cell_locked(vb, &vb->vb_cursor);
834 VTBUF_UNLOCK(vb);
838 vtbuf_scroll_mode(struct vt_buf *vb, int yes)
842 VTBUF_LOCK(vb);
843 oflags = vb->vb_flags;
845 vb->vb_flags |= VBF_SCROLL;
847 vb->vb_flags &= ~VBF_SCROLL;
848 nflags = vb->vb_flags;
851 vtbuf_dirty_cell_locked(vb, &vb->vb_cursor);
852 VTBUF_UNLOCK(vb);