dvtm

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

commit ef9d2925167d83267baf4187a41fed3946242654
parent 717ddc7c698b6185e41526e99d24648b93283aab
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri,  6 Feb 2015 18:24:16 +0100

Better Unicode handling in status bar

Diffstat:
config.mk | 2+-
dvtm.c | 42++++++++++++++++++++++++++----------------
2 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/config.mk b/config.mk @@ -21,7 +21,7 @@ LIBS = -lc -lutil -lncursesw # Cygwin #INCS = -I/usr/include/ncurses -CFLAGS += -std=c99 -Os ${INCS} -DVERSION=\"${VERSION}\" -DNDEBUG -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 +CFLAGS += -std=c99 -Os ${INCS} -DVERSION=\"${VERSION}\" -DNDEBUG -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -D_XOPEN_SOURCE_EXTENDED LDFLAGS += ${LIBS} DEBUG_CFLAGS = ${CFLAGS} -UNDEBUG -O0 -g -ggdb -Wall -Wextra -Wno-unused-parameter diff --git a/dvtm.c b/dvtm.c @@ -298,7 +298,7 @@ updatebarpos(void) { static void drawbar(void) { - int sx, sy, x = 0; + int sx, sy, x, y, width; unsigned int occupied = 0, urgent = 0; if (bar.pos == BAR_OFF) return; @@ -323,29 +323,39 @@ drawbar(void) { else attrset(TAG_NORMAL); printw(TAG_SYMBOL, tags[i]); - /* -2 because we assume %s is contained in TAG_SYMBOL */ - x += STRLEN(TAG_SYMBOL) - 2 + strlen(tags[i]); } + attrset(TAG_NORMAL); + + getyx(stdscr, y, x); + (void)y; + int maxwidth = screen.w - x - 2; + addch('['); attrset(BAR_ATTR); wchar_t wbuf[sizeof bar.text]; - int w, maxwidth = screen.w - x - 2; + size_t numchars = mbstowcs(wbuf, bar.text, sizeof bar.text); + + if (numchars != (size_t)-1 && (width = wcswidth(wbuf, maxwidth)) != -1) { + int pos = 0; + if (BAR_ALIGN == ALIGN_RIGHT) { + while (pos + width < maxwidth) { + addch(' '); + pos++; + } + } - if (mbstowcs(wbuf, bar.text, sizeof bar.text) == (size_t)-1) - return; - if ((w = wcswidth(wbuf, maxwidth)) == -1) - return; - if (BAR_ALIGN == ALIGN_RIGHT) { - for (int i = 0; i + w < maxwidth; i++) - addch(' '); - } - addstr(bar.text); - if (BAR_ALIGN == ALIGN_LEFT) { - for (; w < maxwidth; w++) - addch(' '); + for (size_t i = 0; i < numchars; i++) { + pos += wcwidth(wbuf[i]); + if (pos > maxwidth) + break; + addnwstr(wbuf+i, 1); + } + + clrtoeol(); } + attrset(TAG_NORMAL); mvaddch(bar.y, screen.w - 1, ']'); attrset(NORMAL_ATTR);