Commit Graph

197 Commits

Author SHA1 Message Date
Guido Cella 3c1ddc411c console.lua: fix completion after command prefixes
I'm not sure when this broke but completions after command prefixes were
not being updated.
2025-02-08 02:01:40 +00:00
Guido Cella b2404e16dd console.lua: stop expanding ~/ in file completion
It is not needed to expand ~ in file completion as you type after
62c3aeb9c made commands themselves interpret it. We only need to call
expand-path on the directory before passing it to utils.readdir in order
to find files in it when it contains ~ placeholders. As a bonus this
will now also complete files in directories like ~~/ and ~state/.

This simplifies command completion, and was also the blocker for
splitting running commands out of console.lua, since I didn't know how
to replicate it through mp.input.
2025-02-01 16:11:30 +00:00
Guido Cella cada717416 Revert "console.lua: add pause_on_open script-opt"
This reverts commit 850e03d29f.

The previous commit solved this in a more general way. You can do:

[open-console]
profile-cond=p['user-data/mpv/console/open'] and p['current-tracks/video/albumart'] == false
profile-restore=copy
pause

Thankfully pause_on_open was just added and has not been in a release so
we can remove it.
2025-01-31 06:04:54 +01:00
Guido Cella 8669205d92 console.lua: add user-data/mpv/console/open
Fixes #15762.
2025-01-31 06:04:54 +01:00
nanahi ab461e0209 console.lua: use clipboard property for native Wayland backend
This backend does not require the window focus quirk handling,
and also supports primary selection.
2025-01-27 18:51:31 +01:00
nanahi 3be195e616 console.lua: autocomplete clipboard/text-primary property 2025-01-27 18:51:31 +01:00
Guido Cella 04c328f784 console.lua: use the same blur amount as --osd-blur
I have no idea why, but console's blur is smaller than in OSD messages
and stats (regardless of persistent_overlay). It's smaller regardless of
scale_with_window, or if using 0 PlayRes like stats with
persistent_overlay=yes.

With scale_with_window=yes, multiplying the blur by 2.5 seems to make it
the same. This is probably because 2.5 is 720 / 288, which are the base
height sizes scale from and the OSD's PlayResY. With
scale_with_window=no, we need to multiply by osd_h, which is always 720
with scale_with_window=yes.
2025-01-25 03:14:59 +00:00
Guido Cella 5bbeabf450 console.lua: sort completions
With the previous commit, this sorts completions with the same score
alphabetically.
2025-01-24 04:35:27 +00:00
Guido Cella 8ae3beeb98 console.lua: preserve the order of items with equal score
table.sort() is unstable, meaning that it randomly reorders items with
the same score, so currently fuzzy_find() checks if the line is empty to
not change the original order of the unsorted items. But actually filled
lines have the same problem: e.g. searching foo with filenames like
foo_{1..99}, they are returned in random order.

To fix this sort by score only when 2 items have different score, else
sort by the original position.
2025-01-24 04:35:27 +00:00
Guido Cella 7ded290e2c console.lua: rename format_table() to format_grid()
Since there is no table header or predetermined columns.
2025-01-24 04:34:49 +00:00
Guido Cella 0c5d966f47 console.lua: always say completions instead of suggestions
Both completions and suggestions were being used inconsistently. Just
always use completions which is much more common.
2025-01-24 04:34:49 +00:00
Guido Cella a2ce811b28 console.lua: rename update() to render()
It is not clear what update() updates, in fact this rename allows
removing the comment explaining it. render() is clearer and is the same
term used by the OSC.
2025-01-24 04:34:49 +00:00
Guido Cella effa81eb6e console.lua: set a high z in select mode
Give console's overlay a high z only in select mode, since in this case
you want to click it so it should be above other overlays. In particular
console should be above the OSC's box layout with visibility=always when
you show it by clicking its buttons.

Keep using z=0 otherwise when it doesn't handle clicks, to avoid
unintuitive behavior of overlays handling clicks like the OSC being
drawn below console.

Since the legacy mp.set_osd_ass() doesn't accept z, we need to repeat
its caching logic, like 490b3ba007 and 86d24b069b did for the OSC.
2025-01-22 12:55:24 +02:00
Guido Cella c438732b23 console.lua: improve the hovered item calculation
Currently determine_hovered_item() assumes that each item is
opts.font_size pixels tall, which usually works well. This breaks with
fonts that get drawn taller than that, such as Japanese text, which
makes the calculation inaccurate for the top items and clips the
counter. A couple of users reported that it is inaccurate for them for
the top items even with ASCII characters in track selectors, presumably
because the circles are taken from a different font and make all lines
taller.

To fix this place each selectable item in its own ASS event positioned
like determine_hovered_item() expects.

