mirror of
https://github.com/mpv-player/mpv.git
synced 2026-05-07 20:02:49 +00:00
console.lua: say focused instead of selected
The selected term was causing confusion e.g. in https://github.com/mpv-player/mpv/pull/15711#issuecomment-2676060139. Saying either focused or current makes more sense since the item is not actually selected until you click or press Enter.
This commit is contained in:
committed by
Kacper Michajłow
parent
1f809734b2
commit
42660a8c23
@@ -0,0 +1,2 @@
|
||||
rename `console-selected_color` script-opt to `console-focused_color`
|
||||
rename `console-selected_back_color` script-opt to `console-focused_back_color`
|
||||
@@ -184,15 +184,15 @@ Configurable Options
|
||||
Whether to scale the console with the window height. Can be ``yes``, ``no``,
|
||||
or ``auto``, which follows the value of ``--osd-scale-by-window``.
|
||||
|
||||
``selected_color``
|
||||
``focused_color``
|
||||
Default: ``#222222``
|
||||
|
||||
The color of the selected item.
|
||||
The color of the focused item.
|
||||
|
||||
``selected_back_color``
|
||||
``focused_back_color``
|
||||
Default: ``#FFFFFF``
|
||||
|
||||
The background color of the selected item.
|
||||
The background color of the focused item.
|
||||
|
||||
``match_color``
|
||||
Default: ``#0088FF``
|
||||
|
||||
+5
-5
@@ -14,13 +14,13 @@ When using ``mp.input.select``, the key bindings listed in `CONSOLE`_ are
|
||||
extended with the following:
|
||||
|
||||
ENTER, Ctrl+j and Ctrl+m
|
||||
Confirm the selection of the highlighted item.
|
||||
Select the focused item.
|
||||
|
||||
UP and Ctrl+p
|
||||
Select the item above, or the last one when the first item is selected.
|
||||
Focus the item above, or the last one when the first item is selected.
|
||||
|
||||
DOWN and Ctrl+n
|
||||
Select the item below, or the first one when the last item is selected.
|
||||
Focus the item below, or the first one when the last item is selected.
|
||||
|
||||
PGUP and Ctrl+b
|
||||
Scroll up one page.
|
||||
@@ -29,8 +29,8 @@ PGDN and Ctrl+f
|
||||
Scroll down one page.
|
||||
|
||||
MBTN_LEFT
|
||||
Confirm the selection of the highlighted item, or close the console if
|
||||
clicking outside of the menu rectangle.
|
||||
Select the item under the cursor, or close the console if clicking outside
|
||||
of the menu rectangle.
|
||||
|
||||
WHEEL_UP
|
||||
Scroll up.
|
||||
|
||||
+48
-36
@@ -40,13 +40,15 @@ local opts = {
|
||||
margin_x = -1,
|
||||
margin_y = -1,
|
||||
scale_with_window = "auto",
|
||||
selected_color = "#222222",
|
||||
selected_back_color = "#FFFFFF",
|
||||
focused_color = "#222222",
|
||||
focused_back_color = "#FFFFFF",
|
||||
match_color = "#0088FF",
|
||||
exact_match = false,
|
||||
case_sensitive = false,
|
||||
history_dedup = true,
|
||||
font_hw_ratio = "auto",
|
||||
selected_color = "",
|
||||
selected_back_color = "",
|
||||
}
|
||||
|
||||
local styles = {
|
||||
@@ -103,7 +105,7 @@ local has_completions
|
||||
|
||||
local selectable_items
|
||||
local matches = {}
|
||||
local selected_match = 1
|
||||
local focused_match = 1
|
||||
local first_match_to_print = 1
|
||||
local default_item
|
||||
local item_positions = {}
|
||||
@@ -514,7 +516,7 @@ local function find_matches(needle, haystacks)
|
||||
end
|
||||
|
||||
local function get_matches_to_print(terminal)
|
||||
if not selectable_items or selected_match == 0 then
|
||||
if not selectable_items or focused_match == 0 then
|
||||
return {}
|
||||
end
|
||||
|
||||
@@ -524,10 +526,10 @@ local function get_matches_to_print(terminal)
|
||||
local highlight = terminal and terminal_styles.matched_position or
|
||||
"{\\1c&H" .. option_color_to_ass(opts.match_color) .. "}"
|
||||
|
||||
if selected_match < first_match_to_print then
|
||||
first_match_to_print = selected_match
|
||||
elseif selected_match > first_match_to_print + max_lines - 1 then
|
||||
first_match_to_print = selected_match - max_lines + 1
|
||||
if focused_match < first_match_to_print then
|
||||
first_match_to_print = focused_match
|
||||
elseif focused_match > first_match_to_print + max_lines - 1 then
|
||||
first_match_to_print = focused_match - max_lines + 1
|
||||
end
|
||||
|
||||
local last_match_to_print = math.min(first_match_to_print + max_lines - 1,
|
||||
@@ -541,16 +543,16 @@ local function get_matches_to_print(terminal)
|
||||
if matches[i].index == default_item then
|
||||
item = terminal_styles.default_item
|
||||
end
|
||||
if i == selected_match then
|
||||
if i == focused_match then
|
||||
item = item .. terminal_styles.selected_completion
|
||||
end
|
||||
else
|
||||
if i == selected_match then
|
||||
if i == focused_match then
|
||||
if searching_history and
|
||||
mp.get_property("osd-border-style") == "outline-and-shadow" then
|
||||
item = get_selected_ass()
|
||||
else
|
||||
item = "{\\1c&H" .. option_color_to_ass(opts.selected_color) .. "&}"
|
||||
item = "{\\1c&H" .. option_color_to_ass(opts.focused_color) .. "&}"
|
||||
end
|
||||
end_highlight = item
|
||||
end
|
||||
@@ -632,7 +634,7 @@ local function print_to_terminal()
|
||||
if #selectable_items > calculate_max_lines() then
|
||||
local digits = math.ceil(math.log(#selectable_items, 10))
|
||||
counter = terminal_styles.disabled ..
|
||||
"[" .. string.format("%0" .. digits .. "d", selected_match) ..
|
||||
"[" .. string.format("%0" .. digits .. "d", focused_match) ..
|
||||
"/" .. string.format("%0" .. digits .. "d", #matches) ..
|
||||
"]\027[0m "
|
||||
end
|
||||
@@ -800,15 +802,15 @@ local function render()
|
||||
and y + (1 + i) * line_height
|
||||
or y - (1.5 + #items - i) * line_height
|
||||
|
||||
if (first_match_to_print - 1 + i == selected_match or
|
||||
if (first_match_to_print - 1 + i == focused_match or
|
||||
matches[first_match_to_print - 1 + i].index == default_item)
|
||||
and (not searching_history or border_style == "background-box") then
|
||||
ass:new_event()
|
||||
ass:an(4)
|
||||
ass:pos(x, item_y)
|
||||
ass:append("{\\blur0\\bord0\\4aH&ff&\\1c&H" ..
|
||||
option_color_to_ass(opts.selected_back_color) .. "&}")
|
||||
if first_match_to_print - 1 + i ~= selected_match then
|
||||
option_color_to_ass(opts.focused_back_color) .. "&}")
|
||||
if first_match_to_print - 1 + i ~= focused_match then
|
||||
ass:append("{\\1aH&cc&}")
|
||||
end
|
||||
ass:draw_start()
|
||||
@@ -834,7 +836,7 @@ local function render()
|
||||
if not searching_history or border_style == "background-box" then
|
||||
ass:append("{\\bord0\\4a&Hff&\\blur0}")
|
||||
end
|
||||
ass:append(selected_match .. "/" .. #matches)
|
||||
ass:append(focused_match .. "/" .. #matches)
|
||||
|
||||
local start_percentage = (first_match_to_print - 1) / #matches
|
||||
local end_percentage = (first_match_to_print - 1 + max_lines) / #matches
|
||||
@@ -944,15 +946,15 @@ local function handle_edit()
|
||||
end
|
||||
|
||||
if line == "" and default_item then
|
||||
selected_match = default_item
|
||||
focused_match = default_item
|
||||
|
||||
local max_lines = calculate_max_lines()
|
||||
first_match_to_print = math.max(1, selected_match + 1 - math.ceil(max_lines / 2))
|
||||
first_match_to_print = math.max(1, focused_match + 1 - math.ceil(max_lines / 2))
|
||||
if first_match_to_print > #selectable_items - max_lines + 1 then
|
||||
first_match_to_print = math.max(1, #selectable_items - max_lines + 1)
|
||||
end
|
||||
else
|
||||
selected_match = 1
|
||||
focused_match = 1
|
||||
end
|
||||
|
||||
render()
|
||||
@@ -1031,7 +1033,7 @@ local function submit()
|
||||
if searching_history then
|
||||
searching_history = false
|
||||
selectable_items = nil
|
||||
line = #matches > 0 and matches[selected_match].text or ""
|
||||
line = #matches > 0 and matches[focused_match].text or ""
|
||||
cursor = #line + 1
|
||||
handle_edit()
|
||||
unbind_mouse()
|
||||
@@ -1041,7 +1043,7 @@ local function submit()
|
||||
if selectable_items then
|
||||
if #matches > 0 then
|
||||
mp.commandv("script-message-to", input_caller, "input-event", "submit",
|
||||
utils.format_json({matches[selected_match].index}))
|
||||
utils.format_json({matches[focused_match].index}))
|
||||
end
|
||||
else
|
||||
if selected_completion_index == 0 and autoselect_completion then
|
||||
@@ -1084,8 +1086,8 @@ end
|
||||
local function bind_mouse()
|
||||
mp.add_forced_key_binding("MOUSE_MOVE", "_console_mouse_move", function()
|
||||
local item = determine_hovered_item()
|
||||
if item and item ~= selected_match then
|
||||
selected_match = item
|
||||
if item and item ~= focused_match then
|
||||
focused_match = item
|
||||
render()
|
||||
end
|
||||
end)
|
||||
@@ -1093,7 +1095,7 @@ local function bind_mouse()
|
||||
mp.add_forced_key_binding("MBTN_LEFT", "_console_mbtn_left", function()
|
||||
local item = determine_hovered_item()
|
||||
if item then
|
||||
selected_match = item
|
||||
focused_match = item
|
||||
submit()
|
||||
else
|
||||
set_active(false)
|
||||
@@ -1146,13 +1148,13 @@ local function move_history(amount, is_wheel)
|
||||
if is_wheel then
|
||||
local max_lines = calculate_max_lines()
|
||||
|
||||
-- Update selected_match only if it's the first or last printed item and
|
||||
-- Update focused_match only if it's the first or last printed item and
|
||||
-- there are hidden items.
|
||||
if (amount > 0 and selected_match == first_match_to_print
|
||||
if (amount > 0 and focused_match == first_match_to_print
|
||||
and first_match_to_print - 1 + max_lines < #matches)
|
||||
or (amount < 0 and selected_match == first_match_to_print - 1 + max_lines
|
||||
or (amount < 0 and focused_match == first_match_to_print - 1 + max_lines
|
||||
and first_match_to_print > 1) then
|
||||
selected_match = selected_match + amount
|
||||
focused_match = focused_match + amount
|
||||
end
|
||||
|
||||
if amount > 0 and first_match_to_print < #matches - max_lines + 1
|
||||
@@ -1165,18 +1167,18 @@ local function move_history(amount, is_wheel)
|
||||
|
||||
local item = determine_hovered_item()
|
||||
if item then
|
||||
selected_match = item
|
||||
focused_match = item
|
||||
end
|
||||
|
||||
render()
|
||||
return
|
||||
end
|
||||
|
||||
selected_match = selected_match + amount
|
||||
if selected_match > #matches then
|
||||
selected_match = 1
|
||||
elseif selected_match < 1 then
|
||||
selected_match = #matches
|
||||
focused_match = focused_match + amount
|
||||
if focused_match > #matches then
|
||||
focused_match = 1
|
||||
elseif focused_match < 1 then
|
||||
focused_match = #matches
|
||||
end
|
||||
render()
|
||||
end
|
||||
@@ -1184,7 +1186,7 @@ end
|
||||
-- Go to the first command in the command history (PgUp)
|
||||
local function handle_pgup()
|
||||
if selectable_items then
|
||||
selected_match = math.max(selected_match - calculate_max_lines() + 1, 1)
|
||||
focused_match = math.max(focused_match - calculate_max_lines() + 1, 1)
|
||||
render()
|
||||
return
|
||||
end
|
||||
@@ -1195,7 +1197,7 @@ end
|
||||
-- Stop browsing history and start editing a blank line (PgDown)
|
||||
local function handle_pgdown()
|
||||
if selectable_items then
|
||||
selected_match = math.min(selected_match + calculate_max_lines() - 1, #matches)
|
||||
focused_match = math.min(focused_match + calculate_max_lines() - 1, #matches)
|
||||
render()
|
||||
return
|
||||
end
|
||||
@@ -1780,4 +1782,14 @@ end)
|
||||
|
||||
require "mp.options".read_options(opts, nil, render)
|
||||
|
||||
if opts.selected_color ~= "" then
|
||||
opts.focused_color = opts.selected_color
|
||||
mp.msg.warn("selected_color has been replaced by focused_color")
|
||||
end
|
||||
|
||||
if opts.selected_back_color ~= "" then
|
||||
opts.focused_back_color = opts.selected_back_color
|
||||
mp.msg.warn("selected_back_color has been replaced by focused_back_color")
|
||||
end
|
||||
|
||||
collectgarbage()
|
||||
|
||||
Reference in New Issue
Block a user