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

Merged
merged 2 commits into from
Nov 27, 2024

Conversation

guidocella
Copy link
Contributor

@guidocella guidocella commented Nov 9, 2024

Instead of printing circles in show-text ${playlist}, ${chapter-list} and ${edition-list}, introduce --osd-selected-color and --osd-selected-outline-color to reduce clutter, make the selected item easier to differentiate, and have visual consistency with select.lua.

The defaults are taken from the style of the selected item in the console. These new options are also used there, replacing the hardcoded styles. Due to being user-configurable, selected item styles are changed to take priority over default item styles.

The default selected style is yellow and bold. The bold (hardcoded) allows differentiating the selected item with color blindness. There is also a separate --osd-selected-outline-color option defaulting to black, since without it if the user changes --osd-outline-color yellow text becomes unreadable without a black border. --osd-selected-back-color is omitted for now.

Text and background colors are inverted for the selected item in the terminal. This is hardcoded, adding an option is overkill.

A disadvantage of this commit is that if you run print-text ${playlist} with a VO, the selected style ASS is printed to the terminal (but ASS printed in the console is interpreted). This commit avoids printing the reset ASS sequence for non-selected items to reduce clutter in this case.

Copy link

github-actions bot commented Nov 9, 2024

Download the artifacts for this pull request:

Windows
macOS

player/command.c Outdated Show resolved Hide resolved
@@ -390,6 +390,11 @@ local function fuzzy_find(needle, haystacks)
return result
end

local function mpv_color_to_ass(color)
Copy link
Contributor

@kasper93 kasper93 Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be added to assdraw.lua?

player/command.c Outdated
: TERM_ESC_REVERSE_COLORS;
}

static char *get_style_reset(struct MPContext *mpctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be static const char *

player/command.c Outdated
@@ -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) : "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not freed anywhere.

player/command.c Outdated
@@ -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) : "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two spaces after =

player/command.c Outdated
res = talloc_strdup_append(res, n == current ? list_current
: list_normal);
if (n == current)
res = talloc_strdup_append(res, get_selected_style(mpctx, res));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_selected_style result is not freed

player/command.c Outdated
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_selected_style result is not freed

@@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add bstr_xappend0 in bstr.h, I've seen it used in other places too.

misc/bstr.h Outdated
@@ -150,6 +150,8 @@ struct bstr bstr_strip_linebreaks(struct bstr str);
*/
void bstr_xappend(void *talloc_ctx, bstr *s, bstr append);

#define bstr_xappend0(ctx, dst, s) bstr_xappend(ctx, dst, bstr0(s))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need parentheses around ctx and dst. Also generally we define it as inline functions in this header.

player/command.c Outdated
Comment on lines 1084 to 1087
char *selected_style = get_selected_style(mpctx, res);
res = talloc_strdup_append(res, selected_style);
if (mpctx->video_out && mpctx->opts->video_osd)
talloc_free(selected_style);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about instead get style, we do append style directly to res? So we avoid the need to keep track of the allocation and directly write to the result buffer?

Instead of printing circles in show-text ${playlist}, ${chapter-list}
and ${edition-list}, introduce --osd-selected-color and
--osd-selected-outline-color to reduce clutter, make the selected item
easier to differentiate, and have visual consistency with select.lua.

The defaults are taken from the style of the selected item in the
console. These new options are also used there, replacing the hardcoded
styles. Due to being user-configurable, selected item styles are changed
to take priority over default item styles.

The default selected style is yellow and bold. The bold (hardcoded)
allows differentiating the selected item with color blindness. There is
also a separate --osd-selected-outline-color option defaulting to black,
since without it if the user changes --osd-outline-color yellow text
becomes unreadable without a black border. --osd-selected-back-color is
omitted for now.

Text and background colors are inverted for the selected item in the
terminal. This is hardcoded, adding an option is overkill.

A disadvantage of this commit is that if you run print-text ${playlist}
with a VO, the selected style ASS is printed to the terminal (but ASS
printed in the console is interpreted). This commit avoids printing the
reset ASS sequence for non-selected items to reduce clutter in this
case.
@@ -4592,6 +4592,14 @@ OSD
Specify the color used for OSD.
See ``--sub-color`` for details.

``--osd-selected-color=<color>``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention default value?

@kasper93 kasper93 merged commit f7e2a8c into mpv-player:master Nov 27, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants