[notmuch] [PATCH] ANSI escapes in "new" only when output is a tty

Carl Worth cworth at cworth.org
Sun Nov 22 21:12:09 PST 2009


On Mon, 23 Nov 2009 01:54:35 +0100, Adrian Perez <aperez at igalia.com> wrote:
> When running "notmuch new --verbose", ANSI escapes are used. This may not be
> desirable when the output of the command is *not* being sent to a terminal
> (e.g. when piping output into another command). In that case each file
> processed is printed in a new line and ANSI escapes are not used at
> all.

I've pushed this now.

And I've noticed two things with it:

1. The filenames are often quite long, and if longer than my terminal
width, then I get one line per output rather than one line continually
erased and reprinted. Any good idea about how to fix that without going
too crazy?

2. On any run after the first, the output says "1/0", "2/0", etc.
So we should fix that to either not print the "/0" when total_messages
is 0 *or* we can just make "notmuch new" unconditionally count the
number of files to be processed, (which I've been thinking I wanted to
do anyway).

I'm trying to eliminate any remaining differences between "notmuch new"
on an initial run and "notmuch new" run later. An important reason to
eliminate these differences is that we want to support the user
interrupting the initial database build and then starting it up again
without losing anything.

Besides the file counting, (which would only make such a user lose the
countdown timer on the subsequent runs), the only other thing we have
different about the first run is that it doesn't ignore read-only
directories. And that one's a problem because it means that if someone
(like me) that has a bunch of read-only directories does the following:

      notmuch dump notmuch.dump
      rm -rf ~/mail/notmuch
      notmuch new # then interrupt this with control-C
      notmuch new # oops! This missed most of my mail
      notmuch restore notmuch.dump

Things go badly wrong here as any mail in read-only directories that
didn't get picked up in the first "notmuch new" run will forever more be
ignored by notmuch new.

So that's totally broken and we should come up with a way to fix it.

-Carl


More information about the notmuch mailing list