--- /dev/null
+Return-Path: <aperez@hikari.localdomain>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id DAD76431FBC\r
+ for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 16:53:17 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id gSz0oNWnlT8G for <notmuch@notmuchmail.org>;\r
+ Sun, 22 Nov 2009 16:53:17 -0800 (PST)\r
+Received: from alice.connectical.com (alice.connectical.com [208.89.208.235])\r
+ by olra.theworths.org (Postfix) with ESMTP id 952F9431FAE\r
+ for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 16:53:17 -0800 (PST)\r
+Received: (qmail 20466 invoked from network); 23 Nov 2009 00:53:16 -0000\r
+Received: from 28.218.27.77.dynamic.mundo-r.com (HELO hikari.localdomain)\r
+ (aperez@77.27.218.28)\r
+ by alice.connectical.com with ESMTPA; 23 Nov 2009 00:53:16 -0000\r
+Received: by hikari.localdomain (Postfix, from userid 500)\r
+ id 7A8533114AF8; Mon, 23 Nov 2009 01:54:35 +0100 (CET)\r
+From: Adrian Perez <aperez@igalia.com>\r
+To: notmuch@notmuchmail.org\r
+Date: Mon, 23 Nov 2009 01:54:35 +0100\r
+Message-Id: <1258937675-31405-1-git-send-email-aperez@igalia.com>\r
+X-Mailer: git-send-email 1.6.5.2\r
+Subject: [notmuch] [PATCH] ANSI escapes in "new" only when output is a tty\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 23 Nov 2009 00:53:18 -0000\r
+\r
+When running "notmuch new --verbose", ANSI escapes are used. This may not be\r
+desirable when the output of the command is *not* being sent to a terminal\r
+(e.g. when piping output into another command). In that case each file\r
+processed is printed in a new line and ANSI escapes are not used at all.\r
+---\r
+ notmuch-client.h | 1 +\r
+ notmuch-new.c | 12 ++++++++----\r
+ 2 files changed, 9 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index f105c8b..4fe182e 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -74,6 +74,7 @@ typedef void (*add_files_callback_t) (notmuch_message_t *message);\r
+ typedef struct {\r
+ int ignore_read_only_directories;\r
+ int saw_read_only_directory;\r
++ int output_is_a_tty;\r
+ int verbose;\r
+ \r
+ int total_files;\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index a2b30bd..8172b49 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -180,10 +180,15 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+ state->processed_files++;\r
+ \r
+ if (state->verbose) {\r
+- printf ("\r\033[K%i/%i: %s\r",\r
++ if (state->output_is_a_tty)\r
++ printf("\r\033[K");\r
++\r
++ printf ("%i/%i: %s",\r
+ state->processed_files,\r
+ state->total_files,\r
+ next);\r
++\r
++ putchar((state->output_is_a_tty) ? '\r' : '\n');\r
+ fflush (stdout);\r
+ }\r
+ \r
+@@ -282,9 +287,7 @@ add_files (notmuch_database_t *notmuch,\r
+ return NOTMUCH_STATUS_FILE_ERROR;\r
+ }\r
+ \r
+- if (isatty (fileno (stdout)) && ! debugger_is_active ()\r
+- && ! state->verbose)\r
+- {\r
++ if (state->output_is_a_tty && ! debugger_is_active () && ! state->verbose) {\r
+ /* Setup our handler for SIGALRM */\r
+ memset (&action, 0, sizeof (struct sigaction));\r
+ action.sa_handler = handle_sigalrm;\r
+@@ -405,6 +408,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+ int i;\r
+ \r
+ add_files_state.verbose = 0;\r
++ add_files_state.output_is_a_tty = isatty (fileno (stdout));\r
+ \r
+ for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
+ if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
+-- \r
+1.6.5.2\r
+\r