hirc

IRC client
Log | Files | Refs

commit 384a29cd44cd57010923cae8f9a932fcf45a475c
parent 868961a9a721eeb6d9450a4041301a1eff9d640f
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 28 Nov 2021 23:33:38 +0000

config.c ui.c hirc.1.header: implement divider

Diffstat:
Mconfig.c | 26++++++++++++++++++++++++--
Mhirc.1.header | 6++++++
Mui.c | 32++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/config.c b/config.c @@ -14,6 +14,7 @@ static int config_buflist_location(long num); static int config_buflist_width(long num); static int config_nickcolour_self(long num); static int config_nickcolour_range(long a, long b); +static int config_divider(long num); static int config_format(char *str); char *valname[] = { @@ -147,13 +148,28 @@ struct Config config[] = { .strhandle = NULL, .description = { "Message to send on /part", NULL}}, + {"divider.toggle", 1, Val_bool, + .num = 1, + .numhandle = config_divider, + .description = { + "Turn divider on/off", NULL}}, + {"divider.margin", 1, Val_nzunsigned, + .num = 15, + .numhandle = config_divider, + .description = { + "Number of columns on the left of the divider", NULL}}, + {"divider.string", 1, Val_string, + .str = " ", + .strhandle = config_format, + .description = { + "String to be used as divider", NULL}}, {"format.ui.topic", 1, Val_string, .str = "%{c:99,89}${topic}", .strhandle = config_format, .description = { "Format of topic at top of main window", NULL}}, {"format.ui.error", 1, Val_string, - .str = "%{b}%{c:28}${3} %{b}(at ${1}:${2})", + .str = "%{c:28}%{b}${3} %{b}(at ${1}:${2})", .strhandle = config_format, .description = { "Format of SELF_ERROR messages", NULL}}, @@ -195,7 +211,7 @@ struct Config config[] = { "Format of SELF_TLSNOTCOMPILED messages", NULL}}, #endif /* TLS */ {"format.privmsg", 1, Val_string, - .str = "${nick} ${2}", + .str = "${nick}%{=}${2}", .strhandle = config_format, .description = { "Format of messages", NULL}}, @@ -477,3 +493,9 @@ config_format(char *str) { ui_redraw(); return 1; } + +static int +config_divider(long num) { + windows[Win_main].refresh = 1; + return 1; +} diff --git a/hirc.1.header b/hirc.1.header @@ -46,6 +46,8 @@ Reset all stylistic formatting including colour. Reverse foreground/background. .It %{u} Set/reset underline. +.It %{=} +Place divider here. If disabled, acts like space. .El Certain variables may also be used in formats: @@ -93,3 +95,7 @@ hello world If a variable does not exist, it will be printed verbatim. If a variable does exist, but is empty, nothing is printed. +.Ss The divider +The divider is inspired by weechat's feature where it creates a bar seperating two elements of a line. +If divider.toggle is set to 1, the divider will appear in all messages in channels. +The left hand side of the divider will be padded out to the length specified in divider.margin, and divider.string is inserted between the left and right hand side elements. diff --git a/ui.c b/ui.c @@ -797,9 +797,12 @@ char * ui_format(char *format, struct History *hist) { static char ret[8192]; int rc, escape, pn, i; + int rhs = 0; + int divider = 0; char **params; char *tmp, *p; char colourbuf[2][3]; + char printformat[64]; enum { sub_raw, sub_cmd, @@ -837,6 +840,7 @@ ui_format(char *format, struct History *hist) { if (hist->origin) { if (hist->origin->channel) { + divider = config_getl("divider.toggle"); subs[sub_channel].val = hist->origin->channel->name; subs[sub_topic].val = hist->origin->channel->topic; } @@ -948,6 +952,27 @@ ui_format(char *format, struct History *hist) { continue; } break; + case '=': + if (*(tmp+1) == '\0' && divider) { + rhs = 1; + ret[rc] = '\0'; + /* strlen(ret) - ui_strlenc(NULL, ret, NULL) should get + * the length of hidden characters. Add this onto the + * margin to pad out properly. */ + 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); + format = strchr(format, '}') + 1; + continue; + } else if (*(tmp+1) == '\0') { + ret[rc++] = ' '; + format = strchr(format, '}') + 1; + continue; + } + break; } } @@ -965,5 +990,12 @@ ui_format(char *format, struct History *hist) { } ret[rc] = '\0'; + if (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); + } + return ret; }