Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command: highlight selected list items with color #15286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/selected-style.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `--osd-selected-color` and `--osd-selected-outline-color` options
8 changes: 8 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4582,6 +4582,14 @@ OSD
Specify the color used for OSD.
See ``--sub-color`` for details.

``--osd-selected-color=<color>``
The color of the selected item in lists.
See ``--sub-color`` for details.

``--osd-selected-outline-color=<color>``
The outline color of the selected item in lists.
See ``--sub-color`` for details.

``--osd-fractions``
Show OSD times with fractions of seconds (in millisecond precision). Useful
to see the exact timestamp of a video frame.
Expand Down
4 changes: 4 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ const struct m_sub_options mp_osd_render_sub_opts = {
{"osd", OPT_SUBSTRUCT(osd_style, osd_style_conf)},
{"osd-scale", OPT_FLOAT(osd_scale), M_RANGE(0, 100)},
{"osd-scale-by-window", OPT_BOOL(osd_scale_by_window)},
{"osd-selected-color", OPT_COLOR(osd_selected_color)},
{"osd-selected-outline-color", OPT_COLOR(osd_selected_outline_color)},
{"force-rgba-osd-rendering", OPT_BOOL(force_rgba_osd)},
{0}
},
Expand All @@ -438,6 +440,8 @@ const struct m_sub_options mp_osd_render_sub_opts = {
.osd_bar_marker_style = 1,
.osd_scale = 1,
.osd_scale_by_window = true,
.osd_selected_color = {250, 189, 47, 255},
.osd_selected_outline_color = {0, 0, 0, 255},
},
.change_flags = UPDATE_OSD,
};
Expand Down
2 changes: 2 additions & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ struct mp_osd_render_opts {
int osd_bar_marker_style;
float osd_scale;
bool osd_scale_by_window;
struct m_color osd_selected_color;
struct m_color osd_selected_outline_color;
struct osd_style_opts *osd_style;
bool force_rgba_osd;
};
Expand Down
3 changes: 3 additions & 0 deletions osdep/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#define TERM_ESC_ENABLE_MOUSE "\033[?1003h"
#define TERM_ESC_DISABLE_MOUSE "\033[?1003l"

#define TERM_ESC_REVERSE_COLORS "\033[7m"
#define TERM_ESC_CLEAR_COLORS "\033[0m"

struct input_ctx;

/* Global initialization for terminal output. */
Expand Down
48 changes: 38 additions & 10 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "common/common.h"
#include "input/input.h"
#include "input/keycodes.h"
#include "sub/osd_state.h"
#include "stream/stream.h"
#include "demux/demux.h"
#include "demux/stheader.h"
Expand Down Expand Up @@ -304,6 +305,30 @@ void mark_seek(struct MPContext *mpctx)
cmd->last_seek_time = now;
}

static char *get_selected_style(struct MPContext *mpctx, void *ctx)
{
return mpctx->video_out && mpctx->opts->video_osd
? talloc_asprintf(ctx, "%s{\\b1\\1c&H%x%x%x&\\1a&H%x&\\3c&H%x%x%x&\\3a&H%x&}%s",
OSD_ASS_0,
mpctx->video_out->osd->opts->osd_selected_color.b,
mpctx->video_out->osd->opts->osd_selected_color.g,
mpctx->video_out->osd->opts->osd_selected_color.r,
255 - mpctx->video_out->osd->opts->osd_selected_color.a,
mpctx->video_out->osd->opts->osd_selected_outline_color.b,
mpctx->video_out->osd->opts->osd_selected_outline_color.g,
mpctx->video_out->osd->opts->osd_selected_outline_color.r,
255 - mpctx->video_out->osd->opts->osd_selected_outline_color.a,
OSD_ASS_1)
: TERM_ESC_REVERSE_COLORS;
}

static char *get_style_reset(struct MPContext *mpctx)
{
return mpctx->video_out && mpctx->opts->video_osd
? OSD_ASS_0"{\\r}"OSD_ASS_1
: TERM_ESC_CLEAR_COLORS;
}

