From ecef8f79564d099c3f8a244acb3530411538ad69 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 8 Nov 2014 21:03:28 +0000 Subject: [PATCH] Print one word at a time --- src/ui/window.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index 857a294c..7bb1e973 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -53,6 +53,7 @@ static void _win_print(ProfWin *window, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message); +static void _win_print_wrapped(WINDOW *win, const char * const message); ProfWin* @@ -579,9 +580,10 @@ _win_print(ProfWin *window, const char show_char, const char * const date_fmt, wattron(window->win, attrs); if (flags & NO_EOL) { - wprintw(window->win, "%s", message+offset); + _win_print_wrapped(window->win, message+offset); } else { - wprintw(window->win, "%s\n", message+offset); + _win_print_wrapped(window->win, message+offset); + wprintw(window->win, "\n"); } wattroff(window->win, attrs); @@ -591,6 +593,30 @@ _win_print(ProfWin *window, const char show_char, const char * const date_fmt, } } +static void +_win_print_wrapped(WINDOW *win, const char * const message) +{ + int linei = 0; + int wordi = 0; + char *word = malloc(strlen(message) + 1); + + while (message[linei] != '\0') { + if (message[linei] == ' ') { + wprintw(win, " "); + linei++; + } else { + wordi = 0; + while (message[linei] != ' ' && message[linei] != '\0') { + word[wordi++] = message[linei++]; + } + word[wordi] = '\0'; + wprintw(win, "%s", word); + } + } + + free(word); +} + void win_redraw(ProfWin *window) {