diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-03-15 02:46:39 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-03-15 02:46:39 +0300 |
commit | 24b08dac99804bed30824e9becb6f773d5db1874 (patch) | |
tree | dd73a18e9b7042d4c8ca7972dfcc9c22d01f07e4 /src | |
parent | 8d8d62a108d6329049dac63f25c6119db6c44d12 (diff) | |
download | sciteco-24b08dac99804bed30824e9becb6f773d5db1874.tar.gz |
Curses: use special ellipsis symbol instead of "..." when truncating strings
This requires Unicode icon support to be enabled via ED.
The ellipsis symbol is shorter and more distinctive, allowing more of the original
text to be preserved before truncation.
Diffstat (limited to 'src')
-rw-r--r-- | src/core-commands.c | 2 | ||||
-rw-r--r-- | src/interface-curses/curses-icons.h | 14 | ||||
-rw-r--r-- | src/interface-curses/curses-utils.c | 37 |
3 files changed, 38 insertions, 15 deletions
diff --git a/src/core-commands.c b/src/core-commands.c index a9f6cb9..979095b 100644 --- a/src/core-commands.c +++ b/src/core-commands.c @@ -2248,7 +2248,7 @@ TECO_DEFINE_STATE_CASEINSENSITIVE(teco_state_escape, * Must only be enabled if the terminal emulator is configured * properly. * .IP 512: - * Enable/Disable Unicode icons in the Curses UI. + * Enable/Disable Unicode icons and symbols in the Curses UI. * This requires a capable font, like the ones provided * by the \(lqNerd Fonts\(rq project. * Changes to this flag in interactive mode may not become diff --git a/src/interface-curses/curses-icons.h b/src/interface-curses/curses-icons.h index 933241d..fce9d75 100644 --- a/src/interface-curses/curses-icons.h +++ b/src/interface-curses/curses-icons.h @@ -18,11 +18,15 @@ #include <glib.h> -/** - * Q-Register icon. - * 0xf04cf would look more similar to the current Gtk icon. - */ -#define TECO_CURSES_ICONS_QREG 0xe236 /* */ +enum { + /** + * Q-Register icon. + * 0xf04cf would look more similar to the current Gtk icon. + */ + TECO_CURSES_ICONS_QREG = 0xe236, /* */ + /** Ellipsis used for truncating text */ + TECO_CURSES_ICONS_ELLIPSIS = 0x2026 /* … */ +}; gunichar teco_curses_icons_lookup_file(const gchar *filename); gunichar teco_curses_icons_lookup_dir(const gchar *dirname); diff --git a/src/interface-curses/curses-utils.c b/src/interface-curses/curses-utils.c index f362424..3fd680b 100644 --- a/src/interface-curses/curses-utils.c +++ b/src/interface-curses/curses-utils.c @@ -27,6 +27,7 @@ #include "sciteco.h" #include "string-utils.h" +#include "curses-icons.h" #include "curses-utils.h" /** @@ -46,6 +47,7 @@ guint teco_curses_format_str(WINDOW *win, const gchar *str, gsize len, gint max_width) { + gint truncate_len = teco_ed & TECO_ED_ICONS ? 1 : 3; int old_x, old_y; gint chars_added = 0; @@ -122,13 +124,21 @@ teco_curses_format_str(WINDOW *win, const gchar *str, gsize len, gint max_width) return getcurx(win) - old_x; truncate: - if (max_width >= 3) { + if (max_width >= truncate_len) { /* * Truncate string */ - wattron(win, A_UNDERLINE | A_BOLD); - mvwaddstr(win, old_y, old_x + max_width - 3, "..."); - wattroff(win, A_UNDERLINE | A_BOLD); + wmove(win, old_y, old_x + max_width - truncate_len); + if (truncate_len == 3) { + wattron(win, A_UNDERLINE | A_BOLD); + waddstr(win, "..."); + wattroff(win, A_UNDERLINE | A_BOLD); + } else { + g_assert(truncate_len == 1); + wattron(win, A_BOLD); + teco_curses_add_wc(win, TECO_CURSES_ICONS_ELLIPSIS); + wattroff(win, A_BOLD); + } } return getcurx(win) - old_x; @@ -151,6 +161,7 @@ truncate: guint teco_curses_format_filename(WINDOW *win, const gchar *filename, gint max_width) { + gint truncate_len = teco_ed & TECO_ED_ICONS ? 1 : 3; int old_x = getcurx(win); g_autofree gchar *filename_printable = teco_string_echo(filename, strlen(filename)); @@ -167,10 +178,10 @@ teco_curses_format_filename(WINDOW *win, const gchar *filename, gint max_width) * necessary, which requires a widechar Curses variant. */ waddstr(win, filename_printable); - } else if (filename_len >= 3) { + } else if (filename_len >= truncate_len) { const gchar *keep_post; keep_post = g_utf8_offset_to_pointer(filename_printable + strlen(filename_printable), - -max_width + 3); + -max_width + truncate_len); #ifdef G_OS_WIN32 const gchar *keep_pre = g_path_skip_root(filename_printable); @@ -180,9 +191,17 @@ teco_curses_format_filename(WINDOW *win, const gchar *filename, gint max_width) keep_post += keep_pre - filename_printable; } #endif - wattron(win, A_UNDERLINE | A_BOLD); - waddstr(win, "..."); - wattroff(win, A_UNDERLINE | A_BOLD); + + if (truncate_len == 3) { + wattron(win, A_UNDERLINE | A_BOLD); + waddstr(win, "..."); + wattroff(win, A_UNDERLINE | A_BOLD); + } else { + g_assert(truncate_len == 1); + wattron(win, A_BOLD); + teco_curses_add_wc(win, TECO_CURSES_ICONS_ELLIPSIS); + wattroff(win, A_BOLD); + } waddstr(win, keep_post); } |