Commit 6729ae2b authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

vte: Add a VTE_Printf() convenience

parent 6dcbc76f
......@@ -31,4 +31,5 @@ struct vte;
struct vte *VTE_new(int maxfields, int width);
int VTE_cat(struct vte *, const char *);
int VTE_printf(struct vte *, const char *, ...) v_printflike_(2, 3);
void VTE_destroy(struct vte **);
......@@ -32,6 +32,7 @@
#include "config.h"
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h> /* for MUSL (ssize_t) */
......@@ -162,6 +163,30 @@ VTE_cat(struct vte *vte, const char *s)
return (vte_update(vte));
}
int
VTE_printf(struct vte *vte, const char *fmt, ...)
{
va_list ap;
int res;
CHECK_OBJ_NOTNULL(vte, VTE_MAGIC);
AN(fmt);
if (vte->o_sep != 0)
return (-1);
va_start(ap, fmt);
res = VSB_vprintf(vte->vsb, fmt, ap);
va_end(ap);
if (res < 0) {
vte->o_sep = -1;
return (-1);
}
return (vte_update(vte));
}
void
VCLI_VTE(struct cli *cli, struct vsb **src, int width)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment