commit d190ffb38adc34e7b3ae015d7f2fcdf72a1effc2
parent 0b22f44b7096d02d6dab155628173a8fbd893e2f
Author: hhvn <dev@hhvn.uk>
Date: Thu, 2 Dec 2021 00:47:30 +0000
config.c hirc.1.header ui.c: nicks colourised
Diffstat:
3 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/config.c b/config.c
@@ -223,27 +223,27 @@ struct Config config[] = {
"Format of SELF_TLSNOTCOMPILED messages", NULL}},
#endif /* TLS */
{"format.privmsg", 1, Val_string,
- .str = "${nick}%{=}${2}",
+ .str = "%{nick:${nick}}${nick}%{o}%{=}${2}",
.strhandle = config_redraws,
.description = {
"Format of messages", NULL}},
{"format.join", 1, Val_string,
- .str = "%{b}%{c:44}+%{o}%{=}${nick} (${ident}@${host})",
+ .str = "%{b}%{c:44}+%{o}%{=}%{nick:${nick}}${nick}%{o} (${ident}@${host})",
.strhandle = config_redraws,
.description = {
"Format of JOIN messages", NULL}},
{"format.quit", 1, Val_string,
- .str = "%{b}%{c:40}<%{o}%{=}${nick} (${ident}@${host}): ${1}",
+ .str = "%{b}%{c:40}<%{o}%{=}%{nick:${nick}}${nick}%{o} (${ident}@${host}): ${1}",
.strhandle = config_redraws,
.description = {
"Format of QUIT messages", NULL}},
{"format.part", 1, Val_string,
- .str = "%{b}%{c:40}-%{o}%{=}${nick} (${ident}@${host}): ${2}",
+ .str = "%{b}%{c:40}-%{o}%{=}%{nick:${nick}}${nick}%{o} (${ident}@${host}): ${2}",
.strhandle = config_redraws,
.description = {
"Format of PART messages", NULL}},
{"format.kick", 1, Val_string,
- .str = "%{b}%{c:40}!%{o}%{=}${2} by ${nick} (${ident}@${host}): ${3}",
+ .str = "%{b}%{c:40}!%{o}%{=}%{nick:${2}}${2}${o} by %{nick:${nick}}${nick}%{o} (${ident}@${host}): ${3}",
.strhandle = config_redraws,
.description = {
"Format of PART messages", NULL}},
diff --git a/hirc.1.header b/hirc.1.header
@@ -38,6 +38,9 @@ Set/reset boldness.
.It %{c:fg[,bg]}
Set foreground/background colours.
Background optional.
+.It %{nick:...}
+Set foreground colour to colourised version of text in ellipsis.
+Ellipsis may contain a variable.
.It %{i}
Set/reset italics.
.It %{o}
diff --git a/ui.c b/ui.c
@@ -830,11 +830,12 @@ char *
ui_format(char *format, struct History *hist) {
static char ret[8192];
static int nots = 0;
+ struct Nick *nick;
int rc, escape, pn, i;
int rhs = 0;
int divider = 0;
char **params;
- char *tmp, *p, *ts;
+ char *tmp, *p, *ts, *save;
char colourbuf[2][3];
char printformat[64];
enum {
@@ -1028,9 +1029,9 @@ ui_format(char *format, struct History *hist) {
snprintf(printformat, sizeof(printformat), "%%%lds%%s",
config_getl("divider.margin") + (strlen(ret) - ui_strlenc(NULL, ret, NULL)));
/* Save ret for use in snprintf */
- tmp = strdup(ret);
- rc = snprintf(ret, sizeof(ret), printformat, tmp, config_gets("divider.string"));
- free(tmp);
+ save = strdup(ret);
+ rc = snprintf(ret, sizeof(ret), printformat, save, config_gets("divider.string"));
+ free(save);
format = strchr(format, '}') + 1;
continue;
} else if (*(tmp+1) == '\0') {
@@ -1040,6 +1041,27 @@ ui_format(char *format, struct History *hist) {
}
break;
}
+
+ /* This bit must come last as it modified tmp */
+ if (hist && !nots && strncmp(tmp, "nick:", strlen("nick:")) == 0) {
+ p = struntil(format+2+strlen("nick:"), '}');
+ tmp = malloc(strlen(p) + 2);
+ snprintf(tmp, strlen(p) + 2, "%s}", p);
+ save = strdup(ret);
+ nots = 1;
+ p = strdup(ui_format(tmp, hist));
+ nots = 0;
+ memcpy(ret, save, rc); /* don't need strlcpy as we don't use null byte */
+ nick = nick_create(p, ' ', hist->origin ? hist->origin->server : NULL);
+ rc += snprintf(&ret[rc], sizeof(ret) - rc, "%c%02d", 3 /* ^C */, nick_getcolour(nick));
+ format = strchr(format, '}') + 2;
+
+ nick_free(nick);
+ free(tmp);
+ free(p);
+ free(save);
+ continue;
+ }
}
if (escape) {
@@ -1058,14 +1080,14 @@ ui_format(char *format, struct History *hist) {
ret[rc] = '\0';
if (!nots && divider && !rhs) {
snprintf(printformat, sizeof(printformat), "%%%lds%%s%%s", config_getl("divider.margin"));
- tmp = strdup(ret);
- rc = snprintf(ret, sizeof(ret), printformat, "", config_gets("divider.string"), tmp);
- free(tmp);
+ save = strdup(ret);
+ rc = snprintf(ret, sizeof(ret), printformat, "", config_gets("divider.string"), save);
+ free(save);
}
- tmp = strdup(ret);
- rc = snprintf(ret, sizeof(ret), "%s%s", ts, tmp);
- free(tmp);
+ save = strdup(ret);
+ rc = snprintf(ret, sizeof(ret), "%s%s", ts, save);
+ free(save);
if (ts[0] != '\0')
free(ts);