unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Hannu Hartikainen <hannu@hrtk.in>
To: notmuch@notmuchmail.org
Cc: Hannu Hartikainen <hannu@hrtk.in>
Subject: [PATCH] cli/show: add --color/--no-color
Date: Tue, 22 Jun 2021 15:34:10 +0300	[thread overview]
Message-ID: <20210622123410.323216-1-hannu@hrtk.in> (raw)
In-Reply-To: <20210619203838.275767-1-hannu@hrtk.in>

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:<thread-id>" 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 = &params.crypto.verify, .name = "verify" },
 	{ .opt_bool = &params.output_body, .name = "body" },
 	{ .opt_bool = &params.include_html, .name = "include-html" },
+	{ .opt_bool = &params.color, .name = "color" },
 	{ .opt_inherit = notmuch_shared_options },
 	{ }
     };
-- 
2.32.0

  reply	other threads:[~2021-06-22 12:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-19 20:38 [PATCH] cli/show: add --format=pretty Hannu Hartikainen
2021-06-22 12:34 ` Hannu Hartikainen [this message]
2021-07-12  8:38   ` Yet another revision of --format=pretty Hannu Hartikainen
2021-07-12  8:38     ` [PATCH v3 1/2] cli/show: add --format=pretty Hannu Hartikainen
2021-07-12 23:40       ` David Bremner
2021-07-13 10:24         ` David Bremner
2021-07-13 11:50           ` Hannu Hartikainen
2021-07-12  8:38     ` [PATCH v3 2/2] cli/show: add color for --format=pretty Hannu Hartikainen
2021-07-12 23:19     ` Yet another revision of --format=pretty David Bremner
2021-07-13 12:07       ` Hannu Hartikainen
2021-07-02 20:31 ` [PATCH v2] cli/show: add --format=pretty Hannu Hartikainen
2021-07-04  9:40   ` Tomi Ollila
2021-07-04 11:54     ` Hannu Hartikainen
2021-07-04 14:38 ` [PATCH] " David Bremner
2021-07-05 13:31   ` Hannu Hartikainen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210622123410.323216-1-hannu@hrtk.in \
    --to=hannu@hrtk.in \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).