From 21e0d302fc849d9f8827b9f2cb93472f7c30fafe Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 25 Sep 2015 12:01:08 +0200 Subject: curses UI: fixed truncation of non-filename popup entries --- src/interface-curses.cpp | 23 ++++++++++++++++++----- src/interface-curses.h | 6 ++++++ 2 files changed, 24 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/interface-curses.cpp b/src/interface-curses.cpp index b4cdf7e..7466de3 100644 --- a/src/interface-curses.cpp +++ b/src/interface-curses.cpp @@ -388,9 +388,14 @@ void InterfaceCurses::Popup::add(PopupEntryType type, const gchar *name, bool highlight) { - gchar *entry = g_strconcat(highlight ? "*" : " ", name, NIL); + size_t name_len = strlen(name); + Entry *entry = (Entry *)g_malloc(sizeof(Entry) + name_len + 1); - longest = MAX(longest, (gint)strlen(name)); + entry->type = type; + entry->highlight = highlight; + strcpy(entry->name, name); + + longest = MAX(longest, (gint)name_len); length++; /* @@ -436,15 +441,23 @@ InterfaceCurses::Popup::init_pad(attr_t attr) */ cur_col = 0; for (GSList *cur = list; cur != NULL; cur = g_slist_next(cur)) { - gchar *entry = (gchar *)cur->data; + Entry *entry = (Entry *)cur->data; gint cur_line = cur_col/pad_cols + 1; wmove(pad, cur_line-1, (cur_col % pad_cols)*pad_colwidth); - wattrset(pad, *entry == '*' ? A_BOLD : A_NORMAL); + wattrset(pad, entry->highlight ? A_BOLD : A_NORMAL); - format_filename(pad, entry+1); + switch (entry->type) { + case POPUP_FILE: + case POPUP_DIRECTORY: + format_filename(pad, entry->name); + break; + default: + format_str(pad, entry->name); + break; + } cur_col++; } diff --git a/src/interface-curses.h b/src/interface-curses.h index ed228ee..6116cae 100644 --- a/src/interface-curses.h +++ b/src/interface-curses.h @@ -118,6 +118,12 @@ typedef class InterfaceCurses : public Interface { WINDOW *window; /**! window showing part of pad */ WINDOW *pad; /**! full-height entry list */ + struct Entry { + PopupEntryType type; + bool highlight; + gchar name[]; + }; + GSList *list; /**! list of popup entries */ gint longest; /**! size of longest entry */ gint length; /**! total number of popup entries */ -- cgit v1.2.3