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.
This makes console and mp.input users enable IME when text input is
active and restore IME to the previous state when text input is inactive,
to ensure the best IME mode is selected based on input context.
The default item also has the same background color but with
transparency.
Also stop bolding selections since inverted black and white backgrounds
should be visible even with color blindness. It was annoying with
proportional fonts because it misalignes similar strings.
As mpv's default text colors are white on black border or background,
--osd-selected-color's default of a bright yellow meant to be used with
a black border becomes unreadable with the inverted white background.
We could default to a dark --osd-selected-color and a a light
--osd-selected-outline-color and use --osd-selected-outline-color as the
selected back color. However in show-text commands having only the
selected item with a different white border doesn't look good.
This therefore adds indipendent selected_color and selected_back_color
script-opts. --osd-selected-color is only used for completions and for
the selected item when searching the command history with
outline-and-shadow.
This reverts commit ad0c29e5ac.
This should be unnecessary now that the menu has a visible horizontal
and vertical hitbox, and was not discoverable anyway. Right click can be
useful even while the console is open to pause or open a context menu.
Requested in
https://github.com/mpv-player/mpv/pull/15145#issuecomment-2428032616.
Draw a background behind selectable items even with outline-and-shadow.
This makes sense for a menu because you want it to be readable, select
something and move on. It doesn't stay open while watching like OSD
messages and subtitles, so it can cover more of the video. In fact this
was probably the only menu without a background by default. Also the
scrollbar without a background looked weird, and the background shows
the new horizontal hit box.
--osd-outline-color determines the background color with
outline-and-shadow, while --osd-back-color determines the background
color with background-box. Some transparency is added because using pure
black is not recommended because it causes eye strain; alternatively
--osd-outline-color could default to #222222.
Drawing the background ourselves also allows making the corners rounded.
Free-form text mode keeps using only background-box backgrounds if
configured as covering the whole screen while searching stats key
bindings would be bad. Searching history also doesn't add a background
to not change the layout abruptly. When searching history with
background-box, it preserves the alpha component of --osd-back-color.
Add a scrollbar to give a visual representation of the size and position
in the items. It is not clickable.
The counter is moved above the scrollbar to free up a line for an
another item, simplify calculations, and prevent the selected item from
jumping from the second to the first line as you type.
In terminal output there is no easy way to draw a scrollbar to the right
due to Unicode widths. This just moves the counter into the prompt.