Unfortunately this breaks --profile=box, so keep placing every item in
one ASS event with it.
2025-01-18 12:52:02 +01:00
Guido Cella 89c42e4481 console.lua: deduplicate y position calculation in update()
This deduplicates the calculation of the y position by assigning it to a
y variable, which will also be used in the next commit. margin_x is also
renamed to x for consistency.
2025-01-18 12:52:02 +01:00
Guido Cella a06883f79a console.lua: refactor some log code
Rename lines_max to max_lines which is the name used in other functions,
and inline the log_messages variable because its name was confusing.

The math.max(0, lines_max) call was not necessary because console
doesn't crash with 0 or negative max lines.
2025-01-18 12:52:02 +01:00
nanahi 72550aa7df console.lua: complete screenshot-raw format parameter 2025-01-05 21:28:57 +01:00
Guido Cella 850e03d29f 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.
2025-01-05 21:21:32 +01:00
Guido Cella 2dcf69655a console.lua: complete playlist-play-index none 2025-01-04 16:52:01 +01:00
Guido Cella 6f8d8a38c4 console.lua: apply --osd-selected-color to selected completions 2025-01-04 16:22:20 +01:00
Kacper Michajłow 59d1dc43b9 various: fix typos 2025-01-04 15:59:49 +02:00
Guido Cella c9a99db26c console.lua: don't set the cursor color
This makes no visible difference, only the border color is visible, as
the border is drawn on top of the regular color.
2025-01-03 13:02:10 +01:00
Guido Cella ab25b3d852 console.lua: inherit --osd-back-color in the cursor
3dcc661de7 made the cursor reset to Default style to not apply the blur,
but \blur0 achieves that without resetting every user style. The cursor
can thus respect the user's --osd-back/shadow-color.
2025-01-03 13:02:10 +01:00
Guido Cella 2ecbe8d83b console.lua: inherit --osd-color in the cursor
Following up 19537a4996, also respect the user-specified color in the
cursor. But the cursor is drawn as a border, so we actually need to use
--osd-color as the border color.
2025-01-03 13:02:10 +01:00
Guido Cella 4e8452aee8 console.lua: inherit --osd-shadow-offset
It was requested in
https://github.com/Samillion/ModernZ/issues/259#issuecomment-2556608926
to make console's shadow offset consistent with --osd-shadow-offset. Not
specifying shadow offsets achieves that. This disables console's shadow
by default but there is no reason console should default to having
shadows but the rest of the OSD shouldn't. Users who want shadows can
enable them in the whole OSD with --osd-shadow-offset. console-specific
shadow_{x,y}_offset script-opts can be added if someone requests them
later.
2025-01-03 12:56:10 +01:00
Guido Cella f21b3f8f06 console.lua: inherit --osd-back-color
The previous commit changed --osd-back/shadow-color to nearly the same
one console was using. This allows unhardcoding it from there and using
--osd-back-color even with --osd-border-style=outline-and-shadow for
consistency with the rest of the OSD.
2025-01-03 12:18:03 +01:00
Guido Cella 00ff6e5ae2 console.lua: remove useless assignment
The lines in populate_log_with_matches()

if selected_match < first_match_to_print then
    first_match_to_print = selected_match

will set first_match_to_print to 1 even if it is not set here since
handle_edit() sets selected_match = 1.
2025-01-03 11:25:22 +01:00
Guido Cella f3ed94b74d console.lua: focus the default item after emptying the input line
When console is opened with selectable items and a default item, the
default item is placed at the center. But if you type something and then
clear the line, the first item becomes the selected one. Make it select
the default item and place it in the center in this case too.
2025-01-03 11:25:22 +01:00
Guido Cella 0417218daa console.lua: don't highlight the first completion with mp.input.get
The first completion is highlighted because it is automatically inserted
when pressing Enter, but this isn't the case when the console is used
with mp.input.get, and autoselecting it can be undesirable if you're
entering arbitrary text, unlike with mpv commands where you're usually
choosing from predefined lists. So just don't highlight the first
completion for mp.input clients.
2024-12-28 14:31:44 +01:00
Guido Cella bd150a4d8d console.lua: keep --osd-{,outline}-color's alpha component for styles
There is no need to override this for colored lines.
2024-12-28 14:13:46 +01:00
Guido Cella 61aa8200ad console.lua: complete clipboard/text 2024-12-28 14:09:07 +01:00
der richter d389c06646 console.lua: use native clipboard property on macOS 2024-12-24 16:11:45 +01:00
Guido Cella 19537a4996 console.lua: inherit --osd-color and --osd-outline-color
Stop overriding the OSD font and outline color in the console input line
and log, except for the lines already in a different color. This allows
configuring the console color and makes it consistent with the rest of
the OSD, like 51bd00c33a did for stats.
2024-12-20 14:54:08 +00:00
Guido Cella 661a380fda console.lua: color the default item with --osd-selected-color
Currently if you change --osd-selected-color the preselected item stays
yellow and can't be changed. Since the default item style was just
chosen from the selected color without the bold, also make the default
item follow --osd-selected-color.

