From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YD37FunY0WC8hQAAgWs5BA (envelope-from ) for ; Tue, 22 Jun 2021 14:34:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id KEGJEunY0WAaTAAAbx9fmQ (envelope-from ) for ; Tue, 22 Jun 2021 12:34:49 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 452AE1C233 for ; Tue, 22 Jun 2021 14:34:48 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id D4DEB29033; Tue, 22 Jun 2021 08:34:40 -0400 (EDT) Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by mail.notmuchmail.org (Postfix) with ESMTPS id B099727D92 for ; Tue, 22 Jun 2021 08:34:37 -0400 (EDT) Received: by mail-lf1-f53.google.com with SMTP id i18so1233594lfl.8 for ; Tue, 22 Jun 2021 05:34:37 -0700 (PDT) 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:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2KTm7ehDd5z4wKDPrgCO6UjMN2FEDN20qEL7dBxoPVw=; b=hg3Q6cVIZv2cXVmgN6NBCX14U2Y2m7eF2AVAgz7/dvsoaDTRGKNWg36FdSSpp0Z7Fo uP+GrW3QFddhb+/vGzUkPxDVRkbHF9V8WL4hZu0OfEAQOiIEBfZeu/a2E0aPThkPwP+l PfMM1umDMdF8XkZ1T3FXgGAbLrwnXpV2tLKib8NtCPZIkK7FlfccJI79wzBGmgz0VqBd nwLJElKYvJm6XWMCUZ/Y+mVu0zJg8ZHwDQOcid5q74UAHvuce93DWPoO6nFk7tLsGz6P K8A4oWpHGi8mb7jorxsqG9epeeeSJYX4VMn+62I78J/RDYYsZg5k/w5h+wN2Zquue7AA jSiw== X-Gm-Message-State: AOAM532t2bp00jBIyZzd4EpXVlWnshrGllrNUw9XWwS/AnEQsltwJi9+ 88fbQom22ycZn+1XMNnH0DxBHflUAb8Xug== X-Google-Smtp-Source: ABdhPJxP/JhYwaTVxBCjIO2rS8KNlI4Gv4Dvrinl8mOc0vUo0wAX4qMSk1h/FfArmEzC7J2vOm0m/A== X-Received: by 2002:a19:f612:: with SMTP id x18mr2793500lfe.77.1624365275981; Tue, 22 Jun 2021 05:34:35 -0700 (PDT) Received: from localhost (88-112-11-80.elisa-laajakaista.fi. [88.112.11.80]) by smtp.gmail.com with ESMTPSA id f15sm283076ljm.96.2021.06.22.05.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Jun 2021 05:34:35 -0700 (PDT) From: Hannu Hartikainen To: notmuch@notmuchmail.org Subject: [PATCH] cli/show: add --color/--no-color Date: Tue, 22 Jun 2021 15:34:10 +0300 Message-Id: <20210622123410.323216-1-hannu@hrtk.in> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210619203838.275767-1-hannu@hrtk.in> References: <20210619203838.275767-1-hannu@hrtk.in> MIME-Version: 1.0 Message-ID-Hash: JHZZ522UZ4RS5LJ33RNRHG6RTCF7OZVA X-Message-ID-Hash: JHZZ522UZ4RS5LJ33RNRHG6RTCF7OZVA X-MailFrom: hannu.hartikainen@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Hannu Hartikainen X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1624365288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iKHAntnRlvq3/u11dA82W4511tKZmDZ1cJa18p1KjPY=; b=CU8SMwNI01Sk/qyJn8crzZ9zyy1hmXMDlcTLTQN+47BprLkBPrgmm95T/NMNR/ouJ7Ie7n RBbkYbOWETQ2o/dt2iNcUo6OSJqz0IU81c6nQkLBBzunwbhwh9AApcohu4alSUDywws4ke 6Zh1OWtPO0VOQJLr8lGyFPcMxaJydjPyZ6u0IL9bhbTdZtAnpHp2BLtTsDbODRL1ke+QhA PIK+/wMpuzZ/RCG4By2ALL336WzGCNCYIS+vtpJn4i3USpkQkHhWuqI+Lux3hKNOQOPn7i pYaAK6zW/mQeYM8AtUQ/KhMQ3ZoGm+jKdmwkX/9hsKIq9roUdURvyN62fnFa4A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1624365288; a=rsa-sha256; cv=none; b=BRkj5p/pI2ESxvZHCXU+3UF6niTV9/xIXIw07c1b4V2dDtXM1jfyowN6yuosK50Aw6mwHd 6CiY6tvYNH6rXSbYi4UmqERrbJFAeDz7JIcZwIPdsLxtYpnCxiFEEXJpaAwaKU8Qy+wUF5 9RZWfZ/IoL1DB+qDEA8wO1wqktl4fwpfnSJOawDvlFcXl4YpD+BkBtdB5GrOCSfepBxCvk DG6n9bAqRSk7QlZJ2oTmXYGmM6qP2hZVXHytqOpnDHa/7YwKBMRBTLSa6sa2fr94wQvSFX UP91dDz49n2TYKkqHgfhUWU/QQuEqvY0OcTFHH6uN0u5NBVrgvlo4EtkXYyEng== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.98 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 452AE1C233 X-Spam-Score: -0.98 X-Migadu-Scanner: scn1.migadu.com X-TUID: lRzuqtdAUprH These arguments allow setting color explicitly on or off when using `--format=pretty`. The default is still to use color iff stdout is a TTY. --- I got a reply off-list to my previous patch (cli/show: add --format=pretty) about explicitly enabling color (for use with $PAGER). It's quite a minor addition so I just implemented it. IMHO this warrants its own commit; it's a separate feature from --format=pretty. But I'm ok with squashing these together if that's considered better. Of course, with an explicit --color command-line argument in one command for one purpose, one could reasonably ask if other commands should support colored output as well. What do you all think? doc/man1/notmuch-show.rst | 6 ++++++ notmuch-client.h | 1 + notmuch-show.c | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst index 1fe4dcc7..e61000a6 100644 --- a/doc/man1/notmuch-show.rst +++ b/doc/man1/notmuch-show.rst @@ -209,6 +209,12 @@ Supported options for **show** include "text/html" parts, no part with content type "text/html" is included in the output. +.. option:: --color + + Use colored output for formats that support that (currently only + ``--format=pretty``). By default, color is used if the output + goes to a TTY. To disable color, use ``--no-color``. + A common use of **notmuch show** is to display a single thread of email messages. For this, use a search term of "thread:" as can be seen in the first column of output from the diff --git a/notmuch-client.h b/notmuch-client.h index 8227fea4..c4f7cfd6 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -78,6 +78,7 @@ typedef struct notmuch_show_params { int part; _notmuch_crypto_t crypto; bool include_html; + bool color; GMimeStream *out_stream; } notmuch_show_params_t; diff --git a/notmuch-show.c b/notmuch-show.c index fe3b753e..6274a99a 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -612,7 +612,7 @@ format_part_pretty (const void *ctx, sprinter_t *sp, mime_node_t *node, GMimeContentType *content_type = g_mime_object_get_content_type (meta); GMimeStream *stream = params->out_stream; int i; - bool color = isatty (fileno (stdout)); + bool color = params->color; if (GMIME_IS_MESSAGE (node->part)) { GMimeMessage *message = GMIME_MESSAGE (node->part); @@ -1300,6 +1300,7 @@ notmuch_show_command (notmuch_database_t *notmuch, int argc, char *argv[]) .part = -1, .omit_excluded = true, .output_body = true, + .color = isatty (fileno (stdout)), .crypto = { .decrypt = NOTMUCH_DECRYPT_AUTO }, }; int format = NOTMUCH_FORMAT_NOT_SPECIFIED; @@ -1334,6 +1335,7 @@ notmuch_show_command (notmuch_database_t *notmuch, int argc, char *argv[]) { .opt_bool = ¶ms.crypto.verify, .name = "verify" }, { .opt_bool = ¶ms.output_body, .name = "body" }, { .opt_bool = ¶ms.include_html, .name = "include-html" }, + { .opt_bool = ¶ms.color, .name = "color" }, { .opt_inherit = notmuch_shared_options }, { } }; -- 2.32.0