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
6464 fatal = '{\\1c&H5791f9&}',
6565 suggestion = '{\\1c&Hcc99cc&}',
6666 selected_suggestion = '{\\1c&H2fbdfa&\\b1}',
67+ default_item = '{\\1c&H2fbdfa&}',
6768 disabled = '{\\1c&Hcccccc&}',
6869 }
6970
@@ -74,6 +75,7 @@ local terminal_styles = { · 4 unmodified lines
7475 error = '\027[31m',
7576 fatal = '\027[91m',
7677 selected_suggestion = '\027[7m',
78+ default_item = '\027[1m',
7779 disabled = '\027[38;5;8m',
7880 }
7981
@@ -109,6 +111,7 @@ local selectable_items · 29 unmodified lines
109111 local matches = {}
110112 local selected_match = 1
111113 local first_match_to_print = 1
114+local default_item
112115
113116 local set_active
114117
@@ -417,10 +420,22 @@ local function populate_log_with_matches() · 302 unmodified lines
417420 end
418421
419422 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+
420435 log[#log + 1] = {
421436 text = matches[i].text,
422− style = i == selected_match and styles.selected_suggestion or '',
423− terminal_style = i == selected_match and terminal_styles.selected_suggestion or '',
437+ style = style,
438+ terminal_style = terminal_style,
424439 }
425440 end
426441
@@ -1697,6 +1712,7 @@ set_active = function (active) · 1270 unmodified lines
16971712 line = ''
16981713 cursor = 1
16991714 selectable_items = nil
1715+ default_item = nil
17001716 dont_bind_up_down = false
17011717 unbind_mouse()
17021718 end
@@ -1770,6 +1786,7 @@ mp.register_script_message('get-input', function (script_name, args) · 67 unmodified lines
17701786 if selectable_items then
17711787 matches = {}
17721788 selected_match = args.default_item or 1
1789+ default_item = args.default_item
17731790 first_match_to_print = 1
17741791 for i, item in ipairs(selectable_items) do
17751792 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