about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-08 21:03:28 +0000
committerJames Booth <boothj5@gmail.com>2014-11-08 21:03:28 +0000
commitecef8f79564d099c3f8a244acb3530411538ad69 (patch)
treedbcbf449144084182d08f0fc599ea319b25aef18 /src/ui
parentf1882439c2767f672b498388391b2a1b1d8d355f (diff)
downloadprofani-tty-ecef8f79564d099c3f8a244acb3530411538ad69.tar.gz
Print one word at a time
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/window.c30
1 files 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)
 {