From owner-svn-src-all@FreeBSD.ORG Mon Jun 30 09:59:25 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 255DE749; Mon, 30 Jun 2014 09:59:25 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EA17823E1; Mon, 30 Jun 2014 09:59:24 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5U9xORB096843; Mon, 30 Jun 2014 09:59:24 GMT (envelope-from marius@svn.freebsd.org) Received: (from marius@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s5U9xNeM096835; Mon, 30 Jun 2014 09:59:23 GMT (envelope-from marius@svn.freebsd.org) Message-Id: <201406300959.s5U9xNeM096835@svn.freebsd.org> From: Marius Strobl Date: Mon, 30 Jun 2014 09:59:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r268037 - in stable/10: share/man/man4 sys/conf sys/dev/vt sys/kern sys/sys X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jun 2014 09:59:25 -0000 Author: marius Date: Mon Jun 30 09:59:23 2014 New Revision: 268037 URL: http://svnweb.freebsd.org/changeset/base/268037 Log: MFC: r267978 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 Sponsored by: Bally Wulff Games & Entertainment GmbH Modified: stable/10/share/man/man4/vt.4 stable/10/sys/conf/options stable/10/sys/dev/vt/vt.h stable/10/sys/dev/vt/vt_buf.c stable/10/sys/dev/vt/vt_core.c stable/10/sys/kern/subr_terminal.c stable/10/sys/sys/terminal.h Directory Properties: stable/10/ (props changed) Modified: stable/10/share/man/man4/vt.4 ============================================================================== --- stable/10/share/man/man4/vt.4 Mon Jun 30 09:55:29 2014 (r268036) +++ stable/10/share/man/man4/vt.4 Mon Jun 30 09:59:23 2014 (r268037) @@ -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" @@ -106,6 +108,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 . @@ -135,6 +146,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 @@ -170,6 +183,21 @@ Set to 1 to use virtual terminals in tex Features that require graphics mode, like loadable fonts, will be disabled. .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: stable/10/sys/conf/options ============================================================================== --- stable/10/sys/conf/options Mon Jun 30 09:55:29 2014 (r268036) +++ stable/10/sys/conf/options Mon Jun 30 09:59:23 2014 (r268037) @@ -765,10 +765,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: stable/10/sys/dev/vt/vt.h ============================================================================== --- stable/10/sys/dev/vt/vt.h Mon Jun 30 09:55:29 2014 (r268036) +++ stable/10/sys/dev/vt/vt.h Mon Jun 30 09:59:23 2014 (r268037) @@ -230,7 +230,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: stable/10/sys/dev/vt/vt_buf.c ============================================================================== --- stable/10/sys/dev/vt/vt_buf.c Mon Jun 30 09:55:29 2014 (r268036) +++ stable/10/sys/dev/vt/vt_buf.c Mon Jun 30 09:59:23 2014 (r268037) @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -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: stable/10/sys/dev/vt/vt_core.c ============================================================================== --- stable/10/sys/dev/vt/vt_core.c Mon Jun 30 09:55:29 2014 (r268036) +++ stable/10/sys/dev/vt/vt_core.c Mon Jun 30 09:59:23 2014 (r268037) @@ -956,6 +956,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 (vd->vd_flags & VDF_INITIALIZED) /* Initialization already done. */ @@ -997,7 +999,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 @@ -1155,7 +1162,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. */ @@ -2116,7 +2123,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: stable/10/sys/kern/subr_terminal.c ============================================================================== --- stable/10/sys/kern/subr_terminal.c Mon Jun 30 09:55:29 2014 (r268036) +++ stable/10/sys/kern/subr_terminal.c Mon Jun 30 09:59:23 2014 (r268037) @@ -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: stable/10/sys/sys/terminal.h ============================================================================== --- stable/10/sys/sys/terminal.h Mon Jun 30 09:55:29 2014 (r268036) +++ stable/10/sys/sys/terminal.h Mon Jun 30 09:59:23 2014 (r268037) @@ -41,6 +41,9 @@ #include +#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);