From ebc482b8fd5f3e76506c9baeca596ea965ed372d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sun, 19 May 2013 18:42:38 +0200 Subject: [PATCH] Indicate with ellipsis that text is too long --- src/sdtui.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/sdtui.c b/src/sdtui.c index 7c69c54..0c03ff5 100644 --- a/src/sdtui.c +++ b/src/sdtui.c @@ -98,6 +98,13 @@ struct curses_event MEVENT mouse; }; +static gboolean +is_character_in_locale (wchar_t c) +{ + cchar_t cch; + return setcchar (&cch, &c, A_NORMAL, 0, NULL) != ERR; +} + /** Translate key codes above KEY_MAX returned from ncurses into something * meaningful, based on the terminal type. The values have been obtained * experimentally. Some keycodes make ncurses return KEY_ESCAPE, even @@ -344,11 +351,23 @@ app_add_utf8_string (Application *self, const gchar *str, int n) g_return_val_if_fail (wide_str != NULL, 0); ssize_t wide_len = wcslen (wide_str); - wchar_t padding = L' ', error = L'?'; + wchar_t padding = L' ', error = L'?', ellipsis = L'…'; if (n < 0) n = wide_len; + if (wide_len > n) + { + if (is_character_in_locale (ellipsis) && n > 0) + wide_str[n - 1] = ellipsis; + else if (n >= 3) + { + wide_str[n - 1] = L'.'; + wide_str[n - 2] = L'.'; + wide_str[n - 3] = L'.'; + } + } + gint i; cchar_t cch; for (i = 0; i < n; i++)