Skip to content

Commit

Permalink
console.lua: highlight the select menu's preselected item
Browse files Browse the repository at this point in the history
Requested in
mpv-player#14087 (comment) and
mpv-player#15031 (comment)

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
  • Loading branch information
guidocella committed Oct 9, 2024
1 parent d92c518 commit 314a1c6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ local terminal_styles = {
error = '\027[31m',
fatal = '\027[91m',
selected_suggestion = '\027[7m',
default_item = '\027[1m',
disabled = '\027[38;5;8m',
}

Expand Down Expand Up @@ -108,6 +109,7 @@ local completion_old_cursor
local selectable_items
local matches = {}
local selected_match = 1
local default_match
local first_match_to_print = 1

local set_active
Expand Down Expand Up @@ -453,11 +455,23 @@ local function populate_log_with_matches(max_width)
end

for i = first_match_to_print, last_match_to_print do
local style = ''
local terminal_style = ''

if i == selected_match then
style = styles.selected_suggestion
terminal_style = terminal_styles.selected_suggestion
end
if i == default_match then
style = style .. styles.warn
terminal_style = terminal_style .. terminal_styles.default_item
end

log[#log + 1] = {
text = (max_width and truncate_utf8(matches[i].text, max_width)
or matches[i].text),
style = i == selected_match and styles.selected_suggestion or '',
terminal_style = i == selected_match and terminal_styles.selected_suggestion or '',
style = style,
terminal_style = terminal_style,
}
end

Expand Down Expand Up @@ -1805,6 +1819,7 @@ mp.register_script_message('get-input', function (script_name, args)
if selectable_items then
matches = {}
selected_match = args.default_item or 1
default_match = args.default_item
first_match_to_print = 1
for i, item in ipairs(selectable_items) do
matches[i] = { index = i, text = item }
Expand Down

0 comments on commit 314a1c6

Please sign in to comment.