From 1eb91773bda05b7fdb0669fd961ad64f0564b77a Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 22 Jun 2024 00:25:32 +0200 Subject: [PATCH] loadfile: update the format of terminal track information Stop making unselected tracks and editions grey because they can be hard to read over a dark background (\033[2m would be hard to differentiate from regular text with a light theme instead), and because there is no way to not print the escape sequences in --log-file. Just use the same circles as the OSD and OSC. We need to print the empty circles for alignment on mlterm with East Asian fonts (we could also make them invisible with \033[8m but it would still get added to log files). Add back the space before tracks and editions when the "Playing..." line was printed so they look like a sub-section of it, consistently with the metadata which starts with space which makes it look like a sub-section of the "File tags" line. Leave 2 spaces between columns. Make the lang options only as long as the longest language. Move the track title before symbols like (*) so similar titles look aligned. This is consistent with editions. Remove redundant quotes around track titles. Stop converting Hz to kHz for consistency with other log messages, e.g. AO: [pipewire] 48000Hz stereo 2ch floatp Remove the space in "2 ch" so it doesn't look like 2 separate values (We considered using mp_chmap_to_str(&s->codec->channels) but it prints values like "unknown2"). --- osdep/terminal.h | 2 -- player/loadfile.c | 61 ++++++++++++++++++------------------------ player/lua/console.lua | 16 ++--------- player/lua/select.lua | 2 +- 4 files changed, 29 insertions(+), 52 deletions(-) diff --git a/osdep/terminal.h b/osdep/terminal.h index 1c63809f59509..4174cf2d3b3a4 100644 --- a/osdep/terminal.h +++ b/osdep/terminal.h @@ -38,8 +38,6 @@ #define TERM_ESC_ENABLE_MOUSE "\033[?1003h" #define TERM_ESC_DISABLE_MOUSE "\033[?1003l" -#define TERM_ESC_GREY "\033[38;5;8m" - struct input_ctx; /* Global initialization for terminal output. */ diff --git a/player/loadfile.c b/player/loadfile.c index f12ee95a80ea8..c8b87186ba9ed 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -259,33 +259,30 @@ static void print_stream(struct MPContext *mpctx, struct track *t) } char b[2048] = {0}; - bool tracks_have_lang = false; + int max_lang_length = 0; for (int n = 0; n < mpctx->num_tracks; n++) { - if (mpctx->tracks[n]->lang) { - tracks_have_lang = true; - break; - } + if (mpctx->tracks[n]->lang) + max_lang_length = MPMAX(strlen(mpctx->tracks[n]->lang), max_lang_length); } - if (!isatty(STDOUT_FILENO)) { - APPEND(b, "%s ", t->selected ? BLACK_CIRCLE : WHITE_CIRCLE); - } else if (!t->selected) { - APPEND(b, "%s", TERM_ESC_GREY); - } - APPEND(b, "%-5s --%s=%-2d", tname, selopt, t->user_tid); + // Indent tracks after the Playing: line if present. + if (mpctx->playlist->num_entries > 1 || mpctx->playing->playlist_path) + APPEND(b, " "); + APPEND(b, "%s %-5s --%s=%-2d", t->selected ? BLACK_CIRCLE : WHITE_CIRCLE, + tname, selopt, t->user_tid); if (t->lang) { - APPEND(b, " --%s=%-7s", langopt, t->lang); - } else if (tracks_have_lang) { - FILL(b, 16); + APPEND(b, " --%s=%-*s ", langopt, max_lang_length, t->lang); + } else if (max_lang_length) { + FILL(b, (int) strlen(" --alang= ") + max_lang_length); } + if (t->title) + APPEND(b, " %s ", t->title); if (t->default_track) APPEND(b, " (*)"); if (t->forced_track) APPEND(b, " (f)"); if (t->attached_picture) APPEND(b, " [P]"); - if (t->title) - APPEND(b, " '%s'", t->title); const char *codec = s ? s->codec->codec : NULL; APPEND(b, " (%s", codec ? codec : ""); if (s && s->codec->codec_profile) @@ -300,13 +297,9 @@ static void print_stream(struct MPContext *mpctx, struct track *t) } } else if (t->type == STREAM_AUDIO) { if (s && s->codec->channels.num) - APPEND(b, " %d ch", s->codec->channels.num); - if (s && s->codec->samplerate) { - char *samplerate = mp_format_double(NULL, s->codec->samplerate / 1000.0, - 4, false, false, true); - APPEND(b, " %s kHz", samplerate); - talloc_free(samplerate); - } + APPEND(b, " %dch", s->codec->channels.num); + if (s && s->codec->samplerate) + APPEND(b, " %d Hz", s->codec->samplerate); } APPEND(b, ")"); if (s && s->hls_bitrate > 0) @@ -333,17 +326,21 @@ void update_demuxer_properties(struct MPContext *mpctx) if (!demuxer) return; demux_update(demuxer, get_current_time(mpctx)); + struct demuxer *tracks = mpctx->demuxer; + if (tracks->events & DEMUX_EVENT_STREAMS) { + add_demuxer_tracks(mpctx, tracks); + print_track_list(mpctx, NULL); + tracks->events &= ~DEMUX_EVENT_STREAMS; + } int events = demuxer->events; if ((events & DEMUX_EVENT_INIT) && demuxer->num_editions > 1) { for (int n = 0; n < demuxer->num_editions; n++) { struct demux_edition *edition = &demuxer->editions[n]; char b[128] = {0}; - if (!isatty(STDOUT_FILENO)) { - APPEND(b, "%s ", n == demuxer->edition ? BLACK_CIRCLE : WHITE_CIRCLE); - } else if (n != demuxer->edition) { - APPEND(b, "%s", TERM_ESC_GREY); - } - APPEND(b, "--edition=%d", n); + if (mpctx->playlist->num_entries > 1 || mpctx->playing->playlist_path) + APPEND(b, " "); + APPEND(b, "%s --edition=%d", n == demuxer->edition ? + BLACK_CIRCLE : WHITE_CIRCLE, n); char *name = mp_tags_get_str(edition->metadata, "title"); if (name) APPEND(b, " '%s'", name); @@ -352,12 +349,6 @@ void update_demuxer_properties(struct MPContext *mpctx) MP_INFO(mpctx, "%s\n", b); } } - struct demuxer *tracks = mpctx->demuxer; - if (tracks->events & DEMUX_EVENT_STREAMS) { - add_demuxer_tracks(mpctx, tracks); - print_track_list(mpctx, NULL); - tracks->events &= ~DEMUX_EVENT_STREAMS; - } if (events & DEMUX_EVENT_METADATA) { struct mp_tags *info = mp_tags_filtered(mpctx, demuxer->metadata, mpctx->opts->display_tags); diff --git a/player/lua/console.lua b/player/lua/console.lua index 686d04ff3b9d8..ec9e3d75f3e37 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -1780,20 +1780,8 @@ mp.register_event('log-message', function(e) if e.level == 'trace' then return end -- Use color for debug/v/warn/error/fatal messages. - local style = styles[e.level] - local terminal_style = terminal_styles[e.level] - - -- Strip the terminal escape sequence from unselected tracks. - if e.prefix == 'cplayer' and e.level == 'info' then - local found - e.text, found = e.text:gsub('^\027%[38;5;8m', '') - if found == 1 then - style = styles.disabled - terminal_style = terminal_styles.disabled - end - end - - log_add('[' .. e.prefix .. '] ' .. e.text, style, terminal_style) + log_add('[' .. e.prefix .. '] ' .. e.text, styles[e.level], + terminal_styles[e.level]) end) collectgarbage() diff --git a/player/lua/select.lua b/player/lua/select.lua index 504f578f47bf2..ceadcecc16432 100644 --- a/player/lua/select.lua +++ b/player/lua/select.lua @@ -74,7 +74,7 @@ local function format_track(track) and string.format("%.4f", track["demux-fps"]):gsub("%.?0*$", "") .. " fps " or "") .. (track["demux-channel-count"] and track["demux-channel-count"] .. - " ch " or "") .. + "ch " or "") .. (track["codec-profile"] and track.type == "audio" and track["codec-profile"] .. " " or "") .. (track["demux-samplerate"] and track["demux-samplerate"] / 1000 ..