NeoMutt  2024-10-02-34-g9dd811
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Expando Render API

Render an Expando. More...

Functions

int node_condbool_render (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Callback for every bool node - Implements ExpandoNode::render() -.
 
int node_conddate_render (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render a CondDate Node - Implements ExpandoNode::render() -.
 
static int node_condition_render (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render a Conditional Node - Implements ExpandoNode::render() -.
 
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() -.
 
int node_expando_render (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render an Expando Node - Implements ExpandoNode::render() -.
 
int node_padding_render_eol (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render End-of-Line Padding - Implements ExpandoNode::render() -.
 
int node_padding_render_hard (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render Hard Padding - Implements ExpandoNode::render() -.
 
int node_padding_render_soft (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render Soft Padding - Implements ExpandoNode::render() -.
 
static int node_text_render (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render a Text Node - Implements ExpandoNode::render() -.
 

Detailed Description

Render an Expando.

Parameters
[in]nodeNode to render
[out]bufBuffer in which to save string
[in]max_colsMaximum number of screen columns to use
[in]dataPrivate data
[in]flagsFlags, see MuttFormatFlags
Return values
numNumber of screen columns used

Function Documentation

◆ node_condbool_render()

int node_condbool_render ( const struct ExpandoNode node,
const struct ExpandoRenderData rdata,
struct Buffer buf,
int  max_cols,
void *  data,
MuttFormatFlags  flags 
)

Callback for every bool node - Implements ExpandoNode::render() -.

Definition at line 104 of file node_condbool.c.

107{
108 ASSERT(node->type == ENT_CONDBOOL);
109
110 const struct ExpandoRenderData *rd_match = find_get_number(rdata, node->did, node->uid);
111 if (rd_match)
112 {
113 const long num = rd_match->get_number(node, data, flags);
114 return (num != 0); // bool-ify
115 }
116
117 rd_match = find_get_string(rdata, node->did, node->uid);
118 if (rd_match)
119 {
120 struct Buffer *buf_str = buf_pool_get();
121 rd_match->get_string(node, data, flags, buf_str);
122 const size_t len = buf_len(buf_str);
123 buf_pool_release(&buf_str);
124
125 return (len > 0); // bool-ify
126 }
127
128 return 0;
129}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:491
const struct ExpandoRenderData * find_get_number(const struct ExpandoRenderData *rdata, int did, int uid)
Find a get_number() callback function.
Definition: helpers.c:47
const struct ExpandoRenderData * find_get_string(const struct ExpandoRenderData *rdata, int did, int uid)
Find a get_string() callback function.
Definition: helpers.c:71
@ ENT_CONDBOOL
True/False boolean condition.
Definition: node.h:42
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
#define ASSERT(COND)
Definition: signal2.h:58
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
int uid
Unique ID, e.g. ED_EMA_SIZE.
Definition: node.h:70
int did
Domain ID, e.g. ED_EMAIL.
Definition: node.h:69
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:68
long(* get_number)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Definition: render.h:78
void(* get_string)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Definition: render.h:64
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_conddate_render()

int node_conddate_render ( const struct ExpandoNode node,
const struct ExpandoRenderData rdata,
struct Buffer buf,
int  max_cols,
void *  data,
MuttFormatFlags  flags 
)

Render a CondDate Node - Implements ExpandoNode::render() -.

Definition at line 161 of file node_conddate.c.

164{
165 ASSERT(node->type == ENT_CONDDATE);
166
167 const struct ExpandoRenderData *rd_match = find_get_number(rdata, node->did, node->uid);
168 ASSERT(rd_match && "Unknown UID");
169
170 const long t_test = rd_match->get_number(node, data, flags);
171
172 const struct NodeCondDatePrivate *priv = node->ndata;
173
174 time_t t_cutoff;
175 if (priv->count == 0)
176 t_cutoff = cutoff_this(priv->period);
177 else
178 t_cutoff = cutoff_number(priv->period, priv->count);
179
180 return (t_test > t_cutoff); // bool-ify
181}
@ ENT_CONDDATE
True/False date condition.
Definition: node.h:43
time_t cutoff_number(char period, int count)
Calculate the cutoff time for n units.
Definition: node_conddate.c:79
time_t cutoff_this(char period)
Calculcate the cutoff time of this unit.
void * ndata
Private node data.
Definition: node.h:77
Private data for a Conditional Date -.
Definition: node_conddate.h:33
int count
Number of 'units' to count.
Definition: node_conddate.h:34
char period
Units, e.g. 'd' Day or 'm' Month.
Definition: node_conddate.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_condition_render()

static int node_condition_render ( const struct ExpandoNode node,
const struct ExpandoRenderData rdata,
struct Buffer buf,
int  max_cols,
void *  data,
MuttFormatFlags  flags 
)
static

Render a Conditional Node - Implements ExpandoNode::render() -.

Definition at line 40 of file node_condition.c.

43{
44 ASSERT(node->type == ENT_CONDITION);
45
46 const struct ExpandoNode *node_cond = node_get_child(node, ENC_CONDITION);
47
48 // Discard any text returned, just use the return value as a bool
49 struct Buffer *buf_cond = buf_pool_get();
50 int rc = node_cond->render(node_cond, rdata, buf_cond, max_cols, data, flags);
51 buf_pool_release(&buf_cond);
52
53 if (rc == true)
54 {
55 const struct ExpandoNode *node_true = node_get_child(node, ENC_TRUE);
56 return node_render(node_true, rdata, buf, max_cols, data, flags);
57 }
58 else
59 {
60 const struct ExpandoNode *node_false = node_get_child(node, ENC_FALSE);
61 return node_render(node_false, rdata, buf, max_cols, data, flags);
62 }
63}
struct ExpandoNode * node_get_child(const struct ExpandoNode *node, int index)
Get a child of an ExpandoNode.
Definition: node.c:91
@ ENT_CONDITION
True/False condition.
Definition: node.h:41
@ ENC_CONDITION
Index of Condition Node.
@ ENC_FALSE
Index of False Node.
@ ENC_TRUE
Index of True Node.
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
Basic Expando Node.
Definition: node.h:67
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_container_render()

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() -.

Definition at line 43 of file node_container.c.

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}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
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
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
#define MIN(a, b)
Definition: memory.h:32
@ ENT_CONTAINER
Container for other nodes.
Definition: node.h:44
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
struct ExpandoFormat * format
Formatting info.
Definition: node.h:72
struct ExpandoNodeArray children
Children nodes.
Definition: node.h:75
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_expando_render()

int node_expando_render ( const struct ExpandoNode node,
const struct ExpandoRenderData rdata,
struct Buffer buf,
int  max_cols,
void *  data,
MuttFormatFlags  flags 
)

Render an Expando Node - Implements ExpandoNode::render() -.

Definition at line 336 of file node_expando.c.

339{
340 ASSERT(node->type == ENT_EXPANDO);
341
342 struct Buffer *buf_expando = buf_pool_get();
343
344 const struct ExpandoRenderData *rd_match = find_get_string(rdata, node->did, node->uid);
345 if (rd_match)
346 {
347 rd_match->get_string(node, data, flags, buf_expando);
348 }
349 else
350 {
351 rd_match = find_get_number(rdata, node->did, node->uid);
352 ASSERT(rd_match && "Unknown UID");
353
354 const long num = rd_match->get_number(node, data, flags);
355 buf_printf(buf_expando, "%ld", num);
356 }
357
358 int total_cols = 0;
359
360 const struct NodeExpandoPrivate *priv = node->ndata;
361
362 if (priv->color > -1)
363 add_color(buf, priv->color);
364
365 struct Buffer *tmp = buf_pool_get();
366 const struct ExpandoFormat *fmt = node->format;
367 if (fmt)
368 {
369 max_cols = MIN(max_cols, fmt->max_cols);
370 int min_cols = MIN(max_cols, fmt->min_cols);
371 total_cols += format_string(tmp, min_cols, max_cols, fmt->justification,
372 fmt->leader, buf_string(buf_expando),
373 buf_len(buf_expando), priv->has_tree);
374 if (fmt->lower)
376 }
377 else
378 {
379 total_cols += format_string(tmp, 0, max_cols, JUSTIFY_LEFT, 0, buf_string(buf_expando),
380 buf_len(buf_expando), priv->has_tree);
381 }
382 buf_addstr(buf, buf_string(tmp));
383 buf_pool_release(&tmp);
384
385 if (priv->color > -1)
387
388 buf_pool_release(&buf_expando);
389 return total_cols;
390}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
@ MT_COLOR_INDEX
Index: default colour.
Definition: color.h:83
@ JUSTIFY_LEFT
Left justify the text.
Definition: format.h:34
@ ENT_EXPANDO
Expando, e.g. 'n'.
Definition: node.h:39
void add_color(struct Buffer *buf, enum ColorId cid)
Add a colour code to a buffer.
Definition: node_expando.c:325
Private data for an Expando -.
Definition: node_expando.h:40
int color
ColorId to use.
Definition: node_expando.h:41
bool has_tree
Contains tree characters, used in $index_format's s.
Definition: node_expando.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_padding_render_eol()

int node_padding_render_eol ( const struct ExpandoNode node,
const struct ExpandoRenderData rdata,
struct Buffer buf,
int  max_cols,
void *  data,
MuttFormatFlags  flags 
)

Render End-of-Line Padding - Implements ExpandoNode::render() -.

Definition at line 105 of file node_padding.c.

108{
109 struct ExpandoNode *left = node_get_child(node, ENP_LEFT);
110
111 int total_cols = node_render(left, rdata, buf, max_cols, data, flags);
112
113 total_cols += pad_string(node, buf, max_cols - total_cols);
114
115 return total_cols;
116}
int pad_string(const struct ExpandoNode *node, struct Buffer *buf, int max_cols)
Pad a buffer with a character.
Definition: node_padding.c:76
@ ENP_LEFT
Index of Left-Hand Nodes.
Definition: node_padding.h:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_padding_render_hard()

int node_padding_render_hard ( const struct ExpandoNode node,
const struct ExpandoRenderData rdata,
struct Buffer buf,
int  max_cols,
void *  data,
MuttFormatFlags  flags 
)

Render Hard Padding - Implements ExpandoNode::render() -.

Text to the left of the padding is hard and will be preserved if possible. Text to the right of the padding will be truncated.

Definition at line 124 of file node_padding.c.

127{
128 struct Buffer *buf_left = buf_pool_get();
129 struct Buffer *buf_pad = buf_pool_get();
130 struct Buffer *buf_right = buf_pool_get();
131
132 int cols_used = 0;
133
134 struct ExpandoNode *left = node_get_child(node, ENP_LEFT);
135 if (left)
136 cols_used += node_render(left, rdata, buf_left, max_cols - cols_used, data, flags);
137
138 struct ExpandoNode *right = node_get_child(node, ENP_RIGHT);
139 if (right)
140 cols_used += node_render(right, rdata, buf_right, max_cols - cols_used, data, flags);
141
142 if (max_cols > cols_used)
143 cols_used += pad_string(node, buf_pad, max_cols - cols_used);
144
145 buf_addstr(buf, buf_string(buf_left));
146 buf_addstr(buf, buf_string(buf_pad));
147 buf_addstr(buf, buf_string(buf_right));
148
149 buf_pool_release(&buf_left);
150 buf_pool_release(&buf_pad);
151 buf_pool_release(&buf_right);
152
153 return cols_used;
154}
@ ENP_RIGHT
Index of Right-Hand Nodes.
Definition: node_padding.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_padding_render_soft()

int node_padding_render_soft ( const struct ExpandoNode node,
const struct ExpandoRenderData rdata,
struct Buffer buf,
int  max_cols,
void *  data,
MuttFormatFlags  flags 
)

Render Soft Padding - Implements ExpandoNode::render() -.

Text to the right of the padding is hard and will be preserved if possible. Text to the left of the padding will be truncated.

Definition at line 162 of file node_padding.c.

165{
166 struct Buffer *buf_left = buf_pool_get();
167 struct Buffer *buf_pad = buf_pool_get();
168 struct Buffer *buf_right = buf_pool_get();
169
170 int cols_used = 0;
171
172 struct ExpandoNode *right = node_get_child(node, ENP_RIGHT);
173 if (right)
174 cols_used += node_render(right, rdata, buf_right, max_cols - cols_used, data, flags);
175
176 struct ExpandoNode *left = node_get_child(node, ENP_LEFT);
177 if (left)
178 cols_used += node_render(left, rdata, buf_left, max_cols - cols_used, data, flags);
179
180 if (max_cols > cols_used)
181 cols_used += pad_string(node, buf_pad, max_cols - cols_used);
182
183 buf_addstr(buf, buf_string(buf_left));
184 buf_addstr(buf, buf_string(buf_pad));
185 buf_addstr(buf, buf_string(buf_right));
186
187 buf_pool_release(&buf_left);
188 buf_pool_release(&buf_pad);
189 buf_pool_release(&buf_right);
190
191 return cols_used;
192}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_text_render()

static int node_text_render ( const struct ExpandoNode node,
const struct ExpandoRenderData rdata,
struct Buffer buf,
int  max_cols,
void *  data,
MuttFormatFlags  flags 
)
static

Render a Text Node - Implements ExpandoNode::render() -.

Definition at line 41 of file node_text.c.

44{
45 ASSERT(node->type == ENT_TEXT);
46
47 return format_string(buf, 0, max_cols, JUSTIFY_LEFT, ' ', node->text,
48 mutt_str_len(node->text), false);
49}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
@ ENT_TEXT
Plain text.
Definition: node.h:38
const char * text
Node-specific text.
Definition: node.h:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function: