Commit Graph

735 Commits

Author SHA1 Message Date
Guido Cella 46a35e2edc console.lua: complete fixed precision properties
Add support for the syntax introduced by 8708f4dc91 in the completion
system.
2024-03-21 08:54:58 +01:00
Guido Cella c84bb1ce67 osc.lua: escape text
Escape all messages in osc.lua, because other than the title they
weren't being escaped at all. If for example you did mpv foo.mp4
'{\fs50}bar.mp4' and script-message osc-playlist, it would just render
the second entry as bar.mp4 in big text.

The title was escaped partially, now the escaping is complete because:

- It escapes \. Backslashes at the end of the title are escaped instead
  of being stripped, and \n, \N and \h are now printed verbatim. In
  particular, "\\n" is no longer converted to space and is printed
  verbatim instead which is more correct.
- Newlines ("\n", not the "\\n" escape sequence) are converted to spaces
  instead of rendering them and messing up the text positioning within
  the OSC.
- Spaces at the start are preserved.

Fixes #11209, fixes #11275.
2024-03-21 03:20:14 +01:00
Guido Cella d6610a5b2f command: add escape-ass
This adds a command to escape ASS tags to remove code duplication
between sub/osd_libass.c, console.lua, osc.lua, stats.lua and any user
script that calls mp.create_osd_overlay().

A command is used instead of scripting functions so that all clients can
use this and not just use Lua and JS ones.

osd_mangle_ass() also interprets osd-sym-cc and osd-ass-cc/{0,1}, but
since they use invalid UTF-8 characters there is no risk of escape-ass
users using them by accident, like with any OSD message.

Always replacing \n with \\N in mangle_ass() even when it is not called
by escape-ass doesn't seem to cause any issue, but I made it conditional
anyway to avoid changing how all OSD messages are treated unnecessarily.
2024-03-21 03:20:14 +01:00
Christoph Heinrich 97e16be294 stats.lua: use term-size as terminal output size
The terminal output was static in size with no way of automatically
adjusting it to the current terminal size.

The new term-size property makes truly automatic adjustment possible.
2024-03-21 03:08:52 +01:00
Christoph Heinrich 0230a0c25a stats.lua: fix and unify scroll hint
The scroll hint on page 4 had baked in ass tags, which shouldn't be
there in the terminal. Also the scroll hint on page 0 was missing.

Refactor scroll hint generation into a function and use that for
pages 2, 4 and 0.
2024-03-21 03:08:52 +01:00
Christoph Heinrich c89b8340d5 stats.lua: use term_ellipsis for page 4
Page 4 might as well use the same line shortening function as the other
pages instead of rolling it's own.
2024-03-21 03:08:52 +01:00
Christoph Heinrich 777f69bee8 stats.lua: truncate long lines for the terminal
The terminal is assumed to be 80x24 in size, the new options
`term_width_limit` and `term_height_limit` can be used to overwrite
that.

Lines longer then the terminal width cause problems with scrolling
pages and need to be shortened.

The algorithm used for shortening can deal with tabs and escape
sequences, has rudimentary support for UTF-8 and runs in O(n).

avih helped in the creation of the term_ellipsis() function and split()
is also from him.
2024-03-21 03:08:52 +01:00
Christoph Heinrich 344ac5501d stats.lua: use scroll function for page 2 and 0
Pages 2 and 0 had their own scroll implementations, which worked fine
for ass, but didn't work well in the terminal.

Now they both use the same scroll function as page 4.

That scroll function requires each output line to be one entry
in the table. Page 0 did not adhere to that new requirement, instead
it generated two table entries for a single output line when a graph
is shown. To fulfill that requirement the generated graph now gets
directly appended to the same table entry that's used for the rest
of the line.
2024-03-21 03:08:52 +01:00
Christoph Heinrich 16a480375b stats.lua: refactor page 4 scrolling into function
This scrolling implementation will be used for other pages in future
commits.

The comment said it takes up 20 lines of the terminal, but in reality
it was 22 lines.
2024-03-21 03:08:52 +01:00
Kacper Michajłow 2a08440afb stats.lua: add more information in audio section
- current AO
- AO device
- AO volume
- audio delay
- output format
2024-03-21 02:40:00 +01:00
Kacper Michajłow ad093567e8 osc: add missing window controls for --title-bar=no 2024-03-18 02:22:28 +00:00
Kacper Michajłow a56d8ff184 stats.lua: display video parameters after filtering 2024-03-09 05:58:52 +00:00
nanahi 3dcc661de7 console.lua: fix blurry cursor when --osd-blur is set
This is drawn with the same method as the stats.lua graphs so it's also
blurry. Fix this by using the "Default" style for cursor drawing.
2024-02-27 08:36:56 +01:00
nanahi f4af7b683e stats.lua: fix blurry graphs when --osd-blur is set
When --osd-blur is set to a nonzero value, the graphs also become
blurry. This is because they are rendered by the osd-overlay command
with the "OSD" style which has OSD blur applied, and are treated no
differently from texts. Fix this by using the "Default" style for
these graphs which uses the default OSD options.
2024-02-27 08:36:56 +01:00
Guido Cella 36153d1a4a console.lua: move functions to strip common characters
Move common_prefix_length() and related functions before the first call
to common_prefix_length(). It works now because it's global but if we
ever make all functions local for consistency it will stop working.
2024-02-08 18:18:33 +01:00
Dudemanguy fd2c5ee21d stats.lua: use deinterlace-active property instead
But still read the deinterlacing option to distinguish between yes and
auto.
2024-02-07 14:50:09 +00:00
Guido Cella e2284fba18 command: add load-config-file
Unlike set include mpv.conf, this works after playback has started. It
can be used to auto reload the configuration, e.g. in vim:
autocmd BufWritePost ~/.config/mpv/mpv.conf silent !echo load-config-file %:p | socat - /tmp/mpvsocket

Partially fixes #6362.
2024-02-04 15:12:02 +00:00
Dudemanguy 6ae5ff26b0 osc: add osc-windowcontrols_title option
This allows the title shown with the windowcontrols to be controlled
separately from the normal osc title. Fixes #13295.
2024-01-22 14:41:36 +00:00
nanahi 2cb1485492 stats.lua: display the current GPU context
This displays the current GPU context when --vo=gpu or --vo=gpu-next
is used, which shows the platform and backend information of the vo
which are previously not available.
2024-01-20 17:12:07 +00:00
Guido Cella 6302a795d2 console.lua: highlight the selected suggestion in the terminal 2024-01-20 16:10:12 +00:00
Guido Cella de0849404b scripting: don't observe properties with type nil
mp.observe_property('foo', nil, ...) calls the handler at least 2 times
on each playlist change even when the property doesn't change. This is
dangerous because if you haven't read observe_property's documentation
in a long time this is easy to forget, and you can end up using it for
handlers that are computationally expensive or that cause unintended
side effects.

Therefore, this commit discourages its use more explicitly in the
documentation, and replaces its usages in scripts.

For console.lua, observing focused with type nil leads to calling
mp.osd_message('') when changing file while playing in the terminal with
the console disabled. I don't notice issues from this, but it's safer to
avoid it.

For playlist and track-list this doesn't really matter since they
trigger multiple changes on each new file anyway, but changing it can
avoid encouraging people to imitate the code.

One usage of none in stats.lua is kept because according to b9084dfd47
it is a hack to replicate the deprecated tick event.
2024-01-20 16:09:34 +00:00
nanahi c209d4f73b osc: don't autohide mouse cursor when hovering over windowcontrols title
When the mouse cursor is hovering over the (CSD) windowcontrols title,
the osc keeps displaying, but the cursor autohide isn't disabled like
other visible regions.

