From 322335eb531b4770f297cce6121d47c0f007f3cf Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 11 Feb 2020 22:17:56 +0100 Subject: WIP utf8 ellipse --- configure.ac | 2 +- src/interface.c | 18 ++++++++++++++++-- src/interface.h | 3 +++ src/pa-sink-ctl.c | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 470f179..3ca5384 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ AC_PROG_INSTALL AC_PROG_MAKE_SET # Checks for libraries. -AC_CHECK_LIB([ncurses], [newwin], [CURSES_LIBS=-lncurses], AC_MSG_ERROR([curses required])) +AC_CHECK_LIB([ncursesw], [newwin], [CURSES_LIBS=-lncursesw], AC_MSG_ERROR([curses required])) PKG_CHECK_MODULES(PULSE, [libpulse], [], AC_MSG_ERROR([libpulse required])) PKG_CHECK_MODULES(PULSE_MAINLOOP, [libpulse-mainloop-glib], [], AC_MSG_ERROR([libpulse-mainloop-glib required])) diff --git a/src/interface.c b/src/interface.c index d7f35e2..0ed84eb 100644 --- a/src/interface.c +++ b/src/interface.c @@ -17,6 +17,9 @@ * along with this program. If not, see . */ +#define _XOPEN_SOURCE 700 +#define NCURSES_WIDECHAR 1 + #include #include #include @@ -30,6 +33,7 @@ #include "ctl.h" #include "command.h" #include "pa-sink-ctl.h" +//#include "string-util.h" #ifdef HAVE_SIGNALFD #include @@ -83,6 +87,9 @@ ellipsize(char *str, size_t length) return g_strdup(str); } + /* TODO: currently required to normalize long size */ + length = length + 2; + trimmed = g_new(char, length + 1); offset_start = length/2 - 2; @@ -90,9 +97,16 @@ ellipsize(char *str, size_t length) strncpy(trimmed, str, offset_start); + /* trimmed[offset_start] = '.'; trimmed[offset_start+1] = '.'; - trimmed[offset_start+2] = '.'; + trimmed[offset_start+2] = '.'; + */ + + // Unicode '…' character + trimmed[offset_start] = (char)0xe2; + trimmed[offset_start+1] = (char)0x80; + trimmed[offset_start+2] = (char)0xa6; strncpy(&trimmed[offset_start+3], &str[strlen(str) - offset_end], offset_end); trimmed[length] = '\0'; @@ -115,7 +129,7 @@ print_vol_ctl(gpointer data, gpointer user_data) wattron(ifc->menu_win, A_REVERSE); getmaxyx(ifc->menu_win, max_y, max_x); - name_len =(ifc->max_name_len > max_x / 2 ) ? max_x / 5 * 2 : ifc->max_name_len; + name_len = (ifc->max_name_len > max_x / 2 ) ? max_x / 5 * 2 : ifc->max_name_len; if (!ctl->hide_index) wprintw(ifc->menu_win, "%2u ", ctl->index); diff --git a/src/interface.h b/src/interface.h index ef7cdc2..1e84a2b 100644 --- a/src/interface.h +++ b/src/interface.h @@ -20,6 +20,9 @@ #ifndef INTERFACE_H #define INTERFACE_H +#define _XOPEN_SOURCE 700 +#define NCURSES_WIDECHAR 1 + #include #include #include diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index 4e17337..5c0f7fc 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "ctl.h" #include "interface.h" @@ -570,6 +571,7 @@ main(int argc, char** argv) pa_mainloop_api *mainloop_api = NULL; pa_glib_mainloop *m = NULL; + setlocale(LC_ALL, ""); memset(&ctx, 0, sizeof ctx); ctx.sink_list = NULL; -- cgit