History

console.lua: add pause_on_open script-opt

Add a script-opt to pause when console opens and unpause when it closes, disabled by default. This is particularly useful for selectors that take several seconds to open so you don't have to guess when to pause, like the subtitle line selector with embedded subtitles, or my script which lets you select which lyrics to download after requesting them with curl.

Guido Cella committed 1 year ago

Commit 850e03d1 parent 44384aa3 files · +22 −0Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/console-pause-on-open.rst +1 −0
  2. DOCS/man/console.rst +6 −0
  3. player/lua/console.lua +15 −0
DOCS/interface-changes/console-pause-on-open.rst+1−0
@@ -0,0 +1 @@
1add `console-pause_on_open` script-opt
DOCS/man/console.rst+6−0
@@ -200,3 +200,9 @@ Configurable Options · 199 unmodified lines
200 The ratio of font height to font width.200 The ratio of font height to font width.
201 Adjusts table width of completion suggestions.201 Adjusts table width of completion suggestions.
202 Values in the range 1.8..2.5 make sense for common monospace fonts.202 Values in the range 1.8..2.5 make sense for common monospace fonts.
203
204``pause_on_open``
205 Default: no
206
207 Whether to pause playback when the console opens, and resume it when the
208 console is closed, if playback was not already paused.
player/lua/console.lua+15−0
@@ -38,6 +38,7 @@ local opts = { · 37 unmodified lines
38 case_sensitive = platform ~= 'windows' and true or false,38 case_sensitive = platform ~= 'windows' and true or false,
39 history_dedup = true,39 history_dedup = true,
40 font_hw_ratio = 'auto',40 font_hw_ratio = 'auto',
41 pause_on_open = false,
41}42}
42 43
43local styles = {44local styles = {
@@ -89,6 +90,7 @@ local log_buffers = {[id] = {}} · 45 unmodified lines
89local key_bindings = {}90local key_bindings = {}
90local dont_bind_up_down = false91local dont_bind_up_down = false
91local global_margins = { t = 0, b = 0 }92local global_margins = { t = 0, b = 0 }
93local was_playing = true
92local input_caller94local input_caller
93 95
94local suggestion_buffer = {}96local suggestion_buffer = {}
@@ -1721,12 +1723,21 @@ local function undefine_key_bindings() · 1626 unmodified lines
1721 key_bindings = {}1723 key_bindings = {}
1722end1724end
1723 1725
1726local function pause_playback()
1727 was_playing = not mp.get_property_native('pause')
1728
1729 if opts.pause_on_open and was_playing then
1730 mp.set_property_native('pause', true)
1731 end
1732end
1733
1724-- Set the REPL visibility ("enable", Esc)1734-- Set the REPL visibility ("enable", Esc)
1725set_active = function (active)1735set_active = function (active)
1726 if active == repl_active then return end1736 if active == repl_active then return end
1727 if active then1737 if active then
1728 repl_active = true1738 repl_active = true
1729 insert_mode = false1739 insert_mode = false
1740 pause_playback()
1730 define_key_bindings()1741 define_key_bindings()
1731 1742
1732 if not input_caller then1743 if not input_caller then
@@ -1744,6 +1755,10 @@ set_active = function (active) · 11 unmodified lines
1744 log_buffers[id] = {}1755 log_buffers[id] = {}
1745 unbind_mouse()1756 unbind_mouse()
1746 else1757 else
1758 if opts.pause_on_open and was_playing then
1759 mp.set_property_native('pause', false)
1760 end
1761
1747 repl_active = false1762 repl_active = false
1748 suggestion_buffer = {}1763 suggestion_buffer = {}
1749 undefine_key_bindings()1764 undefine_key_bindings()

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