diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-02-25 21:48:39 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-02-26 09:14:40 +0100 |
commit | c34f9aba29b965bf1da7e16da91ebf94ae123e89 (patch) | |
tree | 84fbe45575d63ca93df3f3631af55deb867b5350 /src/day.c | |
parent | 85772d746f7b1123b94ce9556273b4a9df77eeaf (diff) | |
download | calcurse-c34f9aba29b965bf1da7e16da91ebf94ae123e89.zip |
Refactor UTF-8 chopping
Add a function that makes sure a string does not exceed a given display
size. If the string is too long, dots ("...") are appended.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/day.c')
-rw-r--r-- | src/day.c | 25 |
1 files changed, 8 insertions, 17 deletions
@@ -427,7 +427,6 @@ day_display_item(struct day_item *day, WINDOW *win, int incolor, int width, { int ch_recur, ch_note; char buf[width * UTF8_MAXLEN]; - int i; if (width <= 0) return; @@ -437,23 +436,15 @@ day_display_item(struct day_item *day, WINDOW *win, int incolor, int width, ch_recur = (day->type == RECUR_EVNT || day->type == RECUR_APPT) ? '*' : ' '; ch_note = day_item_get_note(day) ? '>' : ' '; - if (incolor == 0) + + strncpy(buf, mesg, width * UTF8_MAXLEN); + buf[sizeof(buf) - 1] = '\0'; + utf8_chop(buf, width - 3); + + if (!incolor) custom_apply_attr(win, ATTR_HIGHEST); - if (utf8_strwidth(mesg) < width) { - mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, mesg); - } else { - for (i = 0; mesg[i] && width > 0; i++) { - if (!UTF8_ISCONT(mesg[i])) - width -= utf8_width(&mesg[i]); - buf[i] = mesg[i]; - } - if (i) - buf[i - 1] = 0; - else - buf[0] = 0; - mvwprintw(win, y, x, " %c%c%s...", ch_recur, ch_note, buf); - } - if (incolor == 0) + mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, buf); + if (!incolor) custom_remove_attr(win, ATTR_HIGHEST); } |