Fix this by disabling the cursor autohide in this region.
All other existing behaviors of the mouse cursor in this region
are unchanged, including triggering main window area input
and allowing VO dragging.
2024-01-20 16:09:22 +00:00
llyyr 22e21edbd4 stats.lua: make capitalization consistent across pages 2024-01-17 09:48:06 +01:00
Guido Cella dfecc9f083 console.lua: style log lines in the terminal
When running the console in the terminal, style log lines with the same
escape sequences as msg.c.

mp.input can also specify terminal escape sequences, e.g. a script to
select a playlist entry can invert the color of the selection.

Also add a missing newline to help's error message.
2024-01-14 23:26:07 +01:00
Guido Cella 871f7a152a scripting: add mp.input
This lets scripts get textual input from the user using console.lua.
2024-01-13 02:53:08 +00:00
Guido Cella 448cb4d13d console.lua: expand ~/ in file completion
Makes Tab expand loadfile ~/ to loadfile /home/$USER/.

I used expand-path instead of os.getenv('HOME') to make it work on
Windows.
2024-01-04 13:41:15 +00:00
Guido Cella 28b21e4ab7 console.lua: hide the cursor when unfocused
This is commonly done to understand whether a window is focused. This
explicitly checks if focused is false instead of unavailable to not
break the cursor where focused is unimplemented like on --vo=drm.

The cursor is taller than the input text so it is made transparent
instead of completely removing it so that the log doesn't move up and
down while toggling focus. Alternatively, cheight = opts.font_size * 8
can be changed to 7.
2024-01-01 14:24:00 +01:00
Guido Cella 731378d1bb console.lua: don't reinsert completion_append after cycling
43ed0a83d0 avoided reinserting the string that is appended after certain
completions when it is already after the cursor when inserting the
longest common prefix of the suggestions. Do the same when cycling
through them.
2024-01-01 14:23:40 +01:00
Guido Cella 19a37f625f console.lua: refactor find_common_prefix
Reuse common_prefix_length() to make find_common_prefix() shorter and
faster by not creating many temporary strings.

The decrease in the average time to run find_common_prefix() over 1000
calls I measured is:

set \<Tab>: 1e-4s -> 1e-5s
set s\Tab>: 1e-5s -> 5e-6s
2023-12-26 20:12:24 +01:00
Dudemanguy 069143252a osc: allow disabling special mouse wheel behavior
When hovering certain elements over the OSC, using the mouse wheel can
result in special commands (such as seeking, changing audio tracks,
etc.) Not everyone neccessarily wants this feature, so add an option to
make it possible to disable all of it. Maybe more fine-tuned control
would be more ideal, but probably not worth it. Fixes #13096.
2023-12-21 09:13:11 +01:00
HRXN ba547cb098
OSC: fix indentation and stray whitepace 2023-12-17 08:46:44 -05:00
Guido Cella 8ceaec1742 console.lua: clear the suggestions when you move the cursor
Clear completion suggestions from functions that move the cursor, so
that you can't insert suggestions at the wrong spot by pressing Tab
again after moving the cursor,

Also clear suggestions from some editing functions that were never
updated. It is not actually necessary to clear suggestions from
functions that remove text in front of the cursor, but since
handle_del() already clears them, let's just clear them everywhere.
2023-12-15 15:45:11 +00:00
Guido Cella 86c8ef5c1f console.lua: complete current-tracks sub-properties
Also inline option-info's sub-properties so we don't have to define
sub-properties at the top of the function for every one we decide to
complete.
2023-12-15 15:45:00 +00:00
Guido Cella b09deda37a console.lua: implement case-insensitive completion
This is useful for completing files and more rarely for profiles. It
will also be useful to third-party scripts interacting with the console
once the API to do it is merged.
2023-12-15 15:44:48 +00:00
Niklas Haas b690531f30 Revert "OSC: Remove merriment"
This reverts commit af2635d8c9, and
restores feature parity with VLC.
2023-12-13 19:29:39 +01:00
Mia Herkt af2635d8c9
OSC: Remove merriment
I honestly don’t care either way but I also don’t believe this innocent
and cute hat is worth repeatedly having people show up on the issue
tracker to aggressively virtue signal and then shit-talk the project
elsewhere when their “concerns” are ignored and made fun of.
For the record, I approve of neither brand of childish nonsense.

