Avoid displaying status line on Linux when there is no controlling terminal, in more cases
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 37k
- Forks
- 3.5k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 22
Description
On Linux, playing a sound from the command line, with version:
mpv v0.37.0 Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
built on Jan 19 2024 09:09:45
I ran the following set of commands, under bash, with controlling terminal /dev/pts/9, and recorded whether or not they maintained a 'terminal status line' (like: A: 00:00:01 / 00:05:01 (1%)) in the terminal.
mpv --no-config sound.ogg # 1: shows status line
mpv --no-config sound.ogg </dev/null # 2: shows status line
mpv --no-config sound.ogg >/dev/null # 3: shows status line
mpv --no-config sound.ogg >/dev/null </dev/null # 4: shows status line
mpv --no-config sound.ogg 2>pipe # 5: no status line
mpv --no-config sound.ogg 2>pipe </dev/null # 6: no status line
mpv --no-config sound.ogg 2>pipe >/dev/null # 7: shows status line
mpv --no-config sound.ogg 2>pipe >/dev/null </dev/null # 8: shows status line
Here pipe was a named pipe hooked up to tail -f. I also ran the commands under setsid, which runs them without a controlling terminal.
setsid mpv --no-config sound.ogg # 9: no status line
setsid mpv --no-config sound.ogg </dev/null # 10: shows status line
setsid mpv --no-config sound.ogg >/dev/null # 11: shows status line
setsid mpv --no-config sound.ogg >/dev/null </dev/null # 12: shows status line
setsid mpv --no-config sound.ogg 2>pipe # 13: no status line
setsid mpv --no-config sound.ogg 2>pipe </dev/null # 14: shows status line
setsid mpv --no-config sound.ogg 2>pipe >/dev/null # 15: shows status line
setsid mpv --no-config sound.ogg 2>pipe >/dev/null </dev/null # 16: shows status line
In general, I think the behavior when there is a controlling terminal is mostly what I'd expect: to render a status line over stderr if that is indeed a terminal. However, when there is no controlling terminal, mpv displays a status line if either stdout or stdin is not a tty, which is a confusing set of conditions, and can lead to mpv filling a log file with status lines when it is run from a GUI program.
Expected behavior of the wanted feature
Because programs without a controlling terminal and without stdin being a terminal are usually run in contexts without keyboard interaction, but which might log stderr to a file, I believe a better default behavior for, at minimum, cases 14, 16 (no controlling terminal, stdin is a pipe (that mpv is not reading data from), stderr is not a terminal) would be not to display a status line.
It's entirely possible that I've overlooked the reasons that mpv has its current behavior -- there have been many changes to the terminal code over the years, and I have not yet fully understood the files (osdep/terminal-unix.c and https://github.com/mpv-player/mpv/blob/master/common/msg.c) implementing the terminal behavior, let alone their history.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the listed mpv and setsid cases, especially 14 and 16, then read osdep/terminal-unix.c and common/msg.c to trace how terminal status output is enabled. Compare the controlling-terminal, stdin, stdout, and stderr conditions. Done means the specified no-controlling-terminal cases no longer emit a status line while existing terminal behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, c
- Domain
- cli, operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100