If you open the menu at startup, e.g. with --input-commands, it rarely
clips items completely because OSD dimensions are still 0, or as if they
were 100 because those are the default values before receiving property
notifications. Avoid this.
The first completion is automatically inserted when Tab was not pressed,
but this is unwanted when you already typed one of the completions which
is not the first one, move back the cursor and press Enter.
e.g. if the line is "set vid", you place the cursor before "v" and press
Enter, it runs "set ab-loop-avid".
Fix this by aborting when the text in front of the cursor matches one of
the completions.
Make Ctrl+y copy the input line to the clipboard, or the currently
selected item in the menu.
The vi key to copy is used because Ctrl+c is already bound.
Alternative bindings are:
Ctrl+x to cut, but this also clears the line.
Ctrl+shift+c like in terminals, but this is harder to press, and this
commit works differently from terminals anyway since you don't manually
highlight characters, it just copies the whole line.
Alt+w, the emacs copy binding, but unless you use emacs this is weird
and unfamiliar.
case_sensitive originally only affected Tab completion. It defaulted to
yes outside of Windows just to emulate the bad defaults of bash and zsh
(not fish, which has better defaults and defaults to case-insensitive
completion). This was already silly, but then it affected the fuzzy
autocompletion and case-sensitive fuzzy completion is even more silly.
And since 0b3cc3a167, it accidentally stopped affecting even that,
because the completion via script message never checked for the option.
Nobody even noticed this, meaning that nobody was relying on fuzzy
autocompletion being case-sensitive.
Just make case_sensitive only affect the new exact search, and make it
default to no on all platforms. Though IMO the search could just always
be case-insensitive.
Allow matching items exactly instead of fuzzily when prefixing the
search with ' (like in fzf) or with
--script-opt=console-exact_match=yes.
This is mainly useful to filter history entries chronologically.
You can also specify multiple search terms delimited by spaces. But '
makes every term an exact match, unlike fzf where you need to place it
before every word, since we can't hook into fzy's algorithm.
Closes#14587.
Calling input.select() without a prompt argument was failing due to
attempting to concatenate a nil value.
Before mpv 0.40 the prompt defaulted to ">" so this is expected to
work as evident from the example code.
In retrospect, this isn't so great because not neccesarily everyone
would want the mouse to show with the menu and said menu can be
navigated with the keyboard anyway.
This reverts commit a8f5beb5a3.
This is an improvement on #15145 .
If the cursor is automatically hidden, users may not know whether
they are clicking on the inside or outside of selectable items,
the result after clicking is unclear to them.
Pressing ctrl+c in select mode crashes if console wasn't opened in
free-form text mode before.
This also makes the type of the history variable clear.
Fixes a6024b562a.
Those properties are already observed and trigger update, remember the
value to avoid re-fetching them.
This fixes delay caused by properties that synchronize GUI thread like
`focused` which takes 30+ ms in certain cases.
Co-authored-by: Guido Cella <guido@guidocella.xyz>
script-message-to commands type was passing cursor_position as a string,
which caused a crash if you e.g. moved the cursor afterwards. Convert it
to number in console so commands.lua and similar clients don't have to
manually convert it.
Currently --osd-font is the default for select, and a monospace font is
the default for free-form text mode. We can also default to the
proportional --osd-font for mp.input.get clients that don't specify
completions and thus don't need alignment, which is most clients.
In builtin scripts, this is the case for filtering stats key bindings.
With script-message-to commands type, instantly show completions if
available. Useful e.g. with loadfile or apply-profile.
This also shows completions if you just close the console with a filled
line and reopen it.
It was suggested by CogentRedTester in
https://github.com/mpv-player/mpv/pull/10282#issuecomment-1858727729 and
https://github.com/mpv-player/mpv/pull/10282#issuecomment-1858809580 and
by avih that making running commands an mp.input client is a better
architecture.
A practical advantage is that completions are calculated in a different
thread, which prevents hanging when completing slow/network filesystems.
script-binding console/enable becomes script-binding commands/open,
though the console one is kept as an alias. I took the opportunity to
rename this because open makes more sense for a graphical modal, and it
is the word used in mp.input and user-data.
script-message-to console type becomes script-message-to commands type,
though the console one is kept as an alias. It is also changed to
automatically close on submit without having to append '; keypress ESC'
as you don't need to keep the console open after running prefilled
commands.
Also convert to double quotes like other scripts and rename some
inconsistent functions.
Let the complete callback return the character to append to the selected
completion.
I didn't want to document this because it's specifically meant for
properties and unlikely to be needed by other scripts, but silently
interpreting the 3rd return value can screw you over if you do something
like
return candidates, code:find('[%w_]*$')
I was doing this in my lua-repl script, and find() returns the end
position as the 2rd argument, this becomes the 3rd return value and gets
appended to completions. So you have to do
return candidates, code:find('[%w_]*$'), nil
Needed to split running commands out of console.lua.
The overlay to calculate the max item width was never removed, so a new
one was added on each select call, adding 5-10 MBs of memory usage on
each menu opened.
Fix this by reusing the same overlay, which is also faster.
With input.select this allows building nested submenus without the
flicker of console quickly closing and reopening, and also doing
multiple selections, to e.g. cycle through different values of a
property, or increase a property multiple times.
With input.get this is used to change the default behavior to closing by
default on submit. It was argued by avih that this is more useful, and
indeed Github code search shows that everybody is calling
input.terminate() unconditionally on submit, so the impact of the change
should be low, and restoring the old behavior is as easy as passing
keep_open = true, which is just ignored in older mpv versions.
This needs to strike a fine balance between being visible and having
contrast with the text color and not taking attention away from the
selected item. Make it slightly more opaque to differentiate it more
easily.
Fixes#15711.
fzy returns which characters matched the search for every item, so use
this to highlight them.
This defaults to a light blue color that is readable with both black and
white (selected) backgrounds.
The returned positions are just bytes, so we can't put ASS tags or
escape sequences around each byte because that would break displaying
multibyte UTF-8 characters. Only put them around sequences of matched
positions, and only when the sequences start and end at actual character
positions.
The next commit will inject ASS within matching items to highlight
matching positions, which means that the text key of log lines can no
longer be used, and that matching items and log lines diverged enough
that it's simpler to separate them.
As a bonus, we can stop clearing the log and completions when searching
the command history, and restore them after the search.
When searching the command history with outline-and-shadow, the counter
should preserve the border, shadow and blur. Only with background-box it
should disable the shadow to not overlap 2 rectangles. While disabling
border and blur is needed with the menu background+outline-and-shadow.