dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit 0a803f611324f6268d9bee9fd3b23b3948b0d84b
parent 9b9ffcd1dca14867cfab450fe00debc43e33ab15
Author: Marc Andre Tanner <mat@brain-dump.org>
Date:   Sat, 13 Dec 2008 02:28:32 +0100

Fix handling of wide characters in statusbar text

Diffstat:
config.h | 5++---
dvtm.c | 1+
statusbar.c | 25++++++++++++++-----------
3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/config.h b/config.h @@ -27,9 +27,8 @@ #define BAR_ATTR A_NORMAL #define BAR_FG BLUE #define BAR_BG -1 -/* true if the statusbar text should be right aligned, - * set to false if you prefer it left aligned */ -#define BAR_ALIGN_RIGHT true +/* determines whether the statusbar text should be right or left aligned */ +#define BAR_ALIGN ALIGN_RIGHT /* separator between window title and window number */ #define SEPARATOR " | " /* printf format string for the window title, first %s diff --git a/dvtm.c b/dvtm.c @@ -126,6 +126,7 @@ static void zoom(const char *args[]); static void lock(const char *key[]); #ifdef CONFIG_STATUSBAR +enum { ALIGN_LEFT, ALIGN_RIGHT }; static void togglebar(const char *args[]); #endif diff --git a/statusbar.c b/statusbar.c @@ -22,25 +22,28 @@ updatebarpos(void) { static void drawbar() { - int s, l, maxlen = width - 2; - char t = stext[maxlen]; + wchar_t wbuf[sizeof stext]; + int w, maxwidth = width - 2; if (barpos == BarOff || !*stext) return; curs_set(0); attrset(BAR_ATTR); madtty_color_set(stdscr, BAR_FG, BAR_BG); mvaddch(by, 0, '['); - stext[maxlen] = '\0'; - l = strlen(stext); - if (BAR_ALIGN_RIGHT) - for (s = 0; s + l < maxlen; s++) + if (mbstowcs(wbuf, stext, sizeof stext) == -1) + return; + if ((w = wcswidth(wbuf, maxwidth)) == -1) + return; + if (BAR_ALIGN == ALIGN_RIGHT) { + for (int i = 0; i + w < maxwidth; i++) addch(' '); - else - for (; l < maxlen; l++) - stext[l] = ' '; + } addstr(stext); - stext[maxlen] = t; - addch(']'); + if (BAR_ALIGN == ALIGN_LEFT) { + for (; w < maxwidth; w++) + addch(' '); + } + mvaddch(by, width - 1, ']'); attrset(NORMAL_ATTR); if (sel) curs_set(madtty_cursor(sel->term));