1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Print one word at a time

This commit is contained in:
James Booth 2014-11-08 21:03:28 +00:00
parent f1882439c2
commit ecef8f7956

View File

@ -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)
{