mirror of
https://github.com/mpv-player/mpv
synced 2025-02-23 16:36:56 +00:00
player: add --term-title option
This simply printf()s a concatenation of the provided string and the relevant escape sequences. No idea what exactly defines this escape sequence (is it just a xterm thing that is now supported relatively widely?), and this simply uses information provided on the linked github issue. Not much of an advantage over --term-status-msg, though at least this can have a lower update frequency. Also I may consider setting a default value, and then it shouldn't conflict with the status message. Fixes: #1725
This commit is contained in:
parent
b83bdd1d17
commit
b1d16a2300
@ -4429,6 +4429,15 @@ Terminal
|
||||
Print out a custom string during playback instead of the standard status
|
||||
line. Expands properties. See `Property Expansion`_.
|
||||
|
||||
``--term-title=<string>``
|
||||
Set the terminal title. Currently, this simply concatenates the escape
|
||||
sequence setting the window title with the provided (property expanded)
|
||||
string. This will mess up if the expanded string contain bytes that end the
|
||||
escape sequence, or if the terminal does not understand the sequence. The
|
||||
latter probably includes the regrettable win32.
|
||||
|
||||
Expands properties. See `Property Expansion`_.
|
||||
|
||||
``--msg-module``
|
||||
Prepend module name to each console message.
|
||||
|
||||
|
10
common/msg.c
10
common/msg.c
@ -230,6 +230,16 @@ void mp_msg_flush_status_line(struct mp_log *log)
|
||||
}
|
||||
}
|
||||
|
||||
void mp_msg_set_term_title(struct mp_log *log, const char *title)
|
||||
{
|
||||
if (log->root && title) {
|
||||
// Lock because printf to terminal is not necessarily atomic.
|
||||
pthread_mutex_lock(&log->root->lock);
|
||||
fprintf(stderr, "\e]0;%s\007", title);
|
||||
pthread_mutex_unlock(&log->root->lock);
|
||||
}
|
||||
}
|
||||
|
||||
bool mp_msg_has_status_line(struct mpv_global *global)
|
||||
{
|
||||
struct mp_log_root *root = global->log->root;
|
||||
|
@ -14,6 +14,7 @@ bool mp_msg_has_log_file(struct mpv_global *global);
|
||||
void mp_msg_set_early_logging(struct mpv_global *global, bool enable);
|
||||
|
||||
void mp_msg_flush_status_line(struct mp_log *log);
|
||||
void mp_msg_set_term_title(struct mp_log *log, const char *title);
|
||||
|
||||
struct mp_log_buffer_entry {
|
||||
char *prefix;
|
||||
|
@ -702,6 +702,7 @@ static const m_option_t mp_opts[] = {
|
||||
|
||||
{"term-osd-bar", OPT_FLAG(term_osd_bar), .flags = UPDATE_OSD},
|
||||
{"term-osd-bar-chars", OPT_STRING(term_osd_bar_chars), .flags = UPDATE_OSD},
|
||||
{"term-title", OPT_STRING(term_title), .flags = UPDATE_OSD},
|
||||
|
||||
{"term-playing-msg", OPT_STRING(playing_msg)},
|
||||
{"osd-playing-msg", OPT_STRING(osd_playing_msg)},
|
||||
|
@ -217,6 +217,7 @@ typedef struct MPOpts {
|
||||
int term_osd;
|
||||
int term_osd_bar;
|
||||
char *term_osd_bar_chars;
|
||||
char *term_title;
|
||||
char *playing_msg;
|
||||
char *osd_playing_msg;
|
||||
char *status_msg;
|
||||
|
@ -264,6 +264,7 @@ typedef struct MPContext {
|
||||
char *term_osd_status;
|
||||
char *term_osd_subs;
|
||||
char *term_osd_contents;
|
||||
char *term_osd_title;
|
||||
char *last_window_title;
|
||||
struct voctrl_playback_state vo_playback_state;
|
||||
|
||||
|
16
player/osd.c
16
player/osd.c
@ -96,6 +96,21 @@ static void term_osd_update(struct MPContext *mpctx)
|
||||
}
|
||||
}
|
||||
|
||||
static void term_osd_update_title(struct MPContext *mpctx)
|
||||
{
|
||||
if (!mpctx->opts->use_terminal)
|
||||
return;
|
||||
|
||||
char *s = mp_property_expand_escaped_string(mpctx, mpctx->opts->term_title);
|
||||
if (bstr_equals(bstr0(s), bstr0(mpctx->term_osd_title))) {
|
||||
talloc_free(s);
|
||||
return;
|
||||
}
|
||||
|
||||
mp_msg_set_term_title(mpctx->statusline, s);
|
||||
mpctx->term_osd_title = talloc_steal(mpctx, s);
|
||||
}
|
||||
|
||||
void term_osd_set_subs(struct MPContext *mpctx, const char *text)
|
||||
{
|
||||
if (mpctx->video_out || !text || !mpctx->opts->subs_rend->sub_visibility)
|
||||
@ -260,6 +275,7 @@ static void term_osd_print_status_lazy(struct MPContext *mpctx)
|
||||
{
|
||||
struct MPOpts *opts = mpctx->opts;
|
||||
|
||||
term_osd_update_title(mpctx);
|
||||
update_window_title(mpctx, false);
|
||||
update_vo_playback_state(mpctx);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user