From c4246779fff29e10394088a05eadf4b9175ce22c Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <calcurse@cryptocrack.de>
Date: Sat, 2 Jul 2011 10:08:29 +0200
Subject: Make display_todo_item() UTF-8 compatible

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
---
 src/todo.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/todo.c b/src/todo.c
index 8000197..43d5ad5 100644
--- a/src/todo.c
+++ b/src/todo.c
@@ -369,12 +369,13 @@ todo_edit_item (void)
 
 /* Display todo items in the corresponding panel. */
 static void
-display_todo_item (int incolor, char *msg, int prio, int note, int len, int y,
+display_todo_item (int incolor, char *msg, int prio, int note, int width, int y,
                    int x)
 {
   WINDOW *w;
   int ch_note;
-  char buf[len], priostr[2];
+  char buf[width * 6], priostr[2];
+  int i;
 
   w = win[TOD].p;
   ch_note = (note) ? '>' : '.';
@@ -385,12 +386,20 @@ display_todo_item (int incolor, char *msg, int prio, int note, int len, int y,
 
   if (incolor == 0)
     custom_apply_attr (w, ATTR_HIGHEST);
-  if (strlen (msg) < len)
+  if (utf8_strwidth (msg) < width)
     mvwprintw (w, y, x, "%s%c %s", priostr, ch_note, msg);
   else
     {
-      (void)strncpy (buf, msg, len - 1);
-      buf[len - 1] = '\0';
+      for (i = 0; msg[i] && width > 0; i++)
+        {
+          if (!UTF8_ISCONT (msg[i]))
+          width -= utf8_width (&msg[i]);
+          buf[i] = msg[i];
+        }
+      if (i)
+        buf[i - 1] = 0;
+      else
+        buf[0] = 0;
       mvwprintw (w, y, x, "%s%c %s...", priostr, ch_note, buf);
     }
   if (incolor == 0)
-- 
cgit v1.2.3-70-g09d2