Author: jah
Date: Thu May 28 21:22:30 2020
New Revision: 361601
URL: https://svnweb.freebsd.org/changeset/base/361601

Log:
  vt(4): Add support for `vidcontrol -C'
  
  Extract scrollback buffer initialization into a common routine, used both
  during vt(4) init and in handling the CONS_CLRHIST ioctl.
  
  PR:           224436
  Reviewed by:  emaste
  Differential Revision:        https://reviews.freebsd.org/D24815

Modified:
  head/sys/dev/vt/vt.h
  head/sys/dev/vt/vt_buf.c
  head/sys/dev/vt/vt_core.c

Modified: head/sys/dev/vt/vt.h
==============================================================================
--- head/sys/dev/vt/vt.h        Thu May 28 21:19:44 2020        (r361600)
+++ head/sys/dev/vt/vt.h        Thu May 28 21:22:30 2020        (r361601)
@@ -231,6 +231,7 @@ void vtbuf_scroll_mode(struct vt_buf *vb, int yes);
 void vtbuf_dirty(struct vt_buf *vb, const term_rect_t *area);
 void vtbuf_undirty(struct vt_buf *, term_rect_t *);
 void vtbuf_sethistory_size(struct vt_buf *, unsigned int);
+void vtbuf_clearhistory(struct vt_buf *);
 int vtbuf_iscursor(const struct vt_buf *vb, int row, int col);
 void vtbuf_cursor_visibility(struct vt_buf *, int);
 #ifndef SC_NO_CUTPASTE

Modified: head/sys/dev/vt/vt_buf.c
==============================================================================
--- head/sys/dev/vt/vt_buf.c    Thu May 28 21:19:44 2020        (r361600)
+++ head/sys/dev/vt/vt_buf.c    Thu May 28 21:22:30 2020        (r361601)
@@ -416,13 +416,26 @@ vtbuf_init_rows(struct vt_buf *vb)
                vb->vb_rows[r] = &vb->vb_buffer[r * vb->vb_scr_size.tp_col];
 }
 
-void
-vtbuf_init_early(struct vt_buf *vb)
+static void
+vtbuf_do_clearhistory(struct vt_buf *vb)
 {
        term_rect_t rect;
        const teken_attr_t *a;
-       term_char_t c;
+       term_char_t ch;
 
+       a = teken_get_curattr(&vb->vb_terminal->tm_emulator);
+       ch = TCOLOR_FG(a->ta_fgcolor) | TCOLOR_BG(a->ta_bgcolor);
+
+       rect.tr_begin.tp_row = rect.tr_begin.tp_col = 0;
+       rect.tr_end.tp_col = vb->vb_scr_size.tp_col;
+       rect.tr_end.tp_row = vb->vb_history_size;
+
+       vtbuf_do_fill(vb, &rect, VTBUF_SPACE_CHAR(ch));
+}
+
+void
+vtbuf_init_early(struct vt_buf *vb)
+{
        vb->vb_flags |= VBF_CURSOR;
        vb->vb_roffset = 0;
        vb->vb_curroffset = 0;
@@ -432,14 +445,7 @@ vtbuf_init_early(struct vt_buf *vb)
        vb->vb_mark_end.tp_col = 0;
 
        vtbuf_init_rows(vb);
-       rect.tr_begin.tp_row = rect.tr_begin.tp_col = 0;
-       rect.tr_end.tp_col = vb->vb_scr_size.tp_col;
-       rect.tr_end.tp_row = vb->vb_history_size;
-
-       a = teken_get_curattr(&vb->vb_terminal->tm_emulator);
-       c = TCOLOR_FG((term_char_t)a->ta_fgcolor) | 
-           TCOLOR_BG((term_char_t)a->ta_bgcolor);
-       vtbuf_do_fill(vb, &rect, VTBUF_SPACE_CHAR(c));
+       vtbuf_do_clearhistory(vb);
        vtbuf_make_undirty(vb);
        if ((vb->vb_flags & VBF_MTX_INIT) == 0) {
                mtx_init(&vb->vb_lock, "vtbuf", NULL, MTX_SPIN);
@@ -464,6 +470,14 @@ vtbuf_init(struct vt_buf *vb, const term_pos_t *p)
        }
 
        vtbuf_init_early(vb);
+}
+
+void
+vtbuf_clearhistory(struct vt_buf *vb)
+{
+       VTBUF_LOCK(vb);
+       vtbuf_do_clearhistory(vb);
+       VTBUF_UNLOCK(vb);
 }
 
 void

Modified: head/sys/dev/vt/vt_core.c
==============================================================================
--- head/sys/dev/vt/vt_core.c   Thu May 28 21:19:44 2020        (r361600)
+++ head/sys/dev/vt/vt_core.c   Thu May 28 21:22:30 2020        (r361601)
@@ -2329,7 +2329,10 @@ skip_thunk:
                if (*(int *)data != vd->vd_curwindow->vw_buf.vb_history_size)
                        vtbuf_sethistory_size(&vd->vd_curwindow->vw_buf,
                            *(int *)data);
-               return 0;
+               return (0);
+       case CONS_CLRHIST:
+               vtbuf_clearhistory(&vd->vd_curwindow->vw_buf);
+               return (0);
        case CONS_GET:
                /* XXX */
                *(int *)data = M_CG640x480;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to