Factor out styleStrip

weechat-hashes
C. McEnroe 2020-10-09 18:45:52 -04:00
parent f7f5acbbe2
commit c48672313b
2 changed files with 12 additions and 8 deletions

9
chat.h
View File

@ -105,6 +105,15 @@ static inline size_t styleParse(struct Style *style, const char **str) {
return strcspn(*str, (const char[]) { B, C, O, R, I, U, '\0' }); return strcspn(*str, (const char[]) { B, C, O, R, I, U, '\0' });
} }
static inline void styleStrip(struct Cat *cat, const char *str) {
struct Style style = StyleDefault;
while (*str) {
size_t len = styleParse(&style, &str);
catf(cat, "%.*s", (int)len, str);
str += len;
}
}
enum { None, Debug, Network, IDCap = 256 }; enum { None, Debug, Network, IDCap = 256 };
extern char *idNames[IDCap]; extern char *idNames[IDCap];
extern enum Color idColors[IDCap]; extern enum Color idColors[IDCap];

11
ui.c
View File

@ -534,16 +534,11 @@ struct Util uiNotifyUtil;
static void notify(uint id, const char *str) { static void notify(uint id, const char *str) {
if (!uiNotifyUtil.argc) return; if (!uiNotifyUtil.argc) return;
char buf[1024] = "";
styleStrip(&(struct Cat) { buf, sizeof(buf), 0 }, str);
struct Util util = uiNotifyUtil; struct Util util = uiNotifyUtil;
utilPush(&util, idNames[id]); utilPush(&util, idNames[id]);
char buf[1024] = "";
struct Cat cat = { buf, sizeof(buf), 0 };
while (*str) {
struct Style style = StyleDefault;
size_t len = styleParse(&style, &str);
catf(&cat, "%.*s", (int)len, str);
str += len;
}
utilPush(&util, buf); utilPush(&util, buf);
pid_t pid = fork(); pid_t pid = fork();