History

console.lua: highlight the select menu's preselected item

Requested in https://github.com/mpv-player/mpv/pull/14087#issuecomment-2110889436 and https://github.com/mpv-player/mpv/pull/15031#issuecomment-2401328081 This is mainly useful to keep highlighting the current playlist entry after moving the mouse.

Guido Cella committed 2 years ago

Commit 3e63c971 parent ad0c29e1 file · +19 −2Browse files

Showing the changes to player/lua/console.lua (1 of 1 file). Show all

Unified · Split

player/lua/console.lua+19−2
@@ -64,6 +64,7 @@ local styles = { · 63 unmodified lines
64 fatal = '{\\1c&H5791f9&}',64 fatal = '{\\1c&H5791f9&}',
65 suggestion = '{\\1c&Hcc99cc&}',65 suggestion = '{\\1c&Hcc99cc&}',
66 selected_suggestion = '{\\1c&H2fbdfa&\\b1}',66 selected_suggestion = '{\\1c&H2fbdfa&\\b1}',
67 default_item = '{\\1c&H2fbdfa&}',
67 disabled = '{\\1c&Hcccccc&}',68 disabled = '{\\1c&Hcccccc&}',
68}69}
69 70
@@ -74,6 +75,7 @@ local terminal_styles = { · 4 unmodified lines
74 error = '\027[31m',75 error = '\027[31m',
75 fatal = '\027[91m',76 fatal = '\027[91m',
76 selected_suggestion = '\027[7m',77 selected_suggestion = '\027[7m',
78 default_item = '\027[1m',
77 disabled = '\027[38;5;8m',79 disabled = '\027[38;5;8m',
78}80}
79 81
@@ -109,6 +111,7 @@ local selectable_items · 29 unmodified lines
109local matches = {}111local matches = {}
110local selected_match = 1112local selected_match = 1
111local first_match_to_print = 1113local first_match_to_print = 1
114local default_item
112 115
113local set_active116local set_active
114 117
@@ -417,10 +420,22 @@ local function populate_log_with_matches() · 302 unmodified lines
417 end420 end
418 421
419 for i = first_match_to_print, last_match_to_print do422 for i = first_match_to_print, last_match_to_print do
423 local style = ''
424 local terminal_style = ''
425
426 if i == selected_match then
427 style = styles.selected_suggestion
428 terminal_style = terminal_styles.selected_suggestion
429 end
430 if matches[i].index == default_item then
431 style = style .. styles.default_item
432 terminal_style = terminal_style .. terminal_styles.default_item
433 end
434
420 log[#log + 1] = {435 log[#log + 1] = {
421 text = matches[i].text,436 text = matches[i].text,
422 style = i == selected_match and styles.selected_suggestion or '',437 style = style,
423 terminal_style = i == selected_match and terminal_styles.selected_suggestion or '',438 terminal_style = terminal_style,
424 }439 }
425 end440 end
426 441
@@ -1697,6 +1712,7 @@ set_active = function (active) · 1270 unmodified lines
1697 line = ''1712 line = ''
1698 cursor = 11713 cursor = 1
1699 selectable_items = nil1714 selectable_items = nil
1715 default_item = nil
1700 dont_bind_up_down = false1716 dont_bind_up_down = false
1701 unbind_mouse()1717 unbind_mouse()
1702 end1718 end
@@ -1770,6 +1786,7 @@ mp.register_script_message('get-input', function (script_name, args) · 67 unmodified lines
1770 if selectable_items then1786 if selectable_items then
1771 matches = {}1787 matches = {}
1772 selected_match = args.default_item or 11788 selected_match = args.default_item or 1
1789 default_item = args.default_item
1773 first_match_to_print = 11790 first_match_to_print = 1
1774 for i, item in ipairs(selectable_items) do1791 for i, item in ipairs(selectable_items) do
1775 matches[i] = { index = i, text = item }1792 matches[i] = { index = i, text = item }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t