-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
Download the artifacts for this pull request: |
@@ -390,6 +390,11 @@ local function fuzzy_find(needle, haystacks) | |||
return result | |||
end | |||
|
|||
local function mpv_color_to_ass(color) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) : ""; |
There was a problem hiding this comment.
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) : ""; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
video/out/vo_tct.c
Outdated
@@ -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)); |
There was a problem hiding this comment.
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.
330efce
to
7702b78
Compare
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)) |
There was a problem hiding this comment.
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.
c4464ea
to
f5badf3
Compare
player/command.c
Outdated
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); |
There was a problem hiding this comment.
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.
f5badf3
to
8c8785b
Compare
@@ -4592,6 +4592,14 @@ OSD | |||
Specify the color used for OSD. | |||
See ``--sub-color`` for details. | |||
|
|||
``--osd-selected-color=<color>`` |
There was a problem hiding this comment.
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?
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.