mirror of
https://github.com/mpv-player/mpv
synced 2024-12-22 06:42:03 +00:00
player: add --term-osd-bar, which shows a status bar on the terminal
Feature request from github issue #451. Disabled by default, will probably stay this way.
This commit is contained in:
parent
ca8937d7d2
commit
45641378a2
@ -2380,6 +2380,18 @@ OPTIONS
|
||||
|
||||
``force`` enables terminal OSD even if a video window is created.
|
||||
|
||||
``--term-osd-bar``, ``--no-term-osd-bar``
|
||||
Enable printing a progress bar under the status line on the terminal.
|
||||
(Disabled by default.)
|
||||
|
||||
``--term-osd-bar-chars=<string>``
|
||||
Customize the ``--term-osd-bar`` feature. The string is expected to
|
||||
consist of 5 characters (start, left space, position indicator,
|
||||
right space, end). You can use unicode characters, but note that double-
|
||||
width characters will not be treated correctly.
|
||||
|
||||
Default: ``[-+-]``.
|
||||
|
||||
``--title=<string>``
|
||||
Set the window title. Properties are expanded on playback start.
|
||||
(See `Property Expansion`_.)
|
||||
|
@ -597,6 +597,9 @@ const m_option_t mp_opts[] = {
|
||||
{"auto", 2},
|
||||
{"no", 0})),
|
||||
|
||||
OPT_FLAG("term-osd-bar", term_osd_bar, 0),
|
||||
OPT_STRING("term-osd-bar-chars", term_osd_bar_chars, 0),
|
||||
|
||||
OPT_STRING("playing-msg", playing_msg, M_OPT_PARSE_ESCAPES),
|
||||
OPT_STRING("status-msg", status_msg, M_OPT_PARSE_ESCAPES),
|
||||
OPT_STRING("osd-status-msg", osd_status_msg, M_OPT_PARSE_ESCAPES),
|
||||
@ -702,6 +705,7 @@ const struct MPOpts mp_default_opts = {
|
||||
.user_pts_assoc_mode = 1,
|
||||
.initial_audio_sync = 1,
|
||||
.term_osd = 2,
|
||||
.term_osd_bar_chars = "[-+-]",
|
||||
.consolecontrols = 1,
|
||||
.play_frames = -1,
|
||||
.keep_open = 0,
|
||||
|
@ -124,6 +124,8 @@ typedef struct MPOpts {
|
||||
int softsleep;
|
||||
int frame_dropping;
|
||||
int term_osd;
|
||||
int term_osd_bar;
|
||||
char *term_osd_bar_chars;
|
||||
char *playing_msg;
|
||||
char *status_msg;
|
||||
char *osd_status_msg;
|
||||
|
29
player/osd.c
29
player/osd.c
@ -103,6 +103,29 @@ static void term_osd_set_status(struct MPContext *mpctx, const char *text)
|
||||
term_osd_update(mpctx);
|
||||
}
|
||||
|
||||
static void add_term_osd_bar(struct MPContext *mpctx, char **line, int width)
|
||||
{
|
||||
struct MPOpts *opts = mpctx->opts;
|
||||
|
||||
if (width < 5)
|
||||
return;
|
||||
|
||||
int pos = get_percent_pos(mpctx) / 100.0 * (width - 2);
|
||||
|
||||
bstr chars = bstr0(opts->term_osd_bar_chars);
|
||||
bstr parts[5];
|
||||
for (int n = 0; n < 5; n++)
|
||||
parts[n] = bstr_split_utf8(chars, &chars);
|
||||
|
||||
saddf(line, "%.*s", BSTR_P(parts[0]));
|
||||
for (int n = 0; n < pos; n++)
|
||||
saddf(line, "%.*s", BSTR_P(parts[1]));
|
||||
saddf(line, "%.*s", BSTR_P(parts[2]));
|
||||
for (int n = 0; n < width - 2 - pos - 1; n++)
|
||||
saddf(line, "%.*s", BSTR_P(parts[3]));
|
||||
saddf(line, "%.*s", BSTR_P(parts[4]));
|
||||
}
|
||||
|
||||
void print_status(struct MPContext *mpctx)
|
||||
{
|
||||
struct MPOpts *opts = mpctx->opts;
|
||||
@ -182,6 +205,12 @@ void print_status(struct MPContext *mpctx)
|
||||
if (cache >= 0)
|
||||
saddf(&line, " Cache: %d%%", cache);
|
||||
|
||||
if (opts->term_osd_bar) {
|
||||
saddf(&line, "\n");
|
||||
get_screen_size();
|
||||
add_term_osd_bar(mpctx, &line, screen_width);
|
||||
}
|
||||
|
||||
// end
|
||||
term_osd_set_status(mpctx, line);
|
||||
talloc_free(line);
|
||||
|
Loading…
Reference in New Issue
Block a user