If your workflow depends on December festivities, feel free to use an
alternative OSC implementation.

Fixes #13082 and #9548
2023-12-13 18:06:22 +01:00
Guido Cella f886eb5678 console.lua: cycle through completions 2023-12-06 19:06:58 +00:00
Christoph Heinrich c16f868dd7 console: automatically determine the font_hw_ratio
A simplified version of the text width estimation code from uosc.

An osd_overlay is created with compute_bounds=true for measuring the
width of the lower case alphabet at what's estimated to be the largest
font size possible without clipping.

The lower case alphabet was chosen to get decent results for proportional
fonts, even if they aren't officially supported.
2023-12-06 19:06:41 +00:00
Guido Cella df166997ae console.lua: simplify the condition to print to the terminal
This was a simpler fix to not print the console log to the OSD while
switching VO.
2023-12-06 10:59:40 +01:00
Dudemanguy 86b498ecc0 player: remove shared-script-properties property
This property was never encouraged. The manual even stated that "You
should avoid using it, unless you absolutely have to." Since we now have
user-data which is superior in every single way and replaces this,
delete this property. The manual also has threatened people for years
with the line "It's a makeshift solution which could go away any time
(for example, when a better solution becomes available)." We were nice
and deprecated it in 1d00aee8e1 for a
while to give script authors some time to update. Let's remove it for
good now.
2023-11-22 16:29:43 +00:00
nanahi 6f17a5efe3 stats.lua: fix incorrect storage aspect ratio value
The "Resolution" property shows the storage resolution for videos with
non-square pixels.

Currently, display aspect ratio is shown for both "Resolution" and
"Output Resolution" properties which results in a duplicate,
and is incorrect for the "Resolution" property.

The correct aspect ratio is now shown using the sar and sar-name properties.
2023-11-14 15:00:23 +00:00
Christoph Heinrich 5db7dc0860 console: fix crash for long suggestion strings
String formatting of Lua crashes with widths greater then 99, so limit
the value to that.

A nicer solution would be to create our own string padding function that
can handle bigger widths, but such long suggestions aren't common enough
to be worth the effort.
2023-11-11 20:43:02 +00:00
Kacper Michajłow e682834234 stats.lua: disable ASS formatting when printing to terminal 2023-11-08 21:55:08 +00:00
Guido Cella c798f66343 stats.lua: remove unused variable
056072bf95 deleted the only use of property_list.
2023-11-07 20:58:30 +00:00
Guido Cella 5c2cdb749d console.lua: don't print the console log to the OSD when switching VO
Fixes #12735, fixes #12839.
2023-11-07 20:49:44 +00:00
Christoph Heinrich 69c4ed585d stats: don't overwrite color and alpha of `osd-back-color` 2023-11-07 20:48:37 +00:00
Christoph Heinrich 2406a89e00 console: don't overwrite color and alpha of `osd-back-color` 2023-11-07 20:48:37 +00:00
Christoph Heinrich f41805081b console: wrap rows at the top
The previous commit was already a big improvement, but it was still
somewhat slow on the lua interpreter. By wrapping the table at the top
we loose the consistent placement of items while resizing (at least as
long as the column count didn't change), but we avoid taking all the
off screen items into account.

The fewer items fit on screen the faster this becomes.
2023-11-07 01:36:59 +00:00
Christoph Heinrich ff131d7a20 console: optimize table generation
Showing all properties was terribly slow.
Instead of starting at one row and increasing the row count until it
fits, the column count can be increased until it doesn't fit anymore.

That alone already reduces the required iterations, but from the column
count an upper and lower bound for the row count can be calculated.

For large tables this dramatically reduces the amount of iterations.
2023-11-07 01:36:59 +00:00
Christoph Heinrich bca0b20c09 console: enable completions without a prefix
This way it is possible to get a list of all options or all properties,
instead of having to guess the first letter before any suggestions are
shown.
2023-11-07 01:36:59 +00:00