NeoMutt  2025-12-11-276-g10b23b
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 ExpandoRenderCallback *erc, 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 ExpandoRenderCallback *erc, 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 ExpandoRenderCallback *erc, 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 ExpandoRenderCallback *erc, 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 ExpandoRenderCallback *erc, 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 ExpandoRenderCallback *erc, 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 ExpandoRenderCallback *erc, 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 ExpandoRenderCallback *erc, 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 ExpandoRenderCallback *erc, 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
[in]ercExpando Render Callback functions
[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 ExpandoRenderCallback * erc,
struct Buffer * buf,
int max_cols,
void * data,
MuttFormatFlags flags )

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

Definition at line 41 of file node_condbool.c.

44{
45 ASSERT(node->type == ENT_CONDBOOL);
46
47 const struct ExpandoRenderCallback *erc_match = find_get_number(erc, node->did, node->uid);
48 if (erc_match)
49 {
50 const long num = erc_match->get_number(node, data, flags);
51 return (num != 0); // bool-ify
52 }
53
54 erc_match = find_get_string(erc, node->did, node->uid);
55 if (erc_match)
56 {
57 struct Buffer *buf_str = buf_pool_get();
58 erc_match->get_string(node, data, flags, buf_str);
59 const size_t len = buf_len(buf_str);
60 buf_pool_release(&buf_str);
61
62 return (len > 0); // bool-ify
63 }
64
65 return 0;
66}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
const struct ExpandoRenderCallback * find_get_string(const struct ExpandoRenderCallback *erc, int did, int uid)
Find a get_string() callback function.
Definition helpers.c:69
const struct ExpandoRenderCallback * find_get_number(const struct ExpandoRenderCallback *erc, int did, int uid)
Find a get_number() callback function.
Definition helpers.c:45
@ 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:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define ASSERT(COND)
Definition signal2.h:59
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
get_string_t get_string
Callback function to get a string.
Definition render.h:80
get_number_t get_number
Callback function to get a number.
Definition render.h:81
+ 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 ExpandoRenderCallback * erc,
struct Buffer * buf,
int max_cols,
void * data,
MuttFormatFlags flags )

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

Definition at line 169 of file node_conddate.c.

172{
173 ASSERT(node->type == ENT_CONDDATE);
174
175 const struct ExpandoRenderCallback *erc_match = find_get_number(erc, node->did, node->uid);
176 ASSERT(erc_match && "Unknown UID");
177
178 const long t_test = erc_match->get_number(node, data, flags);
179
180 const struct NodeCondDatePrivate *priv = node->ndata;
181
182 time_t t_cutoff;
183 if (priv->count == 0)
184 t_cutoff = cutoff_this(priv->period);
185 else
186 t_cutoff = cutoff_number(priv->period, priv->count);
187
188 return (t_test > t_cutoff); // bool-ify
189}
@ 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.
time_t cutoff_this(char period)
Calculate the cutoff time of this unit.
void * ndata
Private node data.
Definition node.h:77
Private data for a Conditional Date -.
int count
Number of 'units' to count.
char period
Units, e.g. 'd' Day or 'm' Month.
+ 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 ExpandoRenderCallback * erc,
struct Buffer * buf,
int max_cols,
void * data,
MuttFormatFlags flags )
static

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

Definition at line 49 of file node_condition.c.

53{
54 ASSERT(node->type == ENT_CONDITION);
55
56 const struct ExpandoNode *node_cond = node_get_child(node, ENC_CONDITION);
57
58 // Discard any text returned, just use the return value as a bool
59 struct Buffer *buf_cond = buf_pool_get();
60 int rc_cond = node_cond->render(node_cond, erc, buf_cond, max_cols, data, flags);
61
62 int rc = 0;
63 buf_reset(buf_cond);
64
65 if (rc_cond == true)
66 {
67 const struct ExpandoNode *node_true = node_get_child(node, ENC_TRUE);
68 rc = node_render(node_true, erc, buf_cond, max_cols, data, flags);
69 }
70 else
71 {
72 const struct ExpandoNode *node_false = node_get_child(node, ENC_FALSE);
73 rc = node_render(node_false, erc, buf_cond, max_cols, data, flags);
74 }
75
76 const struct ExpandoFormat *fmt = node->format;
77 if (!fmt)
78 {
79 buf_addstr(buf, buf_string(buf_cond));
80 buf_pool_release(&buf_cond);
81 return rc;
82 }
83
84 struct Buffer *tmp = buf_pool_get();
85
86 int min_cols = MAX(fmt->min_cols, fmt->max_cols);
87 min_cols = MIN(min_cols, max_cols);
88 if (fmt->max_cols >= 0)
89 max_cols = MIN(max_cols, fmt->max_cols);
90 rc = format_string(tmp, min_cols, max_cols, fmt->justification, ' ',
91 buf_string(buf_cond), buf_len(buf_cond), true);
92 if (fmt->lower)
94
95 buf_addstr(buf, buf_string(tmp));
96 buf_pool_release(&tmp);
97 buf_pool_release(&buf_cond);
98
99 return rc;
100}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
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:92
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)
Return the minimum of two values.
Definition memory.h:40
#define MAX(a, b)
Return the maximum of two values.
Definition memory.h:38
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 ExpandoRenderCallback *erc, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render a tree of ExpandoNodes into a string.
Definition render.c:45
Formatting information for an Expando.
Definition node.h:53
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:67
struct ExpandoFormat * format
Formatting info.
Definition node.h:72
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderCallback *erc, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition node.h:92
+ 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 ExpandoRenderCallback * erc,
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 && (fmt->max_cols != -1))
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 if (total_cols >= max_cols)
60 break;
61 total_cols += node_render(*enp, erc, tmp, max_cols - total_cols, data, flags);
62 }
63
64 struct Buffer *tmp2 = buf_pool_get();
65 if (fmt)
66 {
67 int max = max_cols;
68 if (fmt->max_cols >= 0)
69 max = MIN(max_cols, fmt->max_cols);
70 int min = MIN(fmt->min_cols, max);
71
72 total_cols = format_string(tmp2, min, max, fmt->justification, ' ',
73 buf_string(tmp), buf_len(tmp), true);
74
75 if (fmt->lower)
77 }
78 else
79 {
80 total_cols = format_string(tmp2, 0, max_cols, JUSTIFY_LEFT, ' ',
81 buf_string(tmp), buf_len(tmp), true);
82 }
83 buf_addstr(buf, buf_string(tmp2));
84 buf_pool_release(&tmp2);
85
86 buf_pool_release(&tmp);
87 return total_cols;
88}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
@ JUSTIFY_LEFT
Left justify the text.
Definition format.h:34
@ ENT_CONTAINER
Container for other nodes.
Definition node.h:44
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 ExpandoRenderCallback * erc,
struct Buffer * buf,
int max_cols,
void * data,
MuttFormatFlags flags )

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

Definition at line 506 of file node_expando.c.

509{
510 ASSERT(node->type == ENT_EXPANDO);
511
512 struct Buffer *buf_expando = buf_pool_get();
513 struct Buffer *buf_format = buf_pool_get();
514
515 const struct ExpandoFormat *fmt = node->format;
516 const struct NodeExpandoPrivate *priv = node->ndata;
517
518 // ---------------------------------------------------------------------------
519 // Numbers and strings get treated slightly differently. We prefer strings.
520 // This allows dates to be stored as 1729850182, but displayed as "2024-10-25".
521
522 const struct ExpandoRenderCallback *erc_match = find_get_string(erc, node->did, node->uid);
523 if (erc_match)
524 {
525 erc_match->get_string(node, data, flags, buf_expando);
526
527 if (fmt && fmt->lower)
528 buf_lower_special(buf_expando);
529 }
530 else
531 {
532 erc_match = find_get_number(erc, node->did, node->uid);
533 ASSERT(erc_match && "Unknown UID");
534
535 const long num = erc_match->get_number(node, data, flags);
536
537 int precision = 1;
538
539 if (fmt)
540 {
541 precision = fmt->max_cols;
542 if ((precision < 0) && (fmt->leader == '0'))
543 precision = fmt->min_cols;
544 }
545
546 if (num < 0)
547 precision--; // Allow space for the '-' sign
548
549 buf_printf(buf_expando, "%.*ld", precision, num);
550 }
551
552 // ---------------------------------------------------------------------------
553
554 int max = max_cols;
555 int min = 0;
556
557 if (fmt)
558 {
559 min = fmt->min_cols;
560 if (fmt->max_cols > 0)
561 max = MIN(max_cols, fmt->max_cols);
562 }
563
564 const enum FormatJustify just = fmt ? fmt->justification : JUSTIFY_LEFT;
565
566 int total_cols = format_string(buf_format, min, max, just, ' ', buf_string(buf_expando),
567 buf_len(buf_expando), priv->has_tree);
568
569 if (!buf_is_empty(buf_format))
570 {
571 if (priv->color > -1)
572 add_color(buf, priv->color);
573
574 buf_addstr(buf, buf_string(buf_format));
575
576 if (priv->color > -1)
578 }
579
580 buf_pool_release(&buf_format);
581 buf_pool_release(&buf_expando);
582
583 return total_cols;
584}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
@ MT_COLOR_INDEX
Index: default colour.
Definition color.h:86
FormatJustify
Alignment for format_string()
Definition format.h:33
@ 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.
char leader
Leader character, 0 or space.
Definition node.h:57
Private data for an Expando -.
int color
ColorId to use.
bool has_tree
Contains tree characters, used in $index_format's s.
+ 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 ExpandoRenderCallback * erc,
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, erc, 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.
@ ENP_LEFT
Index of Left-Hand Nodes.
+ 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 ExpandoRenderCallback * erc,
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, erc, 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, erc, 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.
+ 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 ExpandoRenderCallback * erc,
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, erc, 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, erc, 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 ExpandoRenderCallback * erc,
struct Buffer * buf,
int max_cols,
void * data,
MuttFormatFlags flags )
static

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

Definition at line 42 of file node_text.c.

45{
46 ASSERT(node->type == ENT_TEXT);
47
48 return format_string(buf, 0, max_cols, JUSTIFY_LEFT, ' ', node->text,
49 mutt_str_len(node->text), false);
50}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:500
@ 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: