mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
show: Associate an sprinter with each format
This associates an sprinter constructor with each show format and uses this to construct the appropriate sprinter. Currently nothing is done with this sprinter, but the following patches will weave it through the layers of notmuch show.
This commit is contained in:
parent
14883b0700
commit
d79b24b98d
2 changed files with 10 additions and 0 deletions
|
@ -69,6 +69,7 @@ typedef struct mime_node mime_node_t;
|
||||||
struct notmuch_show_params;
|
struct notmuch_show_params;
|
||||||
|
|
||||||
typedef struct notmuch_show_format {
|
typedef struct notmuch_show_format {
|
||||||
|
struct sprinter *(*new_sprinter) (const void *ctx, FILE *stream);
|
||||||
const char *message_set_start;
|
const char *message_set_start;
|
||||||
notmuch_status_t (*part) (const void *ctx,
|
notmuch_status_t (*part) (const void *ctx,
|
||||||
struct mime_node *node, int indent,
|
struct mime_node *node, int indent,
|
||||||
|
|
|
@ -20,12 +20,14 @@
|
||||||
|
|
||||||
#include "notmuch-client.h"
|
#include "notmuch-client.h"
|
||||||
#include "gmime-filter-reply.h"
|
#include "gmime-filter-reply.h"
|
||||||
|
#include "sprinter.h"
|
||||||
|
|
||||||
static notmuch_status_t
|
static notmuch_status_t
|
||||||
format_part_text (const void *ctx, mime_node_t *node,
|
format_part_text (const void *ctx, mime_node_t *node,
|
||||||
int indent, const notmuch_show_params_t *params);
|
int indent, const notmuch_show_params_t *params);
|
||||||
|
|
||||||
static const notmuch_show_format_t format_text = {
|
static const notmuch_show_format_t format_text = {
|
||||||
|
.new_sprinter = sprinter_text_create,
|
||||||
.part = format_part_text,
|
.part = format_part_text,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -34,6 +36,7 @@ format_part_json_entry (const void *ctx, mime_node_t *node,
|
||||||
int indent, const notmuch_show_params_t *params);
|
int indent, const notmuch_show_params_t *params);
|
||||||
|
|
||||||
static const notmuch_show_format_t format_json = {
|
static const notmuch_show_format_t format_json = {
|
||||||
|
.new_sprinter = sprinter_json_create,
|
||||||
.message_set_start = "[",
|
.message_set_start = "[",
|
||||||
.part = format_part_json_entry,
|
.part = format_part_json_entry,
|
||||||
.message_set_sep = ", ",
|
.message_set_sep = ", ",
|
||||||
|
@ -46,6 +49,7 @@ format_part_mbox (const void *ctx, mime_node_t *node,
|
||||||
int indent, const notmuch_show_params_t *params);
|
int indent, const notmuch_show_params_t *params);
|
||||||
|
|
||||||
static const notmuch_show_format_t format_mbox = {
|
static const notmuch_show_format_t format_mbox = {
|
||||||
|
.new_sprinter = sprinter_text_create,
|
||||||
.part = format_part_mbox,
|
.part = format_part_mbox,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,6 +59,7 @@ format_part_raw (unused (const void *ctx), mime_node_t *node,
|
||||||
unused (const notmuch_show_params_t *params));
|
unused (const notmuch_show_params_t *params));
|
||||||
|
|
||||||
static const notmuch_show_format_t format_raw = {
|
static const notmuch_show_format_t format_raw = {
|
||||||
|
.new_sprinter = sprinter_text_create,
|
||||||
.part = format_part_raw,
|
.part = format_part_raw,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1003,6 +1008,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
|
||||||
char *query_string;
|
char *query_string;
|
||||||
int opt_index, ret;
|
int opt_index, ret;
|
||||||
const notmuch_show_format_t *format = &format_text;
|
const notmuch_show_format_t *format = &format_text;
|
||||||
|
sprinter_t *sprinter;
|
||||||
notmuch_show_params_t params = {
|
notmuch_show_params_t params = {
|
||||||
.part = -1,
|
.part = -1,
|
||||||
.omit_excluded = TRUE,
|
.omit_excluded = TRUE,
|
||||||
|
@ -1130,6 +1136,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create structure printer. */
|
||||||
|
sprinter = format->new_sprinter(ctx, stdout);
|
||||||
|
|
||||||
/* If a single message is requested we do not use search_excludes. */
|
/* If a single message is requested we do not use search_excludes. */
|
||||||
if (params.part >= 0)
|
if (params.part >= 0)
|
||||||
ret = do_show_single (ctx, query, format, ¶ms);
|
ret = do_show_single (ctx, query, format, ¶ms);
|
||||||
|
|
Loading…
Reference in a new issue