From owner-svn-src-all@FreeBSD.ORG Fri Jun 3 14:34:39 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4CDE31065686; Fri, 3 Jun 2011 14:34:39 +0000 (UTC) (envelope-from ru@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3C0EC8FC08; Fri, 3 Jun 2011 14:34:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p53EYdlO067895; Fri, 3 Jun 2011 14:34:39 GMT (envelope-from ru@svn.freebsd.org) Received: (from ru@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p53EYd3i067892; Fri, 3 Jun 2011 14:34:39 GMT (envelope-from ru@svn.freebsd.org) Message-Id: <201106031434.p53EYd3i067892@svn.freebsd.org> From: Ruslan Ermilov Date: Fri, 3 Jun 2011 14:34:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222653 - head/usr.bin/man X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Fri, 03 Jun 2011 14:34:39 -0000 Author: ru Date: Fri Jun 3 14:34:38 2011 New Revision: 222653 URL: http://svn.freebsd.org/changeset/base/222653 Log: When MANCOLOR environment variable is set, enable ANSI color escapes in grotty(1). This makes it possible to view colorized manpages in color. When MANPAGER environment variable is set, use it instead of PAGER. Why another environment variable, one might ask? With color output enabled, both a terminal and a pager should support the ANSI color escapes. On a supporting terminal, less(1) with option -R would be such a pager, while "more -s" (the current default pager for man(1)) will show garbage. It means a different default pager is needed when color output is enabled, but many people have PAGER set customary, and it's unlikely to support ANSI color escapes, so introducing yet another variable (MANPAGER) seemed like a good option to me: - if MANPAGER is set, use that unconditionally; - if you disable color support (it is by default), and don't set MANPAGER, you get an old behavior: -P pager, $PAGER, "more -s", in that order; - if you enable color support (by setting MANCOLOR), and don't set MANPAGER, we ignore PAGER which is unlikely to support ANSI color escapes, and you get: -P pager, "less -Rs", in that order; - you might have good reasons for different man(1) and general purpose pagers; - later versions of GNU man(1) support MANPAGER. Modified: head/usr.bin/man/man.1 head/usr.bin/man/man.sh Modified: head/usr.bin/man/man.1 ============================================================================== --- head/usr.bin/man/man.1 Fri Jun 3 13:49:18 2011 (r222652) +++ head/usr.bin/man/man.1 Fri Jun 3 14:34:38 2011 (r222653) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 2, 2011 +.Dd June 3, 2011 .Dt MAN 1 .Os .Sh NAME @@ -73,8 +73,12 @@ environment variable. .It Fl P Ar pager Use specified pager. Defaults to +.Ic "less -sR" +if color support is enabled, or .Ic "more -s" . Overrides the +.Ev MANPAGER +environment variable, which in turn overrides the .Ev PAGER environment variable. .It Fl S Ar mansect @@ -289,9 +293,19 @@ Otherwise, if set to a special value .Dq Li tty , and output is to a terminal, the pages may be displayed over the whole width of the screen. -.It Ev PAGER +.It Ev MANCOLOR +If set, enables color support. +.It Ev MANPAGER Program used to display files. -If unset, +.Pp +If unset, and color support is enabled, +.Ic "less -sR" +is used. +.Pp +If unset, and color support is disabled, then +.Ev PAGER +is used. +If that has no value either, .Ic "more -s" is used. .El Modified: head/usr.bin/man/man.sh ============================================================================== --- head/usr.bin/man/man.sh Fri Jun 3 13:49:18 2011 (r222652) +++ head/usr.bin/man/man.sh Fri Jun 3 14:34:38 2011 (r222653) @@ -294,10 +294,10 @@ man_display_page() { ret=0 else if [ $debug -gt 0 ]; then - decho "Command: $cattool $catpage | $PAGER" + decho "Command: $cattool $catpage | $MANPAGER" ret=0 else - eval "$cattool $catpage | $PAGER" + eval "$cattool $catpage | $MANPAGER" ret=$? fi fi @@ -356,6 +356,10 @@ man_display_page() { ;; esac + if [ -z "$MANCOLOR" ]; then + NROFF="$NROFF -P-c" + fi + if [ -n "${use_width}" ]; then NROFF="$NROFF -rLL=${use_width}n -rLT=${use_width}n" fi @@ -382,7 +386,7 @@ man_display_page() { if [ -n "$tflag" ]; then pipeline="$pipeline | $TROFF" else - pipeline="$pipeline | $NROFF | $PAGER" + pipeline="$pipeline | $NROFF | $MANPAGER" fi if [ $debug -gt 0 ]; then @@ -484,7 +488,7 @@ man_parse_args() { while getopts 'M:P:S:adfhkm:op:tw' cmd_arg; do case "${cmd_arg}" in M) MANPATH=$OPTARG ;; - P) PAGER=$OPTARG ;; + P) MANPAGER=$OPTARG ;; S) MANSECT=$OPTARG ;; a) aflag=aflag ;; d) debug=$(( $debug + 1 )) ;; @@ -808,7 +812,7 @@ search_whatis() { bad=${bad#\\n} if [ -n "$good" ]; then - echo -e "$good" | $PAGER + echo -e "$good" | $MANPAGER fi if [ -n "$bad" ]; then @@ -832,13 +836,21 @@ setup_cattool() { } # Usage: setup_pager -# Correctly sets $PAGER +# Correctly sets $MANPAGER setup_pager() { # Setup pager. - if [ -z "$PAGER" ]; then - PAGER="more -s" + if [ -z "$MANPAGER" ]; then + if [ -n "$MANCOLOR" ]; then + MANPAGER="less -sR" + else + if [ -n "$PAGER" ]; then + MANPAGER="$PAGER" + else + MANPAGER="more -s" + fi + fi fi - decho "Using pager: $PAGER" + decho "Using pager: $MANPAGER" } # Usage: trim string @@ -921,7 +933,7 @@ do_whatis() { # User's PATH setting decides on the groff-suite to pick up. EQN=eqn -NROFF='groff -S -P-ch -Wall -mtty-char -man' +NROFF='groff -S -P-h -Wall -mtty-char -man' PIC=pic REFER=refer TBL=tbl