unibi_format(3)

✨ NAME ✨

unibi_format, unibi_run β€” bestie, we're interpreting a terminfo format string πŸ’…

So this is page unibi_format(3) from the unibilium manual, and it's about turning those cursed-looking format strings into actual output. Let's get into it 🫢


🌸 SYNOPSIS 🌸

#include <unibilium.h>

void unibi_format(
    unibi_var_t var_dyn[26],
    unibi_var_t var_static[26],
    const char *fmt,
    unibi_var_t param[9],
    void (*out)(void *, const char *, size_t),
    void *ctx1,
    void (*pad)(void *, size_t, int, int),
    void *ctx2
);

size_t unibi_run(const char *fmt, unibi_var_t param[9], char *p, size_t n);

πŸ’– DESCRIPTION πŸ’–

unibi_format takes a format string fmt and, like, executes it. Slay. All the output happens through (possibly repeated) calls to out. And in those calls to out, the tea is:

  • the first argument is always ctx1
  • the second argument is a pointer to a chunk of data
  • the third argument is a count saying how big that chunk is, in bytes

Then there's pad, which gets used whenever the format string has "$<...>" padding instructions in it. In the calls to pad:

  • the first argument is always ctx2
  • the second argument is the delay in tenths of milliseconds
  • the third argument is a boolean flag for whether "*" (proportional delay) was specified in the format string
  • the fourth argument is a boolean flag for whether "/" (forced padding) was specified in the format string

So like, a format string of "$<5/>" would translate into "pad(ctx2, 50, 0, 1)". Iconic. ✨

You may pass a null pointer for pad β€” in that case padding instructions are silently skipped. No drama, no crash, they just don't happen.

The values of param are what get used for the format codes %p1 .. %p9. And the values of var_dyn and var_static are what get used for the so-called dynamic/static variables %Pa .. %Pz and %PA .. %PZ, respectively. Yes bestie, lowercase and uppercase are two whole separate vibes 😌


πŸ¦‹ unibi_run β€” the wrapper πŸ¦‹

unibi_run</purl> is a wrapper around unibi_format. Here's what it does:

  • it passes two arrays (each initialized to 26 zeroes) as var_dyn and var_static
  • fmt and param get passed on unchanged
  • it ignores padding
  • it places all normal output in the buffer pointed to by p
  • n is the size of that buffer, so at most n bytes will be written to p

πŸŽ€ RETURN VALUE πŸŽ€

unibi_run returns the number of bytes that would have been written if the buffer was big enough. So the number of valid bytes sitting in p after a call to unibi_run is the minimum of n and the return value of unibi_run. That's the whole trick, fr fr πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘


Okay that's the whole page, bestie, you ate that πŸ“ This was unibilium-2.1.4, dated 2026-09-07 β€” go forth and interpret those format strings, main character energy only πŸ’œπŸ¦‹

πŸ“¦ where this page comes from