hirc

IRC client
Log | Files | Refs

commit 90766832afab6e7d8bca5495e310b3248735d3ce
parent 17e6ca757039b36930e5d98ad42535d27931e4f4
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 26 Dec 2021 13:10:51 +0000

hirc.1.header s/ui.c: format padding

Diffstat:
Mhirc.1.header | 2++
Msrc/ui.c | 23+++++++++++++++++++++--
2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/hirc.1.header b/hirc.1.header @@ -51,6 +51,8 @@ Reverse foreground/background. Set/reset underline. .It %{=} Place divider here. If disabled, acts like space. +.It %{pad:n,...} +Pad string to n length. Positive pads to the left, negative to the right. .El Certain variables may also be used in formats: diff --git a/src/ui.c b/src/ui.c @@ -1247,7 +1247,8 @@ ui_format(struct Window *window, char *format, struct History *hist) { static int recursive = 0; struct Nick *nick; size_t rc, pc; - int escape, pn, i; + int escape, i; + long pn; int rhs = 0; int divider = 0; char **params; @@ -1476,7 +1477,25 @@ ui_format(struct Window *window, char *format, struct History *hist) { break; } - /* This bit must come last as it modifies content */ + /* pad: and nick: must come last as it modifies content */ + if (strncmp(content, "pad:", strlen("pad:")) == 0 && strchr(content, ',')) { + pn = strtol(content + strlen("pad:"), NULL, 10); + content = strdup(ui_format_get_content(strchr(format+2+strlen("pad:"), ',') + 1, 1)); + save = strdup(ret); + recursive = 1; + p = strdup(ui_format(NULL, content, hist)); + recursive = 0; + memcpy(ret, save, rc); + snprintf(printformat, sizeof(printformat), "%%%lds", pn); + rc += snprintf(&ret[rc], sizeof(ret) - rc, printformat, p); + format = strchr(format+2+strlen("pad:"), ',') + strlen(content) + 2; + + free(content); + free(save); + free(p); + continue; + } + if (hist && !recursive && strncmp(content, "nick:", strlen("nick:")) == 0) { content = strdup(ui_format_get_content(format+2+strlen("nick:"), 1)); save = strdup(ret); /* save ret, as this will be modified by recursing */