From 05256b68fef9d9b64b01afb60de31f9c47b60ca1 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 1 Feb 2020 22:40:55 -0500 Subject: Implement word wrap This actually wasn't that bad? --- chat.c | 14 +++++++++++++- ui.c | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/chat.c b/chat.c index 75cca62..ceaf1b5 100644 --- a/chat.c +++ b/chat.c @@ -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); diff --git a/ui.c b/ui.c index 83c4bc7..7ce0257 100644 --- a/ui.c +++ b/ui.c @@ -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)), -- cgit 1.4.1 bba5e63e01ae&follow=1'>root/bounce.h (unfollow)
Commit message (Expand)Author
2020-08-25Support the pounce_env rc variableJune McEnroe
2020-08-25Remove deprecated option namesJune McEnroe
2020-08-25Document configuration and data file searchJune McEnroe
2020-08-24Use dataOpen for save fileJune McEnroe
2020-08-24Use configOpen to load localCAJune McEnroe
2020-08-24Use configPath to load client cert/privJune McEnroe
2020-08-24Use configOpen in getopt_configJune McEnroe
2020-08-24Import xdg.c from catgirlJune McEnroe
2020-08-23Replace “RAND_bytes” by “getentropy”Issam E. Maghni
2020-08-16contrib/palaver: Add no message preview flagsJune McEnroe
2020-08-13contrib/palaver: Don't set channel for PMsJune McEnroe
2020-08-13Fix unintended interception of NICK after registrationJune McEnroe
2020-08-12Add Additional Components section to READMEJune McEnroe
2020-08-12Document -L / palaver optionJune McEnroe
2020-08-11contrib/palaver: Document service configurationJune McEnroe
2020-08-11contrib/palaver: Add install target and rc scriptJune McEnroe
2020-08-11contrib/palaver: Implement command and notificationsJune McEnroe