From 45641378a2df4d5fe227ad7ba575b01f787ad8e8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 15 Jan 2014 16:14:37 +0100 Subject: 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. --- player/osd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'player') diff --git a/player/osd.c b/player/osd.c index b2062701ea..29ac7af8fe 100644 --- a/player/osd.c +++ b/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); -- cgit v1.2.3