diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-09-16 22:30:35 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-09-16 22:30:35 +0200 |
commit | 8744502cbe42c98422a798c06f4c8ce033725412 (patch) | |
tree | 58141e513fa0a066944be0229cfa3c649f934f8d /src/interface-curses/curses-info-popup.c | |
parent | bc859a06a13b24daea12d35df2a1ec5114b42180 (diff) | |
download | sciteco-8744502cbe42c98422a798c06f4c8ce033725412.tar.gz |
Curses: added support for cool Unicode icons (refs #5)
* Practically requires one of the "Nerd Font" fonts,
so it's disabled by default.
Add 0,512ED to the profile to enable them.
* The new ED flag could be used to control Gtk icons as well,
but they are left always-enabled for the time being.
Is there any reason anybody would like to disable icons in Gtk?
* The list of icons has been adapted and extended from exa:
https://github.com/ogham/exa/blob/master/src/output/icons.rs
* The icons are hardcoded as presorted lists,
so we can binary search them.
This could change in the future. If there is any demand,
they could be made configurable via Q-Registers as well.
Diffstat (limited to 'src/interface-curses/curses-info-popup.c')
-rw-r--r-- | src/interface-curses/curses-info-popup.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/interface-curses/curses-info-popup.c b/src/interface-curses/curses-info-popup.c index be4773b..24dee41 100644 --- a/src/interface-curses/curses-info-popup.c +++ b/src/interface-curses/curses-info-popup.c @@ -28,6 +28,7 @@ #include "interface.h" #include "curses-utils.h" #include "curses-info-popup.h" +#include "curses-icons.h" /* * FIXME: This is redundant with gtk-info-popup.c. @@ -75,8 +76,13 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) gint pad_cols; /**! entry columns */ gint pad_colwidth; /**! width per entry column */ - /* reserve 2 spaces between columns */ - pad_colwidth = MIN(ctx->longest + 2, cols - 2); + /* + * With Unicode icons enabled, we reserve 2 characters at the beginning and one + * after the filename/directory. + * Otherwise 2 characters after the entry. + */ + gint reserve = teco_ed & TECO_ED_ICONS ? 2+1 : 2; + pad_colwidth = MIN(ctx->longest + reserve, cols - 2); /* pad_cols = floor((cols - 2) / pad_colwidth) */ pad_cols = (cols - 2) / pad_colwidth; @@ -111,8 +117,15 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) switch (entry->type) { case TECO_POPUP_FILE: + g_assert(!teco_string_contains(&entry->name, '\0')); + if (teco_ed & TECO_ED_ICONS) + wprintw(ctx->pad, "%C ", teco_curses_icons_lookup_file(entry->name.data)); + teco_curses_format_filename(ctx->pad, entry->name.data, -1); + break; case TECO_POPUP_DIRECTORY: g_assert(!teco_string_contains(&entry->name, '\0')); + if (teco_ed & TECO_ED_ICONS) + wprintw(ctx->pad, "%C ", teco_curses_icons_lookup_dir(entry->name.data)); teco_curses_format_filename(ctx->pad, entry->name.data, -1); break; default: |