From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 826BC1F5AE for ; Mon, 17 May 2021 16:51:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242214AbhEQQww (ORCPT ); Mon, 17 May 2021 12:52:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240423AbhEQQwm (ORCPT ); Mon, 17 May 2021 12:52:42 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB26BC061364 for ; Mon, 17 May 2021 09:49:48 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id a25so7699570edr.12 for ; Mon, 17 May 2021 09:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:references:user-agent:in-reply-to :message-id:mime-version; bh=ZU/Q6RL8lUkXGvcPnqUhky5cL+s2AP7scQz77ssYqa0=; b=YULzspe0R90XhFfvgeC5PripzGWCQrgNeS/NECk2QNq+dipzUIFDtgWGkAlW7wuupx 7177GUnMFr03wtQqyCQkFK5X7+enHeAL3y90OET2KoGiw6D2zmUoKk8cgCUrvzT/DZLQ D9nfPXK82XNq7BBcCfZbNTWypoWlXL2xHbHq8d9xjoKsb+pmhkWpt8IE8MYP+27eBAxg ajeOi872tfudc6uMfkU83dLO6I6l3o9aOXdrujzpT9t73lnTFNdHFqckpkQW4qEvnBVx 7572XgJU4jwWhdimukYc/uW8x7FWCEhWnyM/EqNIL2yTWNw4sve6vlQcbeypdfbIjb5j p1ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:references:user-agent :in-reply-to:message-id:mime-version; bh=ZU/Q6RL8lUkXGvcPnqUhky5cL+s2AP7scQz77ssYqa0=; b=Yl2olYfVxrWxhGtCMOaWHhFBdtOWXE0bmtExsgCchibRhD6YDyJ2zNyKXHSuUZWCde mVo3DtZjq9S1zc/sZFJbxySuLa3gxesoCEXEjg5+GBYLriGcnIBQ1/mZ4cnKThsCQh7H Kfq3BHtRrS7mebgELvMLXPL0qJRyPD90Sjcfb9Z+Rmp5JNS8IhfHpmbqksAkI/3eykBP WozJLb2RCyxT+zz6CCBFEkOcHGE2KoYViEHtTc5kgTuQaP4lSqktONbi9WpbWKubN+E5 uCtcB4bSI+/QbKEBbKRc/c71YNyWGFJJdcQFXDMVWkRyoWtfO+sl92VNB02s0h4d8vSA 6shQ== X-Gm-Message-State: AOAM5335ywRysgSq4X+6YIvB5O/u70oYxH9I/z4OoIzlaVlC36abTX4M dHT1r9xpteMM4P5SmMNOm4w= X-Google-Smtp-Source: ABdhPJxm45Dw3ZKBj6ioErD9Il8/DmgzXDIAF4HwKIxNDZuk4dDUAUsYfjSyM6GVNVu5e1yxz09afA== X-Received: by 2002:a05:6402:438d:: with SMTP id o13mr1162206edc.324.1621270187423; Mon, 17 May 2021 09:49:47 -0700 (PDT) Received: from evledraar (j57224.upc-j.chello.nl. [24.132.57.224]) by smtp.gmail.com with ESMTPSA id y2sm8823391ejg.123.2021.05.17.09.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 09:49:47 -0700 (PDT) From: =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason To: Felipe Contreras Cc: git@vger.kernel.org Subject: Re: Man pages have colors? A deep dive into groff Date: Mon, 17 May 2021 18:48:04 +0200 References: <60a046bd83001_f4b0f20861@natae.notmuch> User-agent: Debian GNU/Linux bullseye/sid; Emacs 27.1; mu4e 1.5.12 In-reply-to: <60a046bd83001_f4b0f20861@natae.notmuch> Message-ID: <87tun1qp91.fsf@evledraar.gmail.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Sat, May 15 2021, Felipe Contreras wrote: > Hi, > > While I was doing the investigagion for my GNU_ROFF patch [1], I checked > different versions of all the tools (asciidoc, asciidoctor, docbook, and > groff). > > When I tested my own compiled version of groff I noticed something > weird: man pages have colors. This did not happen with the version > shipped by Arch Linux. > > I did notice the output generated by docbook stylesheets showed > \m[blue], but no color showed up. > > It turns out Arch Linux disables colors, and so does Debian, by > disabling a feature called SGR. This happened about 10 years, and the > rationale was that "it doesn't work correctly". > > To enable SGR on these distributions you need to do GROFF_SGR=1, but > that is not documented anywhere. > > groff does check for a variable GROFF_NO_SGR, but it's the other way > around: SGR is enabled unless that variable is set. > > There's other ways your distribution might be screwing up with groff > (for example Arch Linux converts \' to ', which is not correct), so you > might want to check your shipped configuration in: > > /usr/share/groff/site-tmac/man.local > > Unfortunately the colors in man pages leave a lot to be desired. > > Here is a simple trick I've been using to show some custom colors: > > man() { > GROFF_NO_SGR=1 \ > LESS_TERMCAP_md=$'\e[1;31m' \ > LESS_TERMCAP_me=$'\e[0m' \ > LESS_TERMCAP_us=$'\e[1;34m' \ > LESS_TERMCAP_ue=$'\e[0m' \ > LESS_TERMCAP_so=$'\e[1;35m' \ > LESS_TERMCAP_se=$'\e[0m' \ > command man "$@" > } > > Hopefully some of you might find this useful. > > Cheers. > > [1] https://lore.kernel.org/git/20210515115653.922902-2-felipe.contreras@gmail.com/ This looks much better. I wonder a good follow-up (hint, hint! :) would be to have exec_man_man() and exec_man_cmd() in builtin/help.c set this depending on color.ui (so we'd do it by default with "auto"). Then e.g. "git help git" would look prettier than "man git".