NeoMutt  2024-04-25-91-gb0e085
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node_container.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include <stddef.h>
33#include "mutt/lib.h"
34#include "node_container.h"
35#include "format.h"
36#include "helpers.h"
37#include "node.h"
38#include "render.h"
39
43int node_container_render(const struct ExpandoNode *node,
44 const struct ExpandoRenderData *rdata, struct Buffer *buf,
45 int max_cols, void *data, MuttFormatFlags flags)
46{
47 ASSERT(node->type == ENT_CONTAINER);
48
49 const struct ExpandoFormat *fmt = node->format;
50 if (fmt)
52
53 int total_cols = 0;
54
55 struct Buffer *tmp = buf_pool_get();
56 struct ExpandoNode **enp = NULL;
57 ARRAY_FOREACH(enp, &node->children)
58 {
59 total_cols += node_render(*enp, rdata, tmp, max_cols - total_cols, data, flags);
60 }
61
62 if (fmt)
63 {
64 int min_cols = MIN(fmt->min_cols, max_cols);
65 struct Buffer *tmp2 = buf_pool_get();
66 total_cols = format_string(tmp2, min_cols, max_cols, fmt->justification,
67 fmt->leader, buf_string(tmp), buf_len(tmp), true);
68 if (fmt->lower)
70 buf_addstr(buf, buf_string(tmp2));
71 buf_pool_release(&tmp2);
72 }
73 else
74 {
75 buf_addstr(buf, buf_string(tmp));
76 }
77
78 buf_pool_release(&tmp);
79 return total_cols;
80}
81
87{
88 struct ExpandoNode *node = node_new();
89
90 node->type = ENT_CONTAINER;
92
93 return node;
94}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:491
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:226
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
void buf_lower_special(struct Buffer *buf)
Convert to lowercase, excluding special characters.
Definition: helpers.c:176
Shared code.
int format_string(struct Buffer *buf, int min_cols, int max_cols, enum FormatJustify justify, char pad_char, const char *str, size_t n, bool arboreal)
Format a string, like snprintf()
Definition: format.c:108
Simple string formatting.
int node_container_render(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Callback for a Container Node - Implements ExpandoNode::render() -.
#define MIN(a, b)
Definition: memory.h:32
Convenience wrapper for the library headers.
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
Definition: node.c:39
Basic Expando Node.
@ ENT_CONTAINER
Container for other nodes.
Definition: node.h:44
struct ExpandoNode * node_container_new(void)
Create a new Container ExpandoNode.
Expando Node for a Container.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
int node_render(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render a tree of ExpandoNodes into a string.
Definition: render.c:45
Render Expandos using Data.
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
#define ASSERT(COND)
Definition: signal2.h:58
String manipulation buffer.
Definition: buffer.h:36
Formatting information for an Expando.
Definition: node.h:53
char leader
Leader character, 0 or space.
Definition: node.h:57
enum FormatJustify justification
Justification: left, centre, right.
Definition: node.h:56
int min_cols
Minimum number of screen columns.
Definition: node.h:54
int max_cols
Maximum number of screen columns.
Definition: node.h:55
bool lower
Display in lower case.
Definition: node.h:58
Basic Expando Node.
Definition: node.h:69
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:96
struct ExpandoFormat * format
Formatting info.
Definition: node.h:75
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:70
struct ExpandoNodeArray children
Children nodes.
Definition: node.h:77