Use two lines to show topic diffs

weechat-hashes
June McEnroe 2022-06-24 14:29:44 -04:00
parent 3475f03ec8
commit b744089d6a
1 changed files with 45 additions and 24 deletions

View File

@ -676,6 +676,28 @@ static void swap(wchar_t *a, wchar_t *b) {
*b = x; *b = x;
} }
static char *highlightMiddle(
char *ptr, char *end, enum Color color,
wchar_t *str, size_t pre, size_t suf
) {
wchar_t nul = L'\0';
swap(&str[pre], &nul);
ptr = seprintf(ptr, end, "%ls", str);
swap(&str[pre], &nul);
swap(&str[suf], &nul);
if (hashBound) {
ptr = seprintf(
ptr, end, "\3%02d,%02d%ls\3%02d,%02d",
Default, color, &str[pre], Default, Default
);
} else {
ptr = seprintf(ptr, end, "\26%ls\26", &str[pre]);
}
swap(&str[suf], &nul);
ptr = seprintf(ptr, end, "%ls", &str[suf]);
return ptr;
}
static void handleTopic(struct Message *msg) { static void handleTopic(struct Message *msg) {
require(msg, true, 2); require(msg, true, 2);
uint id = idFor(msg->params[0]); uint id = idFor(msg->params[0]);
@ -693,8 +715,6 @@ static void handleTopic(struct Message *msg) {
return; return;
} }
char buf[1024];
char *ptr = buf, *end = &buf[sizeof(buf)];
const char *prev = complete(id, "/topic "); const char *prev = complete(id, "/topic ");
completeReject(); completeReject();
if (prev) { if (prev) {
@ -708,45 +728,46 @@ static void handleTopic(struct Message *msg) {
if (swprintf(old, ARRAY_LEN(old), L"%s", prev) < 0) goto plain; if (swprintf(old, ARRAY_LEN(old), L"%s", prev) < 0) goto plain;
if (swprintf(new, ARRAY_LEN(new), L"%s", msg->params[1]) < 0) goto plain; if (swprintf(new, ARRAY_LEN(new), L"%s", msg->params[1]) < 0) goto plain;
if (!hashBound) {
ptr = seprintf(ptr, end, "%c%ls%c -> %c%ls%c", R, old, O, R, new, O);
goto plain;
}
size_t pre; size_t pre;
for (pre = 0; old[pre] && new[pre] && old[pre] == new[pre]; ++pre); for (pre = 0; old[pre] && new[pre] && old[pre] == new[pre]; ++pre);
wchar_t *osuf = &old[wcslen(old)]; size_t osuf = wcslen(old);
wchar_t *nsuf = &new[wcslen(new)]; size_t nsuf = wcslen(new);
while (osuf > &old[pre] && nsuf > &new[pre] && osuf[-1] == nsuf[-1]) { while (osuf > pre && nsuf > pre && old[osuf-1] == new[nsuf-1]) {
osuf--; osuf--;
nsuf--; nsuf--;
} }
wchar_t nul = L'\0'; char buf[1024];
swap(&new[pre], &nul); char *ptr = buf, *end = &buf[sizeof(buf)];
ptr = seprintf(ptr, end, "%ls", new); ptr = seprintf(
swap(&new[pre], &nul); ptr, end, "\3%02d%s\3\ttakes down the sign in \3%02d%s\3: ",
swap(osuf, &nul); hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0]
ptr = seprintf(ptr, end, "\3%02d,%02d%ls", Default, Brown, &old[pre]); );
swap(osuf, &nul); ptr = highlightMiddle(ptr, end, Brown, old, pre, osuf);
swap(nsuf, &nul); uiWrite(id, Cold, tagTime(msg), buf);
ptr = seprintf(ptr, end, "\3%02d,%02d%ls", Default, Green, &new[pre]); ptr = buf;
swap(nsuf, &nul); ptr = seprintf(
ptr = seprintf(ptr, end, "\3%02d,%02d%ls", Default, Default, nsuf); ptr, end, "\3%02d%s\3\tplaces a new sign in \3%02d%s\3: ",
hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0]
);
ptr = highlightMiddle(ptr, end, Green, new, pre, nsuf);
uiWrite(id, Warm, tagTime(msg), buf);
goto log;
plain: plain:
topicComplete(id, msg->params[1]);
urlScan(id, msg->nick, msg->params[1]);
uiFormat( uiFormat(
id, Warm, tagTime(msg), id, Warm, tagTime(msg),
"\3%02d%s\3\tplaces a new sign in \3%02d%s\3: %s", "\3%02d%s\3\tplaces a new sign in \3%02d%s\3: %s",
hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0], hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0],
(ptr > buf ? buf : msg->params[1]) msg->params[1]
); );
log:
logFormat( logFormat(
id, tagTime(msg), "%s places a new sign in %s: %s", id, tagTime(msg), "%s places a new sign in %s: %s",
msg->nick, msg->params[0], msg->params[1] msg->nick, msg->params[0], msg->params[1]
); );
topicComplete(id, msg->params[1]);
urlScan(id, msg->nick, msg->params[1]);
} }
static const char *UserModes[256] = { static const char *UserModes[256] = {