aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-07-02 10:08:29 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2011-07-02 10:08:46 +0200
commitc4246779fff29e10394088a05eadf4b9175ce22c (patch)
tree3df6c39a0ec5c9db9f4e82f03cec9cedf4e32d07 /src
parentc8a745fe2352dcf638801b2eba3e5652763da59b (diff)
downloadcalcurse-c4246779fff29e10394088a05eadf4b9175ce22c.tar.gz
calcurse-c4246779fff29e10394088a05eadf4b9175ce22c.zip
Make display_todo_item() UTF-8 compatible
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r--src/todo.c19
1 files 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)