wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

Lua scripting API

Open wez opened this issue 4 years ago • 2 comments

Today the key assignments are all declarative; while there is a reasonable variety of actions they all need to be statically defined and built into wezterm. I'd like to enable others to script their own actions so that we can keep the core of wezterm reasonably manageable.

At a high level, what I think is needed is:

  • [ ] - Lua bindings for Pane, with accessors for dimensions, cell/scrollback and selection (depends on #157)
  • [ ] - Lua bindings for Tab, with accessors for panes, splits, layouts, zoom state
  • [ ] - Lua bindings for Window that expose some basic window management functions
  • [x] - A Lua function that can trigger key assignments directly
  • [x] - Defining how users register callback functions; we cannot simply put closures in the returned config object; there needs to be a registry of some kind (eg: wezterm.on(name, func))
  • [x] - Adding a key assignment type that calls a callback and passes the Tab and Window from the current context

With this combination it should be possible to write key assignment actions in your config file that can inspect the terminal and perform arbitrary actions.

wez avatar Jun 19 '20 16:06 wez

This would be one of the killer feature of wezterm. Looking forward to this.

For callbacks would need more apis. wezterm.on, wezterm.off, wezterm.emit. You could create a generic event emitter in lua and then add it for objects. wezterm.tab.on('resize', function (e) print('tab resized') end). You could also listen to a particular tab resize only but this could start complicating the code.

Few things that could also be added is to support redirecting print() to some debug view. For windows you have apis to attach it to a windbg. https://github.com/prabirshrestha/dwm-win32/pull/4

prabirshrestha avatar Jun 21 '20 04:06 prabirshrestha

Would love this. Seemless window navigation between neovim and wezterm would be great.

benbooth493 avatar Aug 23 '22 14:08 benbooth493

This is the only missing feature which keeps me from switching from kitty (which can be extended with „plugins” written in python)

adrian-gierakowski avatar May 25 '24 09:05 adrian-gierakowski