static char *skip_n_lines(char *text, int lines)
{
while (text && lines > 0) {
Expand Down Expand Up @@ -1056,10 +1081,11 @@ static int mp_property_list_chapters(void *ctx, struct m_property *prop,
char *name = chapter_name(mpctx, n);
double t = chapter_start_time(mpctx, n);
char* time = mp_format_time(t, false);
res = talloc_asprintf_append(res, "%s", time);
const char *selected_style = n == cur ? get_selected_style(mpctx, res) : "";
const char *reset = n == cur ? get_style_reset(mpctx) : "";
res = talloc_asprintf_append(res, "%s%s %s%s\n", selected_style,
time, name, reset);
talloc_free(time);
const char *m = n == cur ? list_current : list_normal;
res = talloc_asprintf_append(res, " %s%s\n", m, name);
}

*(char **)arg = count ? cut_osd_list(mpctx, "Chapters", res, cur) : res;
Expand Down Expand Up @@ -1164,13 +1190,14 @@ static int property_list_editions(void *ctx, struct m_property *prop,
for (int n = 0; n < num_editions; n++) {
struct demux_edition *ed = &editions[n];

res = talloc_strdup_append(res, n == current ? list_current
: list_normal);
if (n == current)
res = talloc_strdup_append(res, get_selected_style(mpctx, res));
res = talloc_asprintf_append(res, "%d: ", n);
char *title = mp_tags_get_str(ed->metadata, "title");
if (!title)
title = "unnamed";
res = talloc_asprintf_append(res, "'%s'\n", title);
const char *reset = n == current ? get_style_reset(mpctx) : "";
res = talloc_asprintf_append(res, "'%s'%s\n", title, reset);
}

*(char **)arg = res;
Expand Down Expand Up @@ -3401,8 +3428,9 @@ static int mp_property_playlist(void *ctx, struct m_property *prop,

for (int n = 0; n < pl->num_entries; n++) {
struct playlist_entry *e = pl->entries[n];
res = talloc_strdup_append(res, pl->current == e ? list_current
: list_normal);
if (pl->current == e)
res = talloc_strdup_append(res, get_selected_style(mpctx, res));
const char *reset = pl->current == e ? get_style_reset(mpctx) : "";
char *p = e->title;
if (!p || mpctx->opts->playlist_entry_name > 0) {
p = e->filename;
Expand All @@ -3413,9 +3441,9 @@ static int mp_property_playlist(void *ctx, struct m_property *prop,
}
}
if (!e->title || p == e->title || mpctx->opts->playlist_entry_name == 1) {
res = talloc_asprintf_append(res, "%s\n", p);
res = talloc_asprintf_append(res, "%s%s\n", p, reset);
} else {
res = talloc_asprintf_append(res, "%s (%s)\n", e->title, p);
res = talloc_asprintf_append(res, "%s (%s)%s\n", e->title, p, reset);
}
}

Expand Down
21 changes: 15 additions & 6 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ local function fuzzy_find(needle, haystacks)
return result
end

local function mpv_color_to_ass(color)
return color:sub(8,9) .. color:sub(6,7) .. color:sub(4,5),
string.format('%x', 255 - tonumber('0x' .. color:sub(2,3)))
end

local function populate_log_with_matches()
if not selectable_items or selected_match == 0 then
return
Expand Down Expand Up @@ -431,13 +436,17 @@ local function populate_log_with_matches()
local style = ''
local terminal_style = ''

if i == selected_match then
style = styles.selected_suggestion
terminal_style = terminal_styles.selected_suggestion
end
if matches[i].index == default_item then
style = style .. styles.default_item
terminal_style = terminal_style .. terminal_styles.default_item
style = styles.default_item
terminal_style = terminal_styles.default_item
end
if i == selected_match then
local color, alpha = mpv_color_to_ass(mp.get_property('osd-selected-color'))
local outline_color, outline_alpha =
mpv_color_to_ass(mp.get_property('osd-selected-outline-color'))
style = style .. "{\\b1\\1c&H" .. color .. "&\\1a&H" .. alpha ..
"&\\3c&H" .. outline_color .. "&\\3a&H" .. outline_alpha .. "&}"
terminal_style = terminal_style .. terminal_styles.selected_suggestion
end

log[#log + 1] = {
Expand Down
5 changes: 2 additions & 3 deletions video/out/vo_tct.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#define DEFAULT_WIDTH 80
#define DEFAULT_HEIGHT 25

static const bstr TERM_ESC_CLEAR_COLORS = bstr0_lit("\033[0m");
static const bstr TERM_ESC_COLOR256_BG = bstr0_lit("\033[48;5");
static const bstr TERM_ESC_COLOR256_FG = bstr0_lit("\033[38;5");
static const bstr TERM_ESC_COLOR24BIT_BG = bstr0_lit("\033[48;2");
Expand Down Expand Up @@ -160,7 +159,7 @@ static void write_plain(bstr *frame,
if (buffering <= VO_TCT_BUFFER_PIXEL)
print_buffer(frame);
}
bstr_xappend(NULL, frame, TERM_ESC_CLEAR_COLORS);
bstr_xappend(NULL, frame, (bstr)bstr0_lit(TERM_ESC_CLEAR_COLORS));
if (buffering <= VO_TCT_BUFFER_LINE)
print_buffer(frame);
}
Expand Down Expand Up @@ -197,7 +196,7 @@ static void write_half_blocks(bstr *frame,
if (buffering <= VO_TCT_BUFFER_PIXEL)
print_buffer(frame);
}
bstr_xappend(NULL, frame, TERM_ESC_CLEAR_COLORS);
bstr_xappend(NULL, frame, (bstr)bstr0_lit(TERM_ESC_CLEAR_COLORS));
if (buffering <= VO_TCT_BUFFER_LINE)
print_buffer(frame);
}
Expand Down
Loading