1 Return-Path: <aperez@hikari.localdomain>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id DAD76431FBC
\r
6 for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 16:53:17 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id gSz0oNWnlT8G for <notmuch@notmuchmail.org>;
\r
11 Sun, 22 Nov 2009 16:53:17 -0800 (PST)
\r
12 Received: from alice.connectical.com (alice.connectical.com [208.89.208.235])
\r
13 by olra.theworths.org (Postfix) with ESMTP id 952F9431FAE
\r
14 for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 16:53:17 -0800 (PST)
\r
15 Received: (qmail 20466 invoked from network); 23 Nov 2009 00:53:16 -0000
\r
16 Received: from 28.218.27.77.dynamic.mundo-r.com (HELO hikari.localdomain)
\r
17 (aperez@77.27.218.28)
\r
18 by alice.connectical.com with ESMTPA; 23 Nov 2009 00:53:16 -0000
\r
19 Received: by hikari.localdomain (Postfix, from userid 500)
\r
20 id 7A8533114AF8; Mon, 23 Nov 2009 01:54:35 +0100 (CET)
\r
21 From: Adrian Perez <aperez@igalia.com>
\r
22 To: notmuch@notmuchmail.org
\r
23 Date: Mon, 23 Nov 2009 01:54:35 +0100
\r
24 Message-Id: <1258937675-31405-1-git-send-email-aperez@igalia.com>
\r
25 X-Mailer: git-send-email 1.6.5.2
\r
26 Subject: [notmuch] [PATCH] ANSI escapes in "new" only when output is a tty
\r
27 X-BeenThere: notmuch@notmuchmail.org
\r
28 X-Mailman-Version: 2.1.12
\r
30 List-Id: "Use and development of the notmuch mail system."
\r
31 <notmuch.notmuchmail.org>
\r
32 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
33 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
34 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
35 List-Post: <mailto:notmuch@notmuchmail.org>
\r
36 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
37 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
38 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
39 X-List-Received-Date: Mon, 23 Nov 2009 00:53:18 -0000
\r
41 When running "notmuch new --verbose", ANSI escapes are used. This may not be
\r
42 desirable when the output of the command is *not* being sent to a terminal
\r
43 (e.g. when piping output into another command). In that case each file
\r
44 processed is printed in a new line and ANSI escapes are not used at all.
\r
46 notmuch-client.h | 1 +
\r
47 notmuch-new.c | 12 ++++++++----
\r
48 2 files changed, 9 insertions(+), 4 deletions(-)
\r
50 diff --git a/notmuch-client.h b/notmuch-client.h
\r
51 index f105c8b..4fe182e 100644
\r
52 --- a/notmuch-client.h
\r
53 +++ b/notmuch-client.h
\r
54 @@ -74,6 +74,7 @@ typedef void (*add_files_callback_t) (notmuch_message_t *message);
\r
56 int ignore_read_only_directories;
\r
57 int saw_read_only_directory;
\r
58 + int output_is_a_tty;
\r
62 diff --git a/notmuch-new.c b/notmuch-new.c
\r
63 index a2b30bd..8172b49 100644
\r
66 @@ -180,10 +180,15 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
67 state->processed_files++;
\r
69 if (state->verbose) {
\r
70 - printf ("\r\033[K%i/%i: %s\r",
\r
71 + if (state->output_is_a_tty)
\r
72 + printf("\r\033[K");
\r
74 + printf ("%i/%i: %s",
\r
75 state->processed_files,
\r
79 + putchar((state->output_is_a_tty) ? '\r' : '\n');
\r
83 @@ -282,9 +287,7 @@ add_files (notmuch_database_t *notmuch,
\r
84 return NOTMUCH_STATUS_FILE_ERROR;
\r
87 - if (isatty (fileno (stdout)) && ! debugger_is_active ()
\r
88 - && ! state->verbose)
\r
90 + if (state->output_is_a_tty && ! debugger_is_active () && ! state->verbose) {
\r
91 /* Setup our handler for SIGALRM */
\r
92 memset (&action, 0, sizeof (struct sigaction));
\r
93 action.sa_handler = handle_sigalrm;
\r
94 @@ -405,6 +408,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
97 add_files_state.verbose = 0;
\r
98 + add_files_state.output_is_a_tty = isatty (fileno (stdout));
\r
100 for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
101 if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
\r