Requested in
https://github.com/Samillion/ModernZ/issues/259#issuecomment-2556608926.
2024-12-20 12:43:34 +01:00
Guido Cella 8d76ff79a3 console.lua: rename dimension variables
These are easier to read with _ between words. Also screenx/y could be
assumed to be display coordinates, so rename them to osd_w/h. They are
not named osd_width/osd_height to avoid Redefined local LSP warnings
with the ones in the upper scope.
2024-12-10 22:21:31 +01:00
Guido Cella 7bae5b8d37 console.lua: clear completions before searching history 2024-12-10 14:18:51 +01:00
Guido Cella 7253b6c63d console.lua: remove code repetition to initialize matches 2024-12-10 14:18:51 +01:00
Guido Cella 5dbaa69138 console.lua: add margin_{x,y} script-opts
Allow configuring the margins from the left bottom indipendently of
--osd-margin-{x,y}.

Fixes #15478.
2024-12-10 13:47:43 +01:00
Guido Cella 94135b1245 console.lua: don't override --osd-bold in completions
Respect the OSD bold style in completions printed after the selected
one.

Fixes #15452.
2024-12-09 19:21:33 +01:00
Guido Cella 78ee714fff console.lua: fix mp.input.get clients that don't specify completions
Actually update the rendered text when typing with an input.get client
that didn't specify a complete callback.

Fixes #15430, fixes 57b73f1af6.
2024-12-03 14:59:53 +01:00
Guido Cella 063410fa04 console.lua: don't reinsert the next characters on complete
This avoids inserting the characters in front of the cursor again when
completing to text already in front of the cursor.

This is important after 2f271a92de made Enter automatically insert the
first completion.
2024-12-02 20:57:01 +01:00
Guido Cella 9d67fc28e2 console.lua: don't complete DLLs on Windows
run completion on Windows is slow because system32 contains thousands of
DLLs, so filter executables with an extension in PATHEXT.
2024-12-02 20:56:49 +01:00
Guido Cella 1f1c30146c console.lua: complete executables after run 2024-12-01 19:28:22 +01:00
Guido Cella 43ff1c1af6 console.lua: complete filter labels for {a,v}f-command 2024-12-01 19:28:22 +01:00
Guido Cella 15e7a1184a console.lua: complete command flags 2024-12-01 19:28:22 +01:00
Guido Cella 220de247b8 console.lua: remove code repetition in complete() 2024-12-01 19:28:22 +01:00
nanahi 510d634b5b console.lua: use native clipboard property on win32 and wayland
Since native clipboard is implemented on win32 and wayland,
use the clipboard property instead.

This fixes the problems with commandline implementations of clipboard:
- On win32, the powershell implementation is complex, and it can take
  several seconds to run for the first time.
- On wayland, it requires wl-paste to be installed, which isn't always
  available. It also works poorly on GNOME.
2024-11-27 20:31:41 +01:00
Guido Cella b9e6030053 command: highlight selected list items with color
Instead of printing circles in show-text ${playlist}, ${chapter-list}
and ${edition-list}, introduce --osd-selected-color and
--osd-selected-outline-color to reduce clutter, make the selected item
easier to differentiate, and have visual consistency with select.lua.

The defaults are taken from the style of the selected item in the
console. These new options are also used there, replacing the hardcoded
styles. Due to being user-configurable, selected item styles are changed
to take priority over default item styles.

The default selected style is yellow and bold. The bold (hardcoded)
allows differentiating the selected item with color blindness. There is
also a separate --osd-selected-outline-color option defaulting to black,
since without it if the user changes --osd-outline-color yellow text
becomes unreadable without a black border. --osd-selected-back-color is
omitted for now.

Text and background colors are inverted for the selected item in the
terminal. This is hardcoded, adding an option is overkill.

A disadvantage of this commit is that if you run print-text ${playlist}
with a VO, the selected style ASS is printed to the terminal (but ASS
printed in the console is interpreted). This commit avoids printing the
reset ASS sequence for non-selected items to reduce clutter in this
case.
2024-11-27 15:37:42 +01:00
Guido Cella d54a45d075 console.lua: enable runtime updates of script-opts 2024-11-27 15:32:10 +01:00
Guido Cella 86bbe997ce console.lua: don't append spaces after completion
After pressing Tab a space is usually appended after the suggestion, and
with the new autocompletion you have to enter a space again before
seeing the completions for the next token even when there is only 1
matching completion. Just don't append spaces and let the user manually
type 1 space after completion, which is more intuitive.
2024-11-25 16:43:14 +01:00