diff --git a/config.h b/config.h index dc0256b..10000ba 100644 --- 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 index afcb498..f18d573 100644 --- 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 index d918a5b..648514e 100644 --- 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));