mpv icon indicating copy to clipboard operation
mpv copied to clipboard

loadfile: improve the format of terminal track information

Open guidocella opened this issue 1 year ago • 16 comments

Make terminal output consistent with the symbols introduced in 14462dafe4.

There is no need to print ◌ for unselected tracks for alignment since terminal text is always monospace.

guidocella avatar May 20 '24 20:05 guidocella

* and aren't necessarily the same width.

na-na-hi avatar May 20 '24 21:05 na-na-hi

looking at this, we could also do minor alignment fixes

diff --git a/player/loadfile.c b/player/loadfile.c
index 86d4f7cf48..31d052cdbe 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -236,6 +236,7 @@ static void uninit_demuxer(struct MPContext *mpctx)
 }
 
 #define APPEND(s, ...) mp_snprintf_cat(s, sizeof(s), __VA_ARGS__)
+#define FILL(s, n) mp_snprintf_cat(s, sizeof(s), "%-*s", n, "")
 
 static void print_stream(struct MPContext *mpctx, struct track *t)
 {
@@ -261,10 +262,13 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
         if (forced_opt)
             forced_only = t->selected;
     }
-    APPEND(b, " %s %-5s", t->selected ? (forced_only ? "*" : "●") : " ", tname);
-    APPEND(b, " --%s=%d", selopt, t->user_tid);
-    if (t->lang && langopt)
-        APPEND(b, " --%s=%s", langopt, t->lang);
+    APPEND(b, "%s %-5s", t->selected ? (forced_only ? "*" : "\xE2\x97\x8F") : " ", tname);
+    APPEND(b, " --%s=%-2d", selopt, t->user_tid);
+    if (t->lang && langopt) {
+        APPEND(b, " --%s=%-7s", langopt, t->lang);
+    } else {
+        FILL(b, 16);
+    }
     if (t->default_track)
         APPEND(b, " (*)");
     if (t->forced_track)
@@ -282,13 +286,16 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
     if (t->type == STREAM_VIDEO) {
         if (s && s->codec->disp_w)
             APPEND(b, " %dx%d", s->codec->disp_w, s->codec->disp_h);
-        if (s && s->codec->fps)
-            APPEND(b, " %.3ffps", s->codec->fps);
+        if (s && s->codec->fps) {
+            char *fps = mp_format_double(NULL, s->codec->fps, 4, false, false, true);
+            APPEND(b, " %s fps", fps);
+            talloc_free(fps);
+        }
     } else if (t->type == STREAM_AUDIO) {
         if (s && s->codec->channels.num)
-            APPEND(b, " %dch", s->codec->channels.num);
+            APPEND(b, " %d ch", s->codec->channels.num);
         if (s && s->codec->samplerate)
-            APPEND(b, " %dHz", s->codec->samplerate);
+            APPEND(b, " %d Hz", s->codec->samplerate);
     }
     APPEND(b, ")");
     if (s && s->hls_bitrate > 0)

kasper93 avatar May 20 '24 21:05 kasper93

* and aren't necessarily the same width.

They should be in monospaced font, no?

kasper93 avatar May 20 '24 21:05 kasper93

They should be in monospaced font, no?

There is the issue with using an East Asian font as the primary font, which has monospace ASCII characters but with this glyph (and some other glyph such as kanji) being double width.

na-na-hi avatar May 20 '24 22:05 na-na-hi

We can use ∗ which is also wider in Japanese fonts.

guidocella avatar May 21 '24 08:05 guidocella

Do we need both the asterisk and [F] with --sub-forced-events-only?

guidocella avatar May 21 '24 09:05 guidocella

Do we need both the asterisk and [F] with --sub-forced-events-only?

It was added here https://github.com/mpv-player/mpv/commit/d8bd1c35ef6fb397a8ad2987cc41bab805f43e6c not sure how useful it is. To print [F] and (*)

kasper93 avatar May 21 '24 15:05 kasper93

--sub-forced-events-only is not worth showing imo. Nobody uses the option in the first place (except by mistake when thinking it had something to do with selecting forced tracks) and you'll struggle to find a file that actually would use a mix of forced and non-forced events.

Dudemanguy avatar May 21 '24 16:05 Dudemanguy

Nuked it.

guidocella avatar May 21 '24 16:05 guidocella

I made this leave spaces only if at least a track has a language, because it looked silly when none did:

● Video --vid=1                  [P] 'cover.jpg' (mjpeg) (external)
● Audio --aid=1                  (mp3 2 ch 48 kHz)
● Subs  --sid=1                  '8 Hallowed Be Thy Name.lrc' (text) (external)

I also hid the fps of images like I did in stats.lua and select.lua, as it's just a bogus value taken from --mf-fps.

guidocella avatar May 21 '24 19:05 guidocella

Can we remove the quotes around track titles?

guidocella avatar May 23 '24 16:05 guidocella

I think they are good to distinguish title from other fields.

kasper93 avatar May 23 '24 16:05 kasper93

If is a problem, we could mark selected elements with bold or some color. In case we are outputting to tty.

kasper93 avatar May 23 '24 17:05 kasper93

Bold or colored tracks seem too invasive, and the escapes sequence show as garbled in the console log.

guidocella avatar May 23 '24 18:05 guidocella

Bold or colored tracks seem too invasive, and the escapes sequence show as garbled in the console log.

Console log can be fixed, as for the rest it is probably matter of preference, I've seen nice cli interfaces with colors.

kasper93 avatar May 23 '24 21:05 kasper93

I tried to make unselected tracks grey instead.

guidocella avatar May 24 '24 08:05 guidocella

There is also an escape sequence to make text invisible: "\e[8m○\e[0m" fixes the alignment on mlterm and the clutter and differentiates selected tracks without UTF-8 support.

guidocella avatar May 24 '24 09:05 guidocella

Both grey color and invisible escape sequence look good to me.

na-na-hi avatar May 24 '24 13:05 na-na-hi

Either way is fine for me too. Circles works better for log, but could use circles if !tty and gray if tty, but I don't have strong opinion of either as long it also marks them in log somehow.

kasper93 avatar May 24 '24 15:05 kasper93

--log-file still logs the isatty path output.

guidocella avatar May 24 '24 17:05 guidocella

I think printing unicode circles is useful for OSD text but there's nothing wrong with the simple ASCII representation for terminal usage.

As for the spacing: I think it made sense that tracks are indented. Just like the File tags: section.

sfan5 avatar Jun 21 '24 18:06 sfan5