From 277ab02f3820b41286f3fa9c637f6322b564ea77 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 2 Jun 2019 16:41:38 +0200 Subject: [PATCH] command: show number of hidden items in OSD lists Affects the "classic" OSD rendering of some properties, like playlists. --- player/command.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/player/command.c b/player/command.c index 33b60158d4..333e4fe784 100644 --- a/player/command.c +++ b/player/command.c @@ -330,29 +330,35 @@ static char *cut_osd_list(struct MPContext *mpctx, char *text, int pos) char *new = talloc_strdup(NULL, ""); - int start = pos - max_lines / 2; + int start = MPMAX(pos - max_lines / 2, 0); if (start == 1) start = 0; // avoid weird transition when pad_h becomes visible int pad_h = start > 0; - if (pad_h) - new = talloc_strdup_append_buffer(new, "\342\206\221 (hidden items)\n"); int space = max_lines - pad_h - 1; int pad_t = count - start > space; if (!pad_t) start = count - space; + if (pad_h) { + new = talloc_asprintf_append_buffer(new, "\342\206\221 (%d hidden items)\n", + start); + } + char *head = skip_n_lines(text, start); if (!head) { talloc_free(new); return text; } - char *tail = skip_n_lines(head, max_lines - pad_h - pad_t); + int lines_shown = max_lines - pad_h - pad_t; + char *tail = skip_n_lines(head, lines_shown); new = talloc_asprintf_append_buffer(new, "%.*s", (int)(tail ? tail - head : strlen(head)), head); - if (pad_t) - new = talloc_strdup_append_buffer(new, "\342\206\223 (hidden items)\n"); + if (pad_t) { + new = talloc_asprintf_append_buffer(new, "\342\206\223 (%d hidden items)\n", + count - start - lines_shown + 1); + } talloc_free(text); return new;