NeoMutt  2024-04-25-1-g3de005
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 <stddef.h>
32#include <assert.h>
33#include <stdbool.h>
34#include "mutt/lib.h"
35#include "node_container.h"
36#include "format.h"
37#include "helpers.h"
38#include "node.h"
39#include "render.h"
40
44int node_container_render(const struct ExpandoNode *node,
45 const struct ExpandoRenderData *rdata, struct Buffer *buf,
46 int max_cols, void *data, MuttFormatFlags flags)
47{
48 assert(node->type == ENT_CONTAINER);
49
50 const struct ExpandoFormat *fmt = node->format;
51 if (fmt)
53
54 int total_cols = 0;
55
56 struct Buffer *tmp = buf_pool_get();
57 struct ExpandoNode **enp = NULL;
58 ARRAY_FOREACH(enp, &node->children)
59 {
60 total_cols += node_tree_render(*enp, rdata, tmp, max_cols - total_cols, data, flags);
61 }
62
63 if (fmt)
64 {
65 int min_cols = MIN(fmt->min_cols, max_cols);
66 struct Buffer *tmp2 = buf_pool_get();
67 total_cols = format_string(tmp2, min_cols, max_cols, fmt->justification,
68 fmt->leader, buf_string(tmp), buf_len(tmp), true);
69 if (fmt->lower)
71 buf_addstr(buf, buf_string(tmp2));
72 buf_pool_release(&tmp2);
73 }
74 else
75 {
76 buf_addstr(buf, buf_string(tmp));
77 }
78
79 buf_pool_release(&tmp);
80 return total_cols;
81}
82
88{
89 struct ExpandoNode *node = node_new();
90
91 node->type = ENT_CONTAINER;
93
94 return node;
95}
#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:490
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
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:177
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_tree_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
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