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 printed after
"Playing..." or "Track switched" and similar, 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 track columns.

Make the lang options only as long as the longest language.

Place hls-bitrate within the same parentheses as the other data.

Replace the incomprehensible (*) (f) and [P] with textual descriptions
within []. Also place external there.

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").
This commit is contained in:
Guido Cella 2024-06-24 15:56:55 +02:00 committed by sfan5
parent f7c1461053
commit 82ffe8f425
4 changed files with 50 additions and 56 deletions

View File

@ -38,8 +38,6 @@
#define TERM_ESC_ENABLE_MOUSE "\033[?1003h" #define TERM_ESC_ENABLE_MOUSE "\033[?1003h"
#define TERM_ESC_DISABLE_MOUSE "\033[?1003l" #define TERM_ESC_DISABLE_MOUSE "\033[?1003l"
#define TERM_ESC_GREY "\033[38;5;8m"
struct input_ctx; struct input_ctx;
/* Global initialization for terminal output. */ /* Global initialization for terminal output. */

View File

@ -239,8 +239,12 @@ static void uninit_demuxer(struct MPContext *mpctx)
#define WHITE_CIRCLE "\xe2\x97\x8b" #define WHITE_CIRCLE "\xe2\x97\x8b"
#define APPEND(s, ...) mp_snprintf_cat(s, sizeof(s), __VA_ARGS__) #define APPEND(s, ...) mp_snprintf_cat(s, sizeof(s), __VA_ARGS__)
#define FILL(s, n) mp_snprintf_cat(s, sizeof(s), "%*s", n, "") #define FILL(s, n) mp_snprintf_cat(s, sizeof(s), "%*s", n, "")
#define ADD_FLAG(b, flag, first) do { \
APPEND(b, " %s%s", first ? "[" : "", flag); \
first = false; \
} while(0)
static void print_stream(struct MPContext *mpctx, struct track *t) static void print_stream(struct MPContext *mpctx, struct track *t, bool indent)
{ {
struct sh_stream *s = t->stream; struct sh_stream *s = t->stream;
const char *tname = "?"; const char *tname = "?";
@ -259,33 +263,24 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
} }
char b[2048] = {0}; char b[2048] = {0};
bool tracks_have_lang = false; int max_lang_length = 0;
for (int n = 0; n < mpctx->num_tracks; n++) { for (int n = 0; n < mpctx->num_tracks; n++) {
if (mpctx->tracks[n]->lang) { if (mpctx->tracks[n]->lang)
tracks_have_lang = true; max_lang_length = MPMAX(strlen(mpctx->tracks[n]->lang), max_lang_length);
break;
}
} }
if (!isatty(STDOUT_FILENO)) { if (indent)
APPEND(b, "%s ", t->selected ? BLACK_CIRCLE : WHITE_CIRCLE); APPEND(b, " ");
} else if (!t->selected) { APPEND(b, "%s %-5s --%s=%-2d", t->selected ? BLACK_CIRCLE : WHITE_CIRCLE,
APPEND(b, "%s", TERM_ESC_GREY); tname, selopt, t->user_tid);
}
APPEND(b, "%-5s --%s=%-2d", tname, selopt, t->user_tid);
if (t->lang) { if (t->lang) {
APPEND(b, " --%s=%-7s", langopt, t->lang); APPEND(b, " --%s=%-*s ", langopt, max_lang_length, t->lang);
} else if (tracks_have_lang) { } else if (max_lang_length) {
FILL(b, 16); FILL(b, (int) strlen(" --alang= ") + max_lang_length);
} }
if (t->default_track)
APPEND(b, " (*)");
if (t->forced_track)
APPEND(b, " (f)");
if (t->attached_picture)
APPEND(b, " [P]");
if (t->title) if (t->title)
APPEND(b, " '%s'", t->title); APPEND(b, " '%s'", t->title);
const char *codec = s ? s->codec->codec : NULL; const char *codec = s ? s->codec->codec : NULL;
APPEND(b, " (%s", codec ? codec : "<unknown>"); APPEND(b, " (%s", codec ? codec : "<unknown>");
if (s && s->codec->codec_profile) if (s && s->codec->codec_profile)
@ -301,18 +296,29 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
} else if (t->type == STREAM_AUDIO) { } else if (t->type == STREAM_AUDIO) {
if (s && s->codec->channels.num) if (s && s->codec->channels.num)
APPEND(b, " %dch", s->codec->channels.num); APPEND(b, " %dch", s->codec->channels.num);
if (s && s->codec->samplerate) { if (s && s->codec->samplerate)
char *samplerate = mp_format_double(NULL, s->codec->samplerate / 1000.0, APPEND(b, " %d Hz", s->codec->samplerate);
4, false, false, true);
APPEND(b, " %s kHz", samplerate);
talloc_free(samplerate);
} }
}
APPEND(b, ")");
if (s && s->hls_bitrate > 0) if (s && s->hls_bitrate > 0)
APPEND(b, " (%d kbps)", (s->hls_bitrate + 500) / 1000); APPEND(b, " %d kbps", (s->hls_bitrate + 500) / 1000);
APPEND(b, ")");
bool first = true;
if (t->default_track)
ADD_FLAG(b, "default", first);
if (t->forced_track)
ADD_FLAG(b, "forced", first);
if (t->attached_picture)
ADD_FLAG(b, "picture", first);
if (t->visual_impaired_track)
ADD_FLAG(b, "visual_impaired", first);
if (t->hearing_impaired_track)
ADD_FLAG(b, "hearing_impaired", first);
if (t->is_external) if (t->is_external)
APPEND(b, " (external)"); ADD_FLAG(b, "external", first);
if (!first)
APPEND(b, "]");
MP_INFO(mpctx, "%s\n", b); MP_INFO(mpctx, "%s\n", b);
} }
@ -323,7 +329,11 @@ void print_track_list(struct MPContext *mpctx, const char *msg)
for (int t = 0; t < STREAM_TYPE_COUNT; t++) { for (int t = 0; t < STREAM_TYPE_COUNT; t++) {
for (int n = 0; n < mpctx->num_tracks; n++) for (int n = 0; n < mpctx->num_tracks; n++)
if (mpctx->tracks[n]->type == t) if (mpctx->tracks[n]->type == t)
print_stream(mpctx, mpctx->tracks[n]); // Indent tracks after messages like "Tracks switched" and
// "Playing:".
print_stream(mpctx, mpctx->tracks[n], msg ||
mpctx->playlist->num_entries > 1 ||
mpctx->playing->playlist_path);
} }
} }
@ -338,17 +348,15 @@ void update_demuxer_properties(struct MPContext *mpctx)
for (int n = 0; n < demuxer->num_editions; n++) { for (int n = 0; n < demuxer->num_editions; n++) {
struct demux_edition *edition = &demuxer->editions[n]; struct demux_edition *edition = &demuxer->editions[n];
char b[128] = {0}; char b[128] = {0};
if (!isatty(STDOUT_FILENO)) { if (mpctx->playlist->num_entries > 1 || mpctx->playing->playlist_path)
APPEND(b, "%s ", n == demuxer->edition ? BLACK_CIRCLE : WHITE_CIRCLE); APPEND(b, " ");
} else if (n != demuxer->edition) { APPEND(b, "%s --edition=%d", n == demuxer->edition ?
APPEND(b, "%s", TERM_ESC_GREY); BLACK_CIRCLE : WHITE_CIRCLE, n);
}
APPEND(b, "--edition=%d", n);
char *name = mp_tags_get_str(edition->metadata, "title"); char *name = mp_tags_get_str(edition->metadata, "title");
if (name) if (name)
APPEND(b, " '%s'", name); APPEND(b, " '%s'", name);
if (edition->default_edition) if (edition->default_edition)
APPEND(b, " (*)"); APPEND(b, " [default]");
MP_INFO(mpctx, "%s\n", b); MP_INFO(mpctx, "%s\n", b);
} }
} }

View File

@ -1780,20 +1780,8 @@ mp.register_event('log-message', function(e)
if e.level == 'trace' then return end if e.level == 'trace' then return end
-- Use color for debug/v/warn/error/fatal messages. -- Use color for debug/v/warn/error/fatal messages.
local style = styles[e.level] log_add('[' .. e.prefix .. '] ' .. e.text, styles[e.level],
local terminal_style = terminal_styles[e.level] 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)
end) end)
collectgarbage() collectgarbage()