Implement word wrap

This actually wasn't that bad?
weechat-hashes
C. McEnroe 2020-02-01 22:40:55 -05:00
parent cd3dc4ef4c
commit 05256b68fe
2 changed files with 35 additions and 1 deletions

14
chat.c
View File

@ -76,7 +76,19 @@ int main(int argc, char *argv[]) {
ircConfig(insecure, cert, priv);
uiInit();
uiFormat(Network, Cold, NULL, C "3Trave" U "ling" U C "0,3.." C "0,4.");
uiFormat(Network, Cold, NULL, C "3Trave" U "ling" U C "0,3.." C "0,4." R);
uiFormat(
Network, Cold, NULL,
"Jackdaws love my big sphinx of quartz. "
"The quick brown fox jumps over the lazy dog. "
"Jackdaws love my big sphinx of quartz. "
"Jackdaws love my big sphinx of quartz. "
"Jackdaws love my big sphinx of quartz. "
"The quick brown fox jumps over the lazy dog. "
"The quick brown fox jumps over the lazy dog. "
"Jackdaws love my big sphinx of quartz. "
"Jackdaws love my big sphinx of quartz. "
);
uiDraw();
int irc = ircConnect(host, port);

22
ui.c
View File

@ -209,11 +209,33 @@ static void styleParse(struct Style *style, const char **str, size_t *len) {
*len = strcspn(*str, "\2\3\17\26\35\37");
}
static int wordWidth(const char *str) {
size_t len = strcspn(str, " ");
// TODO: wcswidth.
return len;
}
static void styleAdd(WINDOW *win, const char *str) {
int _, x, width;
getmaxyx(win, _, width);
size_t len;
struct Style style = Reset;
while (*str) {
if (*str == ' ') {
const char *word = &str[strspn(str, " ")];
getyx(win, _, x);
if (width - x - 1 < wordWidth(word)) {
waddch(win, '\n');
str = word;
}
}
styleParse(&style, &str, &len);
size_t sp = strspn(str, " ");
sp += strcspn(&str[sp], " ");
if (sp < len) len = sp;
wattr_set(
win,
style.attr | colorAttr(mapColor(style.fg)),