Author: marius
Date: Fri Jun 27 19:57:57 2014
New Revision: 267978
URL: http://svnweb.freebsd.org/changeset/base/267978

Log:
  In order to get vt(4) a bit closer to the feature set provided by sc(4),
  implement options TERMINAL_{KERN,NORM}_ATTR. These are aliased to
  SC_{KERNEL_CONS,NORM}_ATTR and like these latter, allow to change the
  default colors of normal and kernel text respectively.
  Note on the naming: Although affecting the output of vt(4), technically
  kern/subr_terminal.c is primarily concerned with changing default colors
  so it would be inconsistent to term these options VT_{KERN,NORM}_ATTR.
  Actually, if the architecture and abstraction of terminal+teken+vt would
  be perfect, dev/vt/* wouldn't be touched by this commit at all.
  
  Reviewed by:  emaste
  MFC after:    3 days
  Sponsored by: Bally Wulff Games & Entertainment GmbH

Modified:
  head/share/man/man4/vt.4
  head/sys/conf/options
  head/sys/dev/vt/vt.h
  head/sys/dev/vt/vt_buf.c
  head/sys/dev/vt/vt_core.c
  head/sys/kern/subr_terminal.c
  head/sys/sys/terminal.h

Modified: head/share/man/man4/vt.4
==============================================================================
--- head/share/man/man4/vt.4    Fri Jun 27 19:57:54 2014        (r267977)
+++ head/share/man/man4/vt.4    Fri Jun 27 19:57:57 2014        (r267978)
@@ -31,6 +31,8 @@
 .Nm vt
 .Nd virtual terminal console driver
 .Sh SYNOPSIS
+.Cd "options TERMINAL_KERN_ATTR=_attribute_"
+.Cd "options TERMINAL_NORM_ATTR=_attribute_"
 .Cd "options VT_MAXWINDOWS=N"
 .Cd "options VT_ALT_TO_ESC_HACK=1"
 .Cd "options VT_TWOBUTTON_MOUSE"
@@ -107,6 +109,15 @@ These kernel options control the
 .Nm
 driver.
 .Bl -tag -width MAXCONS
+.It Dv TERMINAL_NORM_ATTR=_attribute_
+.It Dv TERMINAL_KERN_ATTR=_attribute_
+These options allow to change the default colors used for normal and kernel
+text respectively.
+Available colors are defined in
+.In sys/terminal.h .
+See
+.Sx EXAMPLES
+below.
 .It Dv VT_MAXWINDOWS=N
 Set the number of virtual terminals to be created to
 .Fa N .
@@ -136,6 +147,8 @@ These options will be removed in a futur
 version.
 .Bl -column -offset indent ".Sy vt VT_TWOBUTTON_MOUSE" ".Sy SC_TWOBUTTON_MOUSE"
 .It Sy vt Option Name Ta Sy sc Option Name
+.It Dv TERMINAL_KERN_ATTR Ta Dv SC_KERNEL_CONS_ATTR
+.It Dv TERMINAL_NORM_ATTR Ta Dv SC_NORM_ATTR
 .It Dv VT_TWOBUTTON_MOUSE Ta Dv SC_TWOBUTTON_MOUSE
 .It Dv VT_MAXWINDOWS Ta Dv MAXCONS
 .It none Ta Dv SC_NO_CUTPASTE
@@ -177,6 +190,21 @@ driver for the system console, if the
 .Xr syscons 4
 driver is also compiled in and is the default.
 .El
+.Sh EXAMPLES
+The following line will change the default color of normal text.
+Normal text will be green on black background.
+Reversed normal text will be black on green background.
+Note that you cannot put any white space inside the quoted string,
+because of the current implementation of
+.Xr config 8 .
+.Pp
+.Dl "options TERMINAL_NORM_ATTR=(FG_GREEN|BG_BLACK)"
+.Pp
+The following line will change the default color of kernel messages.
+Kernel messages will be printed bright red on black background.
+Reversed kernel messages will be black on bright red background.
+.Pp
+.Dl "options TERMINAL_KERN_ATTR=(FG_LIGHTRED|BG_BLACK)"
 .Sh FILES
 .Bl -tag -width /usr/share/syscons/keymaps/* -compact
 .It Pa /dev/console

Modified: head/sys/conf/options
==============================================================================
--- head/sys/conf/options       Fri Jun 27 19:57:54 2014        (r267977)
+++ head/sys/conf/options       Fri Jun 27 19:57:57 2014        (r267978)
@@ -763,10 +763,11 @@ SC_TWOBUTTON_MOUSE        opt_syscons.h
 DEV_SC                 opt_syscons.h
 DEV_VT                 opt_syscons.h
 
-
 # teken terminal emulator options
 TEKEN_CONS25           opt_teken.h
 TEKEN_UTF8             opt_teken.h
+TERMINAL_KERN_ATTR     opt_teken.h
+TERMINAL_NORM_ATTR     opt_teken.h
 
 # options for printf
 PRINTF_BUFR_SIZE       opt_printf.h

Modified: head/sys/dev/vt/vt.h
==============================================================================
--- head/sys/dev/vt/vt.h        Fri Jun 27 19:57:54 2014        (r267977)
+++ head/sys/dev/vt/vt.h        Fri Jun 27 19:57:57 2014        (r267978)
@@ -224,7 +224,7 @@ void vtbuf_extract_marked(struct vt_buf 
        ((mask)->vbm_row & ((uint64_t)1 << ((row) % 64)))
 #define        VTBUF_DIRTYCOL(mask, col) \
        ((mask)->vbm_col & ((uint64_t)1 << ((col) % 64)))
-#define        VTBUF_SPACE_CHAR        (' ' | TC_WHITE << 26 | TC_BLACK << 29)
+#define        VTBUF_SPACE_CHAR(attr)  (' ' | (attr))
 
 #define        VHS_SET 0
 #define        VHS_CUR 1

Modified: head/sys/dev/vt/vt_buf.c
==============================================================================
--- head/sys/dev/vt/vt_buf.c    Fri Jun 27 19:57:54 2014        (r267977)
+++ head/sys/dev/vt/vt_buf.c    Fri Jun 27 19:57:57 2014        (r267978)
@@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/mutex.h>
+#include <sys/reboot.h>
 #include <sys/systm.h>
 
 #include <dev/vt/vt.h>
@@ -385,13 +386,13 @@ vtbuf_init_rows(struct vt_buf *vb)
        vb->vb_history_size = MAX(vb->vb_history_size, vb->vb_scr_size.tp_row);
 
        for (r = 0; r < vb->vb_history_size; r++)
-               vb->vb_rows[r] = &vb->vb_buffer[r *
-                   vb->vb_scr_size.tp_col];
+               vb->vb_rows[r] = &vb->vb_buffer[r * vb->vb_scr_size.tp_col];
 }
 
 void
 vtbuf_init_early(struct vt_buf *vb)
 {
+       term_rect_t rect;
 
        vb->vb_flags |= VBF_CURSOR;
        vb->vb_roffset = 0;
@@ -402,6 +403,10 @@ 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 = vb->vb_scr_size;
+       vtbuf_fill(vb, &rect, VTBUF_SPACE_CHAR((boothowto & RB_MUTE) == 0 ?
+           TERMINAL_KERN_ATTR : TERMINAL_NORM_ATTR));
        vtbuf_make_undirty(vb);
        if ((vb->vb_flags & VBF_MTX_INIT) == 0) {
                mtx_init(&vb->vb_lock, "vtbuf", NULL, MTX_SPIN);
@@ -474,20 +479,27 @@ vtbuf_grow(struct vt_buf *vb, const term
 
                /* Copy history and fill extra space. */
                for (r = 0; r < history_size; r ++) {
+                       /*
+                        * XXX VTBUF_SPACE_CHAR(TERMINAL_NORM_ATTR) will
+                        * extended lines of kernel text using the wrong
+                        * background color.
+                        */
                        row = rows[r];
                        if (r < h) { /* Copy. */
                                memmove(rows[r], copyrows[r],
                                    MIN(p->tp_col, w) * sizeof(term_char_t));
                                for (c = MIN(p->tp_col, w); c < p->tp_col;
                                    c++) {
-                                       row[c] = VTBUF_SPACE_CHAR;
+                                       row[c] = VTBUF_SPACE_CHAR(
+                                           TERMINAL_NORM_ATTR);
                                }
                        } else { /* Just fill. */
                                rect.tr_begin.tp_col = 0;
                                rect.tr_begin.tp_row = r;
                                rect.tr_end.tp_col = p->tp_col;
                                rect.tr_end.tp_row = p->tp_row;
-                               vtbuf_fill(vb, &rect, VTBUF_SPACE_CHAR);
+                               vtbuf_fill(vb, &rect,
+                                   VTBUF_SPACE_CHAR(TERMINAL_NORM_ATTR));
                                break;
                        }
                }

