mirror of https://github.com/mpv-player/mpv
options: add --no-terminal switch
Mostly useful for internal reasons. This code will be enabled by default if mpv is started via the client API.
This commit is contained in:
parent
20fbe2fb8c
commit
8437356b6c
|
@ -2411,6 +2411,13 @@ OPTIONS
|
|||
|
||||
Default: ``[-+-]``.
|
||||
|
||||
``--no-terminal``, ``--terminal``
|
||||
Disable any use of the terminal and stdin/stdout/stderr. This completely
|
||||
silences any message output.
|
||||
|
||||
Unlike ``--really-quiet``, this disables input and terminal initialization
|
||||
as well.
|
||||
|
||||
``--title=<string>``
|
||||
Set the window title. Properties are expanded on playback start.
|
||||
(See `Property Expansion`_.)
|
||||
|
|
34
common/msg.c
34
common/msg.c
|
@ -45,6 +45,7 @@ struct mp_log_root {
|
|||
struct mpv_global *global;
|
||||
// --- protected by mp_msg_lock
|
||||
char *msglevels;
|
||||
bool use_terminal; // make accesses to stderr/stdout
|
||||
bool smode; // slave mode compatibility glue
|
||||
bool module;
|
||||
bool termosd; // use terminal control codes for status line
|
||||
|
@ -98,18 +99,22 @@ static bool match_mod(const char *name, bstr mod)
|
|||
static void update_loglevel(struct mp_log *log)
|
||||
{
|
||||
pthread_mutex_lock(&mp_msg_lock);
|
||||
log->level = MSGL_STATUS + log->root->verbose; // default log level
|
||||
// Stupid exception for the remains of -identify
|
||||
if (match_mod(log->verbose_prefix, bstr0("identify")))
|
||||
log->level = -1;
|
||||
bstr s = bstr0(log->root->msglevels);
|
||||
bstr mod;
|
||||
int level;
|
||||
while (mp_msg_split_msglevel(&s, &mod, &level) > 0) {
|
||||
if (match_mod(log->verbose_prefix, mod))
|
||||
log->level = level;
|
||||
log->level = -1;
|
||||
log->terminal_level = -1;
|
||||
if (log->root->use_terminal) {
|
||||
log->level = MSGL_STATUS + log->root->verbose; // default log level
|
||||
// Stupid exception for the remains of -identify
|
||||
if (match_mod(log->verbose_prefix, bstr0("identify")))
|
||||
log->level = -1;
|
||||
bstr s = bstr0(log->root->msglevels);
|
||||
bstr mod;
|
||||
int level;
|
||||
while (mp_msg_split_msglevel(&s, &mod, &level) > 0) {
|
||||
if (match_mod(log->verbose_prefix, mod))
|
||||
log->level = level;
|
||||
}
|
||||
log->terminal_level = log->root->use_terminal ? log->level : -1;
|
||||
}
|
||||
log->terminal_level = log->level;
|
||||
for (int n = 0; n < log->root->num_buffers; n++)
|
||||
log->level = MPMAX(log->level, log->root->buffers[n]->level);
|
||||
log->reload_counter = log->root->reload_counter;
|
||||
|
@ -372,8 +377,11 @@ void mp_msg_update_msglevels(struct mpv_global *global)
|
|||
root->verbose = opts->verbose;
|
||||
root->module = opts->msg_module;
|
||||
root->smode = opts->msg_identify;
|
||||
root->color = opts->msg_color && isatty(fileno(stdout));
|
||||
root->termosd = !opts->slave_mode && isatty(fileno(stderr));
|
||||
root->use_terminal = opts->use_terminal;
|
||||
if (root->use_terminal) {
|
||||
root->color = opts->msg_color && isatty(fileno(stdout));
|
||||
root->termosd = !opts->slave_mode && isatty(fileno(stderr));
|
||||
}
|
||||
|
||||
talloc_free(root->msglevels);
|
||||
root->msglevels = talloc_strdup(root, global->opts->msglevels);
|
||||
|
|
|
@ -226,6 +226,7 @@ const m_option_t mp_opts[] = {
|
|||
// ------------------------- common options --------------------
|
||||
OPT_FLAG("quiet", quiet, CONF_GLOBAL),
|
||||
OPT_FLAG_STORE("really-quiet", verbose, CONF_GLOBAL | CONF_PRE_PARSE, -10),
|
||||
OPT_FLAG("terminal", use_terminal, CONF_GLOBAL | CONF_PRE_PARSE),
|
||||
OPT_GENERAL(char*, "msglevel", msglevels, CONF_GLOBAL|CONF_PRE_PARSE,
|
||||
.type = &m_option_type_msglevels),
|
||||
OPT_FLAG("msgcolor", msg_color, CONF_GLOBAL | CONF_PRE_PARSE),
|
||||
|
@ -649,6 +650,7 @@ const m_option_t mp_opts[] = {
|
|||
};
|
||||
|
||||
const struct MPOpts mp_default_opts = {
|
||||
.use_terminal = 1,
|
||||
.msg_color = 1,
|
||||
.audio_driver_list = NULL,
|
||||
.audio_decoders = "-spdif:*", // never select spdif by default
|
||||
|
|
|
@ -44,6 +44,7 @@ typedef struct mp_vo_opts {
|
|||
} mp_vo_opts;
|
||||
|
||||
typedef struct MPOpts {
|
||||
int use_terminal;
|
||||
char *msglevels;
|
||||
int verbose;
|
||||
int msg_identify;
|
||||
|
|
|
@ -1097,7 +1097,7 @@ static void play_current_file(struct MPContext *mpctx)
|
|||
load_per_file_options(mpctx->mconfig, mpctx->playlist->current->params,
|
||||
mpctx->playlist->current->num_params);
|
||||
|
||||
if (!opts->consolecontrols)
|
||||
if (opts->use_terminal && !opts->consolecontrols)
|
||||
getch2_disable();
|
||||
|
||||
#if HAVE_LIBASS
|
||||
|
@ -1393,7 +1393,7 @@ terminate_playback: // don't jump here after ao/vo/getch initialization!
|
|||
if (mpctx->stop_play != PT_RESTART)
|
||||
m_config_restore_backups(mpctx->mconfig);
|
||||
|
||||
if (opts->consolecontrols)
|
||||
if (opts->use_terminal && opts->consolecontrols)
|
||||
getch2_enable();
|
||||
|
||||
mpctx->filename = NULL;
|
||||
|
|
|
@ -149,7 +149,8 @@ static MP_NORETURN void exit_player(struct MPContext *mpctx,
|
|||
mpctx->ass_library = NULL;
|
||||
#endif
|
||||
|
||||
getch2_disable();
|
||||
if (mpctx->opts->use_terminal)
|
||||
getch2_disable();
|
||||
uninit_libav(mpctx->global);
|
||||
|
||||
if (how != EXIT_NONE) {
|
||||
|
@ -288,8 +289,6 @@ static void osdep_preinit(int *p_argc, char ***p_argv)
|
|||
pSetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE);
|
||||
#endif
|
||||
|
||||
terminal_init();
|
||||
|
||||
mp_time_init();
|
||||
}
|
||||
|
||||
|
@ -342,18 +341,21 @@ static int mpv_main(int argc, char *argv[])
|
|||
char *verbose_env = getenv("MPV_VERBOSE");
|
||||
if (verbose_env)
|
||||
opts->verbose = atoi(verbose_env);
|
||||
|
||||
// Preparse the command line
|
||||
m_config_preparse_command_line(mpctx->mconfig, mpctx->global, argc, argv);
|
||||
|
||||
mp_msg_update_msglevels(mpctx->global);
|
||||
|
||||
if (opts->use_terminal)
|
||||
terminal_init();
|
||||
|
||||
init_libav(mpctx->global);
|
||||
GetCpuCaps(&gCpuCaps);
|
||||
screenshot_init(mpctx);
|
||||
mpctx->mixer = mixer_init(mpctx, mpctx->global);
|
||||
command_init(mpctx);
|
||||
|
||||
// Preparse the command line
|
||||
m_config_preparse_command_line(mpctx->mconfig, mpctx->global, argc, argv);
|
||||
mp_msg_update_msglevels(mpctx->global);
|
||||
|
||||
mp_print_version(mpctx->log, false);
|
||||
|
||||
if (!mp_parse_cfgfiles(mpctx))
|
||||
|
@ -413,13 +415,15 @@ static int mpv_main(int argc, char *argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
if (mpctx->opts->slave_mode)
|
||||
terminal_setup_stdin_cmd_input(mpctx->input);
|
||||
else if (mpctx->opts->consolecontrols)
|
||||
terminal_setup_getch(mpctx->input);
|
||||
if (opts->use_terminal) {
|
||||
if (mpctx->opts->slave_mode)
|
||||
terminal_setup_stdin_cmd_input(mpctx->input);
|
||||
else if (mpctx->opts->consolecontrols)
|
||||
terminal_setup_getch(mpctx->input);
|
||||
|
||||
if (opts->consolecontrols)
|
||||
getch2_enable();
|
||||
if (opts->consolecontrols)
|
||||
getch2_enable();
|
||||
}
|
||||
|
||||
#if HAVE_LIBASS
|
||||
mpctx->ass_log = mp_log_new(mpctx, mpctx->global->log, "!libass");
|
||||
|
|
|
@ -70,6 +70,9 @@ static void term_osd_update(struct MPContext *mpctx)
|
|||
int num_parts = 0;
|
||||
char *parts[3] = {0};
|
||||
|
||||
if (!mpctx->opts->use_terminal)
|
||||
return;
|
||||
|
||||
if (mpctx->term_osd_subs && mpctx->term_osd_subs[0])
|
||||
parts[num_parts++] = mpctx->term_osd_subs;
|
||||
if (mpctx->term_osd_text && mpctx->term_osd_text[0])
|
||||
|
@ -147,6 +150,9 @@ void print_status(struct MPContext *mpctx)
|
|||
|
||||
update_window_title(mpctx, false);
|
||||
|
||||
if (!opts->use_terminal)
|
||||
return;
|
||||
|
||||
if (opts->quiet || !(mpctx->initialized_flags & INITIALIZED_PLAYBACK)) {
|
||||
term_osd_set_status(mpctx, "");
|
||||
return;
|
||||
|
|
|
@ -1300,7 +1300,8 @@ void run_playloop(struct MPContext *mpctx)
|
|||
|
||||
execute_queued_seek(mpctx);
|
||||
|
||||
getch2_poll();
|
||||
if (mpctx->opts->use_terminal)
|
||||
getch2_poll();
|
||||
}
|
||||
|
||||
// Waiting for the slave master to send us a new file to play.
|
||||
|
@ -1330,6 +1331,7 @@ void idle_loop(struct MPContext *mpctx)
|
|||
run_command(mpctx, cmd);
|
||||
mp_cmd_free(cmd);
|
||||
mp_flush_events(mpctx);
|
||||
getch2_poll();
|
||||
if (mpctx->opts->use_terminal)
|
||||
getch2_poll();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue