1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 13:21:38 +03:00

add wezterm.has_action

refs: https://github.com/wez/wezterm/issues/3454
This commit is contained in:
Wez Furlong 2023-04-06 20:46:32 -07:00
parent b1c58bad39
commit b45a4d7215
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
3 changed files with 29 additions and 0 deletions

View File

@ -346,6 +346,12 @@ end
)?;
wezterm_mod.set("hostname", lua.create_function(hostname)?)?;
wezterm_mod.set("action", luahelper::enumctor::Enum::<KeyAssignment>::new())?;
wezterm_mod.set(
"has_action",
lua.create_function(|_lua, name: String| {
Ok(KeyAssignment::variants().contains(&name.as_str()))
})?,
)?;
lua.set_named_registry_value(LUA_REGISTRY_USER_CALLBACK_COUNT, 0)?;
wezterm_mod.set("action_callback", lua.create_function(action_callback)?)?;

View File

@ -67,6 +67,8 @@ As features stabilize some brief notes about them will accumulate here.
* [pane:get_tty_name()](config/lua/pane/get_tty_name.md) and
[PaneInformation.tty_name](config/lua/PaneInformation.md) to reason about the
tty name on local unix systems.
* [wezterm.has_action()](config/lua/wezterm/has_action.md) makes it easier to
author a wezterm config that works across different wezterm versions. #3454
#### Fixed
* mux: Stale remote window mapping could prevent spawning new tabs in remote domain. #2759

View File

@ -0,0 +1,21 @@
# wezterm.has_action(NAME)
{{since('nightly')}}
Returns true if the string *NAME* is a valid key assignment action variant
that can be used with [wezterm.action](action.md).
This is useful when you want to use a wezterm configuration across multiple
different versions of wezterm.
```lua
if wezterm.has_action 'PromptInputLine' then
table.insert(config.keys, {
key = 'p',
mods = 'LEADER',
action = wezterm.action.PromptInputLine {
-- other parameters here
},
})
end
```