Modified: head/sys/dev/vt/vt_core.c
==============================================================================
--- head/sys/dev/vt/vt_core.c   Fri Jun 27 19:57:54 2014        (r267977)
+++ head/sys/dev/vt/vt_core.c   Fri Jun 27 19:57:57 2014        (r267978)
@@ -958,6 +958,8 @@ vtterm_cnprobe(struct terminal *tm, stru
        struct vt_window *vw = tm->tm_softc;
        struct vt_device *vd = vw->vw_device;
        struct winsize wsz;
+       term_attr_t attr;
+       term_char_t c;
 
        if (!vty_enabled(VTY_VT))
                return;
@@ -1002,7 +1004,12 @@ vtterm_cnprobe(struct terminal *tm, stru
 
        vtbuf_init_early(&vw->vw_buf);
        vt_winsize(vd, vw->vw_font, &wsz);
-       terminal_set_winsize(tm, &wsz);
+       c = (boothowto & RB_MUTE) == 0 ? TERMINAL_KERN_ATTR :
+           TERMINAL_NORM_ATTR;
+       attr.ta_format = TCHAR_FORMAT(c);
+       attr.ta_fgcolor = TCHAR_FGCOLOR(c);
+       attr.ta_bgcolor = TCHAR_BGCOLOR(c);
+       terminal_set_winsize_blank(tm, &wsz, 1, &attr);
 
        if (vtdbest != NULL) {
 #ifdef DEV_SPLASH
@@ -1160,7 +1167,7 @@ vt_change_font(struct vt_window *vw, str
        /* Grow the screen buffer and terminal. */
        terminal_mute(tm, 1);
        vtbuf_grow(&vw->vw_buf, &size, vw->vw_buf.vb_history_size);
-       terminal_set_winsize_blank(tm, &wsz, 0);
+       terminal_set_winsize_blank(tm, &wsz, 0, NULL);
        terminal_mute(tm, 0);
 
        /* Actually apply the font to the current window. */
@@ -2127,7 +2134,7 @@ vt_allocate(struct vt_driver *drv, void 
        /* Update console window sizes to actual. */
        vt_winsize(vd, vd->vd_windows[VT_CONSWINDOW]->vw_font, &wsz);
        terminal_set_winsize_blank(vd->vd_windows[VT_CONSWINDOW]->vw_terminal,
-           &wsz, 0);
+           &wsz, 0, NULL);
 }
 
 void

Modified: head/sys/kern/subr_terminal.c
==============================================================================
--- head/sys/kern/subr_terminal.c       Fri Jun 27 19:57:54 2014        
(r267977)
+++ head/sys/kern/subr_terminal.c       Fri Jun 27 19:57:57 2014        
(r267978)
@@ -119,20 +119,20 @@ static teken_funcs_t terminal_drawmethod
 
 /* Kernel message formatting. */
 static const teken_attr_t kernel_message = {
-       .ta_fgcolor     = TC_WHITE,
-       .ta_bgcolor     = TC_BLACK,
-       .ta_format      = TF_BOLD,
+       .ta_fgcolor     = TCHAR_FGCOLOR(TERMINAL_KERN_ATTR),
+       .ta_bgcolor     = TCHAR_BGCOLOR(TERMINAL_KERN_ATTR),
+       .ta_format      = TCHAR_FORMAT(TERMINAL_KERN_ATTR)
 };
 
 static const teken_attr_t default_message = {
-       .ta_fgcolor     = TC_WHITE,
-       .ta_bgcolor     = TC_BLACK,
+       .ta_fgcolor     = TCHAR_FGCOLOR(TERMINAL_NORM_ATTR),
+       .ta_bgcolor     = TCHAR_BGCOLOR(TERMINAL_NORM_ATTR),
+       .ta_format      = TCHAR_FORMAT(TERMINAL_NORM_ATTR)
 };
 
-#define        TCHAR_CREATE(c, a)      ((c) | \
-       (a)->ta_format << 21 | \
-       teken_256to8((a)->ta_fgcolor) << 26 | \
-       teken_256to8((a)->ta_bgcolor) << 29)
+#define        TCHAR_CREATE(c, a)      ((c) | TFORMAT((a)->ta_format) |        
\
+       TCOLOR_FG(teken_256to8((a)->ta_fgcolor)) |                      \
+       TCOLOR_BG(teken_256to8((a)->ta_bgcolor)))
 
 static void
 terminal_init(struct terminal *tm)
@@ -191,7 +191,7 @@ terminal_maketty(struct terminal *tm, co
 
 void
 terminal_set_winsize_blank(struct terminal *tm, const struct winsize *size,
-    int blank)
+    int blank, const term_attr_t *attr)
 {
        term_rect_t r;
 
@@ -209,8 +209,8 @@ terminal_set_winsize_blank(struct termin
        TERMINAL_UNLOCK(tm);
 
        if ((blank != 0) && !(tm->tm_flags & TF_MUTE))
-               tm->tm_class->tc_fill(tm, &r, TCHAR_CREATE((teken_char_t)' ',
-                   &default_message));
+               tm->tm_class->tc_fill(tm, &r,
+                   TCHAR_CREATE((teken_char_t)' ', attr));
 
        terminal_sync_ttysize(tm);
 }
@@ -219,7 +219,8 @@ void
 terminal_set_winsize(struct terminal *tm, const struct winsize *size)
 {
 
-       terminal_set_winsize_blank(tm, size, 1);
+       terminal_set_winsize_blank(tm, size, 1,
+           (const term_attr_t *)&default_message);
 }
 
 /*

Modified: head/sys/sys/terminal.h
==============================================================================
--- head/sys/sys/terminal.h     Fri Jun 27 19:57:54 2014        (r267977)
+++ head/sys/sys/terminal.h     Fri Jun 27 19:57:57 2014        (r267978)
@@ -41,6 +41,9 @@
 
 #include <teken/teken.h>
 
+#include "opt_syscons.h"
+#include "opt_teken.h"
+
 struct terminal;
 struct thread;
 struct tty;
@@ -71,11 +74,71 @@ typedef uint32_t term_char_t;
 #define        TCHAR_CHARACTER(c)      ((c) & 0x1fffff)
 #define        TCHAR_FORMAT(c)         (((c) >> 21) & 0x1f)
 #define        TCHAR_FGCOLOR(c)        (((c) >> 26) & 0x7)
-#define        TCHAR_BGCOLOR(c)        ((c) >> 29)
+#define        TCHAR_BGCOLOR(c)        (((c) >> 29) & 0x7)
+
+typedef teken_attr_t term_attr_t;
 
 typedef teken_color_t term_color_t;
+#define        TCOLOR_FG(c)    (((c) & 0x7) << 26)
+#define        TCOLOR_BG(c)    (((c) & 0x7) << 29)
 #define        TCOLOR_LIGHT(c) ((c) | 0x8)
 #define        TCOLOR_DARK(c)  ((c) & ~0x8)
+
+#define        TFORMAT(c)      (((c) & 0x1f) << 21)
+
+/* syscons(4) compatible color attributes for foreground text */
+#define        FG_BLACK                TCOLOR_FG(TC_BLACK)
+#define        FG_BLUE                 TCOLOR_FG(TC_BLUE)
+#define        FG_GREEN                TCOLOR_FG(TC_GREEN)
+#define        FG_CYAN                 TCOLOR_FG(TC_CYAN)
+#define        FG_RED                  TCOLOR_FG(TC_RED)
+#define        FG_MAGENTA              TCOLOR_FG(TC_MAGENTA)
+#define        FG_BROWN                TCOLOR_FG(TC_BROWN)
+#define        FG_LIGHTGREY            TCOLOR_FG(TC_WHITE)
+#define        FG_DARKGREY             (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_BLACK))
+#define        FG_LIGHTBLUE            (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_BLUE))
+#define        FG_LIGHTGREEN           (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_GREEN))
+#define        FG_LIGHTCYAN            (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_CYAN))
+#define        FG_LIGHTRED             (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_RED))
+#define        FG_LIGHTMAGENTA         (TFORMAT(TF_BOLD) | 
TCOLOR_FG(TC_MAGENTA))
+#define        FG_YELLOW               (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_BROWN))
+#define        FG_WHITE                (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_WHITE))
+#define        FG_BLINK                TFORMAT(TF_BLINK)
+
+/* syscons(4) compatible color attributes for text background */
+#define        BG_BLACK                TCOLOR_BG(TC_BLACK)
+#define        BG_BLUE                 TCOLOR_BG(TC_BLUE)
+#define        BG_GREEN                TCOLOR_BG(TC_GREEN)
+#define        BG_CYAN                 TCOLOR_BG(TC_CYAN)
+#define        BG_RED                  TCOLOR_BG(TC_RED)
+#define        BG_MAGENTA              TCOLOR_BG(TC_MAGENTA)
+#define        BG_BROWN                TCOLOR_BG(TC_BROWN)
+#define        BG_LIGHTGREY            TCOLOR_BG(TC_WHITE)
+#define        BG_DARKGREY             (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_BLACK))
+#define        BG_LIGHTBLUE            (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_BLUE))
+#define        BG_LIGHTGREEN           (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_GREEN))
+#define        BG_LIGHTCYAN            (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_CYAN))
+#define        BG_LIGHTRED             (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_RED))
+#define        BG_LIGHTMAGENTA         (TFORMAT(TF_BOLD) | 
TCOLOR_BG(TC_MAGENTA))
+#define        BG_YELLOW               (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_BROWN))
+#define        BG_WHITE                (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_WHITE))
+
+#ifndef TERMINAL_NORM_ATTR
+#ifdef SC_NORM_ATTR
+#define        TERMINAL_NORM_ATTR      SC_NORM_ATTR
+#else
+#define        TERMINAL_NORM_ATTR      (FG_LIGHTGREY | BG_BLACK)
+#endif
+#endif
+
+#ifndef TERMINAL_KERN_ATTR
+#ifdef SC_KERNEL_CONS_ATTR
+#define        TERMINAL_KERN_ATTR      SC_KERNEL_CONS_ATTR
+#else
+#define        TERMINAL_KERN_ATTR      (FG_WHITE | BG_BLACK)
+#endif
+#endif
+
 typedef teken_pos_t term_pos_t;
 typedef teken_rect_t term_rect_t;
 
@@ -138,7 +201,7 @@ struct terminal {
 struct terminal *terminal_alloc(const struct terminal_class *tc, void *softc);
 void   terminal_maketty(struct terminal *tm, const char *fmt, ...);
 void   terminal_set_winsize_blank(struct terminal *tm,
-    const struct winsize *size, int blank);
+    const struct winsize *size, int blank, const term_attr_t *attr);
 void   terminal_set_winsize(struct terminal *tm, const struct winsize *size);
 void   terminal_mute(struct terminal *tm, int yes);
 void   terminal_input_char(struct terminal *tm, term_char_t c);
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to