diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2013-05-19 18:42:38 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2013-05-19 18:42:38 +0200 |
commit | ebc482b8fd5f3e76506c9baeca596ea965ed372d (patch) | |
tree | 400b5cefecfcfc71503a3f5fb6a3901ce5cd1d8f /src/sdtui.c | |
parent | a405bd508ccbca8340f9421151d16a8b9d3bb3cb (diff) | |
download | tdv-ebc482b8fd5f3e76506c9baeca596ea965ed372d.tar.gz tdv-ebc482b8fd5f3e76506c9baeca596ea965ed372d.tar.xz tdv-ebc482b8fd5f3e76506c9baeca596ea965ed372d.zip |
Indicate with ellipsis that text is too long
Diffstat (limited to 'src/sdtui.c')
-rw-r--r-- | src/sdtui.c | 21 |
1 files changed, 20 insertions, 1 deletions
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++) |