[notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output format, with output control

2010-03-10 Thread David Bremner
On Wed, 10 Mar 2010 01:25:22 -0800, Carl Worth  wrote:
> On Tue, 09 Mar 2010 16:19:16 -0400, David Bremner  
> wrote:
> > 
> > --format=tabular --output=message-id
> 
> Ah, so maybe your "notmuch show --format=tabular" is basically the same
> thing I imagined for "notmuch search" (once we teach it to accept a list
> of the desired elements to output).

There is a third "control axis", namely one piece of output per thread
(current "notmuch search" style), or all of the messages ("notmuch show
style")



[notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output format, with output control

2010-03-10 Thread Carl Worth
On Tue, 09 Mar 2010 16:19:16 -0400, David Bremner  wrote:
> I think some tabular format would be handy because it is very easy to
> parse with scripts, and because it is a natural natural way to get
> e.g. a list of message-ids.
> 
> --format=tabular --output=message-id

Ah, so maybe your "notmuch show --format=tabular" is basically the same
thing I imagined for "notmuch search" (once we teach it to accept a list
of the desired elements to output).

> On the other hand, I'm not yet using this code, so I guess the main
> point is to discuss how output control should be implemented, and in
> that sense the patch is a demo. I suspect once we start using json
> output more, we will definitely want it there.

Yes. I think we next need to implement some --output options and then
see what we want from there.

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



Re: [notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output format, with output control

2010-03-10 Thread David Bremner
On Wed, 10 Mar 2010 01:25:22 -0800, Carl Worth cwo...@cworth.org wrote:
 On Tue, 09 Mar 2010 16:19:16 -0400, David Bremner da...@tethera.net wrote:
  
  --format=tabular --output=message-id
 
 Ah, so maybe your notmuch show --format=tabular is basically the same
 thing I imagined for notmuch search (once we teach it to accept a list
 of the desired elements to output).

There is a third control axis, namely one piece of output per thread
(current notmuch search style), or all of the messages (notmuch show
style)

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output format, with output control

2010-03-09 Thread David Bremner
On Tue, 09 Mar 2010 11:51:46 -0800, Carl Worth  wrote:

> Are you proposing the tabular format for inclusion in notmuch?
> 
> Or does "prototype" suggest that you were just showing a demonstration
> of what could be done here?
> 
> If you do want this included, what's the motivation for this format?

I think some tabular format would be handy because it is very easy to
parse with scripts, and because it is a natural natural way to get
e.g. a list of message-ids.

--format=tabular --output=message-id

On the other hand, I'm not yet using this code, so I guess the main
point is to discuss how output control should be implemented, and in
that sense the patch is a demo. I suspect once we start using json
output more, we will definitely want it there.

All the best, 

David


[notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output format, with output control

2010-03-09 Thread Carl Worth
On Sat, 19 Dec 2009 10:55:24 -0400, david at tethera.net wrote:
> From: David Bremner 
> 
> Currently this only outputs the information from the "message header";
> i.e. the part before the rfc2822 header or body.

Hi David, 

Are you proposing the tabular format for inclusion in notmuch?

Or does "prototype" suggest that you were just showing a demonstration
of what could be done here?

If you do want this included, what's the motivation for this format?

Thanks,

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



Re: [notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output format, with output control

2010-03-09 Thread Carl Worth
On Sat, 19 Dec 2009 10:55:24 -0400, da...@tethera.net wrote:
 From: David Bremner brem...@unb.ca
 
 Currently this only outputs the information from the message header;
 i.e. the part before the rfc2822 header or body.

Hi David, 

Are you proposing the tabular format for inclusion in notmuch?

Or does prototype suggest that you were just showing a demonstration
of what could be done here?

If you do want this included, what's the motivation for this format?

Thanks,

-Carl


pgpTzgk3Lel3p.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output format, with output control

2010-03-09 Thread David Bremner
On Tue, 09 Mar 2010 11:51:46 -0800, Carl Worth cwo...@cworth.org wrote:

 Are you proposing the tabular format for inclusion in notmuch?
 
 Or does prototype suggest that you were just showing a demonstration
 of what could be done here?
 
 If you do want this included, what's the motivation for this format?

I think some tabular format would be handy because it is very easy to
parse with scripts, and because it is a natural natural way to get
e.g. a list of message-ids.

--format=tabular --output=message-id

On the other hand, I'm not yet using this code, so I guess the main
point is to discuss how output control should be implemented, and in
that sense the patch is a demo. I suspect once we start using json
output more, we will definitely want it there.

All the best, 

David
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output format, with output control

2009-12-19 Thread da...@tethera.net
From: David Bremner 

Currently this only outputs the information from the "message header";
i.e. the part before the rfc2822 header or body.

Adding this required adding an extra parameter, currently unused, to
format_message_text and format_message_json. Also the struct
definition is changed to match the new function prototypes.

An int (enum) is used as a mask, each bit corresponds to some part to
be shown or not shown.  This enum will need to be extended as more
things are controllable via --show.
---
 notmuch-show.c |   89 ---
 1 files changed, 77 insertions(+), 12 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 51aa87d..99a4d3c 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -20,10 +20,18 @@

 #include "notmuch-client.h"

+/* These should be powers of 2 */
+typedef enum {SHOW_MESSAGE_ID = 1, 
+ SHOW_MATCH = 2, 
+ SHOW_FILENAME = 4
+} show_mask_t;
+
+static const show_mask_t SHOW_ALL = ~0;
+
 typedef struct show_format {
 const char *message_set_start;
 const char *message_start;
-void (*message) (const void *ctx,
+void (*message) (const void *ctx, show_mask_t show_mask,
 notmuch_message_t *message,
 int indent);
 const char *header_start;
@@ -40,7 +48,7 @@ typedef struct show_format {
 } show_format_t;

 static void
-format_message_text (unused (const void *ctx),
+format_message_text (unused (const void *ctx), show_mask_t show_mask,
 notmuch_message_t *message,
 int indent);
 static void
@@ -59,7 +67,21 @@ static const show_format_t format_text = {
 };

 static void
-format_message_json (const void *ctx,
+format_message_tabular (unused (const void *ctx), show_mask_t show_mask,
+notmuch_message_t *message,
+int indent);
+
+static const show_format_t format_tabular = {
+"", 
+"", format_message_tabular, 
+"", NULL, "", 
+"", NULL, "",
+"\n", "", 
+""
+};
+
+static void
+format_message_json (const void *ctx, show_mask_t show_mask,
 notmuch_message_t *message,
 unused (int indent));
 static void
@@ -124,7 +146,30 @@ _get_one_line_summary (const void *ctx, notmuch_message_t 
*message)
 }

 static void
-format_message_text (unused (const void *ctx), notmuch_message_t *message, int 
indent)
+format_message_tabular (unused (const void *ctx), show_mask_t show_mask,
+   notmuch_message_t *message, 
+   unused(int indent))
+{
+int count=0;
+
+if (show_mask & SHOW_MESSAGE_ID) {
+   fputs ( notmuch_message_get_message_id (message), stdout);
+   count++;
+}
+
+if (show_mask & SHOW_MATCH) 
+   printf ("%s%d", count++ ? "\t" : "", 
+   notmuch_message_get_flag (message, 
+ NOTMUCH_MESSAGE_FLAG_MATCH));
+
+if (show_mask & SHOW_FILENAME) 
+   printf("%s%s", count++ ? "\t" : "", 
+  notmuch_message_get_filename (message));
+}
+
+static void
+format_message_text (unused (const void *ctx), unused(show_mask_t show_mask),
+notmuch_message_t *message, int indent)
 {
 printf ("id:%s depth:%d match:%d filename:%s\n",
notmuch_message_get_message_id (message),
@@ -134,7 +179,8 @@ format_message_text (unused (const void *ctx), 
notmuch_message_t *message, int i
 }

 static void
-format_message_json (const void *ctx, notmuch_message_t *message, unused (int 
indent))
+format_message_json (const void *ctx, unused(show_mask_t show_mask),
+notmuch_message_t *message, unused (int indent))
 {
 void *ctx_quote = talloc_new (ctx);

@@ -323,11 +369,12 @@ format_part_json (GMimeObject *part, int *part_count)
 }

 static void
-show_message (void *ctx, const show_format_t *format, notmuch_message_t 
*message, int indent)
+show_message (void *ctx, const show_format_t *format, show_mask_t show_mask,
+ notmuch_message_t *message, int indent)
 {
 fputs (format->message_start, stdout);
 if (format->message)
-   format->message(ctx, message, indent);
+   format->message(ctx, show_mask, message, indent);

 fputs (format->header_start, stdout);
 if (format->header) 
@@ -344,8 +391,8 @@ show_message (void *ctx, const show_format_t *format, 
notmuch_message_t *message


 static void
-show_messages (void *ctx, const show_format_t *format, notmuch_messages_t 
*messages, int indent,
-  notmuch_bool_t entire_thread)
+show_messages (void *ctx, const show_format_t *format,  show_mask_t show_mask, 
+  notmuch_messages_t *messages, int indent, notmuch_bool_t 
entire_thread)
 {
 notmuch_message_t *message;
 notmuch_bool_t match;
@@ -371,13 +418,14 @@ show_messages (void *ctx, const show_format_t *format, 
notmuch_messages_t *messa
next_indent = indent;

if 

[notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output format, with output control

2009-12-19 Thread david
From: David Bremner brem...@unb.ca

Currently this only outputs the information from the message header;
i.e. the part before the rfc2822 header or body.

Adding this required adding an extra parameter, currently unused, to
format_message_text and format_message_json. Also the struct
definition is changed to match the new function prototypes.

An int (enum) is used as a mask, each bit corresponds to some part to
be shown or not shown.  This enum will need to be extended as more
things are controllable via --show.
---
 notmuch-show.c |   89 ---
 1 files changed, 77 insertions(+), 12 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 51aa87d..99a4d3c 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -20,10 +20,18 @@
 
 #include notmuch-client.h
 
+/* These should be powers of 2 */
+typedef enum {SHOW_MESSAGE_ID = 1, 
+ SHOW_MATCH = 2, 
+ SHOW_FILENAME = 4
+} show_mask_t;
+
+static const show_mask_t SHOW_ALL = ~0;
+
 typedef struct show_format {
 const char *message_set_start;
 const char *message_start;
-void (*message) (const void *ctx,
+void (*message) (const void *ctx, show_mask_t show_mask,
 notmuch_message_t *message,
 int indent);
 const char *header_start;
@@ -40,7 +48,7 @@ typedef struct show_format {
 } show_format_t;
 
 static void
-format_message_text (unused (const void *ctx),
+format_message_text (unused (const void *ctx), show_mask_t show_mask,
 notmuch_message_t *message,
 int indent);
 static void
@@ -59,7 +67,21 @@ static const show_format_t format_text = {
 };
 
 static void
-format_message_json (const void *ctx,
+format_message_tabular (unused (const void *ctx), show_mask_t show_mask,
+notmuch_message_t *message,
+int indent);
+
+static const show_format_t format_tabular = {
+, 
+, format_message_tabular, 
+, NULL, , 
+, NULL, ,
+\n, , 
+
+};
+
+static void
+format_message_json (const void *ctx, show_mask_t show_mask,
 notmuch_message_t *message,
 unused (int indent));
 static void
@@ -124,7 +146,30 @@ _get_one_line_summary (const void *ctx, notmuch_message_t 
*message)
 }
 
 static void
-format_message_text (unused (const void *ctx), notmuch_message_t *message, int 
indent)
+format_message_tabular (unused (const void *ctx), show_mask_t show_mask,
+   notmuch_message_t *message, 
+   unused(int indent))
+{
+int count=0;
+
+if (show_mask  SHOW_MESSAGE_ID) {
+   fputs ( notmuch_message_get_message_id (message), stdout);
+   count++;
+}
+
+if (show_mask  SHOW_MATCH) 
+   printf (%s%d, count++ ? \t : , 
+   notmuch_message_get_flag (message, 
+ NOTMUCH_MESSAGE_FLAG_MATCH));
+
+if (show_mask  SHOW_FILENAME) 
+   printf(%s%s, count++ ? \t : , 
+  notmuch_message_get_filename (message));
+}
+
+static void
+format_message_text (unused (const void *ctx), unused(show_mask_t show_mask),
+notmuch_message_t *message, int indent)
 {
 printf (id:%s depth:%d match:%d filename:%s\n,
notmuch_message_get_message_id (message),
@@ -134,7 +179,8 @@ format_message_text (unused (const void *ctx), 
notmuch_message_t *message, int i
 }
 
 static void
-format_message_json (const void *ctx, notmuch_message_t *message, unused (int 
indent))
+format_message_json (const void *ctx, unused(show_mask_t show_mask),
+notmuch_message_t *message, unused (int indent))
 {
 void *ctx_quote = talloc_new (ctx);
 
@@ -323,11 +369,12 @@ format_part_json (GMimeObject *part, int *part_count)
 }
 
 static void
-show_message (void *ctx, const show_format_t *format, notmuch_message_t 
*message, int indent)
+show_message (void *ctx, const show_format_t *format, show_mask_t show_mask,
+ notmuch_message_t *message, int indent)
 {
 fputs (format-message_start, stdout);
 if (format-message)
-   format-message(ctx, message, indent);
+   format-message(ctx, show_mask, message, indent);
 
 fputs (format-header_start, stdout);
 if (format-header) 
@@ -344,8 +391,8 @@ show_message (void *ctx, const show_format_t *format, 
notmuch_message_t *message
 
 
 static void
-show_messages (void *ctx, const show_format_t *format, notmuch_messages_t 
*messages, int indent,
-  notmuch_bool_t entire_thread)
+show_messages (void *ctx, const show_format_t *format,  show_mask_t show_mask, 
+  notmuch_messages_t *messages, int indent, notmuch_bool_t 
entire_thread)
 {
 notmuch_message_t *message;
 notmuch_bool_t match;
@@ -371,13 +418,14 @@ show_messages (void *ctx, const show_format_t *format, 
notmuch_messages_t *messa
next_indent = indent;
 
if (match || entire_thread) {
-