Skip to content

[RFC] mp.input: allow clients to override console.lua script-opts#17469

Open
CogentRedTester wants to merge 1 commit intompv-player:masterfrom
CogentRedTester:mp.input/console-opt-overrides
Open

[RFC] mp.input: allow clients to override console.lua script-opts#17469
CogentRedTester wants to merge 1 commit intompv-player:masterfrom
CogentRedTester:mp.input/console-opt-overrides

Conversation

@CogentRedTester
Copy link
Contributor

@CogentRedTester CogentRedTester commented Feb 27, 2026

Currently, all input requests are styled the same no matter the source of the request. Users can change style settings using script-opts, but these changes will still apply to requests from all clients. The problem with this approach, is that not all scripts request the same kind of input, so not all will necessarily benefit from the same kind of styling, and some scripts which draw their own UI elements may want console.lua styling to better match their own.

This commit allows a table of script-opt overrides to be passed to mp.input.get() and mp.input.select() under the console_opt_overrides key, which console.lua will use instead of the its own. To minimise required changes, metatables are used to allow console.lua to seamlessly fall back on the original script-opts if the client does not provide an override. I have also required that incoming opts have the same type as the existing script-opts, which should prevent any crashes caused by mismatched types.

From looking through the code, I don't believe there are any stateful or cached values based on opts that need to be specially updated, the opts appear to be re-queried any time the console is rendered or a keybind is pressed and any crashes/bugs that might be caused by invalid inputs of the right type would presumably also happen if the user sets script-opts normally. However, I would appreciate a second opinion from someone familiar with console.lua.

@CogentRedTester CogentRedTester force-pushed the mp.input/console-opt-overrides branch 2 times, most recently from 72e865f to 75afe9e Compare February 27, 2026 11:09
@guidocella
Copy link
Contributor

Ref. #16138

I'm not sure if it's desirable to override the user preferences like the font size though?

@CogentRedTester
Copy link
Contributor Author

CogentRedTester commented Feb 27, 2026

I'm not sure if it's desirable to override the user preferences like the font size though?

There are definitely some preferences that are less useful to override, but with the metatable implementation, it would require more code to support a limited subset than to support them all. Or are you referring to the fact that some options may have accessibility reasons for users to override? I can see that argument, but I don't think the solution is to ban changes to some options as some scripts may have legitimate reasons to change them. I would prefer instead to encourage those scripts to expose their own script-opts to change their own defaults.

It would not be difficult to add a (non-overridable) script-opt that allows users to provide a list of script opts that cannot be shadowed, but I'm not convinced its worth the extra complexity.

Ref. #16138

Regarding the solution in the linked issue, overriding script-opts manually in the opened and closed callbacks is an option, but the original styling is still drawn for a fraction of a second initially, and extra care has to be taken to ensure there are no race conditions (the code they presented there could potentially wipe custom options set by other scripts). If this is a desirable feature, I think it makes more sense to do what this PR does.

@guidocella
Copy link
Contributor

guidocella commented Feb 27, 2026

Yeah scripts can expose their own script-opts.

That issue made me wonder, is your use case to center the input? If so it's probably better to add a dedicated option. Centering totally breaks log and completions but it's fine if you don't use those, though it's not clear how wide the input line should be.

@CogentRedTester
Copy link
Contributor Author

CogentRedTester commented Feb 27, 2026

I hadn't considered centering actually, I was thinking more things like changing colours to match the colour scheme of the script, changing borders/padding/gaps based on how many select items a script expects to have, or changing exact_match/case_sensitive/history_dedup depending on the context of the input request.

Edit: and of course border/background/font-size styling to make the input request look visually like the other elements a script is drawing on the screen

@guidocella
Copy link
Contributor

Yeah that's fair. We can actually use this in select.lua to make history search exact by default.

I would suggest not mentioning REPL since that's just a leftover of the original name of the script. I removed most references in 9551de6 but apparently I missed my own at the start of the mp.input docs (you can remove that too if you want).

Since we have several -override options maybe this can be named script_opt_overrides? Which also makes it clear that not specified script-opts are untouched.

@CogentRedTester CogentRedTester force-pushed the mp.input/console-opt-overrides branch 2 times, most recently from 0150833 to d24f17d Compare March 3, 2026 02:17
@CogentRedTester
Copy link
Contributor Author

I have replaced the word REPL with script, and I have renamed the option to console_opt_overrides, as I think using script may be a little misleading about which script's opts are being overridden.

@CogentRedTester
Copy link
Contributor Author

This PR does create some overlap between console.lua script-opts and the arguments sent to input.get(), which may lead to some confusion in the future about where any new options should be placed. It may be worth pre-emptively coming up with some policy about what kinds of options should be placed in console.lua and what kind should need to be sent via console_opt_overrides.

Another option is not to have a console_opt_overrides argument at all, and instead allow console.lua script-opts to be specified directly in the arg table (implementation wise this is almost identical to do, it just means we have to be careful of overlapping option names).

This commit allows a table of script-opt overrides to be passed to
`mp.input.get()` and `mp.input.select()`, which console.lua will use
instead of the its own.

To minimise required changes, metatables are used to allow console.lua
to seamlessly fall back on the original script-opts if the client does
not provide an override.
To prevent exceptions, the incoming opts must be of the same type.
@CogentRedTester CogentRedTester force-pushed the mp.input/console-opt-overrides branch from d24f17d to 9646411 Compare March 3, 2026 02:41
@CogentRedTester
Copy link
Contributor Author

Added a note to the console.lua documentation stating that mp.input clients can override configuration options.

@guidocella
Copy link
Contributor

I don't think any option overlaps so far. script-opts are for global user preferences while mp.input fields only make sense for individual requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants