Skip to content

Commit

Permalink
loadfile: update the format of terminal track information
Browse files Browse the repository at this point in the history
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 so they look like a
sub-section of the "Playing..." line printed with playlists and of
"Track switched", consistently with the metadata which starts with space
which makes it look like a sub-section of the "File tags" line.

Also stop converting Hz to kHz for consistency with other log messages,
e.g. AO: [pipewire] 48000Hz stereo 2ch floatp
  • Loading branch information
guidocella committed Jun 21, 2024
1 parent bab9b2c commit 1246ee9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
2 changes: 0 additions & 2 deletions osdep/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
23 changes: 5 additions & 18 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,8 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
}
}

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);
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) {
Expand Down Expand Up @@ -301,12 +297,8 @@ 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);
}
if (s && s->codec->samplerate)
APPEND(b, " %d Hz", s->codec->samplerate);
}
APPEND(b, ")");
if (s && s->hls_bitrate > 0)
Expand Down Expand Up @@ -338,12 +330,7 @@ void update_demuxer_properties(struct MPContext *mpctx)
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);
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);
Expand Down
16 changes: 2 additions & 14 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 1246ee9

Please sign in to comment.