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
#14087 (comment) and
#15031 (comment)

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
  • Loading branch information
guidocella authored and kasper93 committed Oct 14, 2024
1 parent ad0c29e commit 3e63c97
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ local styles = {
fatal = '{\\1c&H5791f9&}',
suggestion = '{\\1c&Hcc99cc&}',
selected_suggestion = '{\\1c&H2fbdfa&\\b1}',
default_item = '{\\1c&H2fbdfa&}',
disabled = '{\\1c&Hcccccc&}',
}

Expand All @@ -74,6 +75,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 @@ -109,6 +111,7 @@ local selectable_items
local matches = {}
local selected_match = 1
local first_match_to_print = 1
local default_item

local set_active

Expand Down Expand Up @@ -417,10 +420,22 @@ local function populate_log_with_matches()
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 matches[i].index == default_item then
style = style .. styles.default_item
terminal_style = terminal_style .. terminal_styles.default_item
end

log[#log + 1] = {
text = 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 @@ -1697,6 +1712,7 @@ set_active = function (active)
line = ''
cursor = 1
selectable_items = nil
default_item = nil
dont_bind_up_down = false
unbind_mouse()
end
Expand Down Expand Up @@ -1770,6 +1786,7 @@ mp.register_script_message('get-input', function (script_name, args)
if selectable_items then
matches = {}
selected_match = args.default_item or 1
default_item = 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 3e63c97

Please sign in to comment.