add format-window-title event

This provides a flexible way for users to customize what gets
shown in the window title bar.

closes: https://github.com/wez/wezterm/pull/603
This commit is contained in:
Wez Furlong committed 2021-04-24 16:47:26 -07:00
1 parent 1f8908cddb
commit e3fcdc9f36
8 files changed
+266 -32

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
# PaneInformation
The `PaneInformation` struct describes a pane. Unlike [the Pane
object](pane/index.md), `PaneInformation` is purely a snapshot of some of
the key characteristics of the pane, intended for use in synchronous, fast,
event callbacks that format GUI elements such as the window and tab title bars.
The `PaneInformation` struct contains the following fields:
* `pane_id` - the pane identifier number
* `pane_index` - the logical position of the pane within its containing layout
* `is_active` - is true if the pane is the active pane within its containing tab
* `is_zoomed` - is true if the pane is in the zoomed state
* `left` - the cell x coordinate of the left edge of the pane
* `top` - the cell y coordinate of the top edge of the pane
* `width` - the width of the pane in cells
* `height` - the height of the pane in cells
* `pixel_width` - the width of the pane in pixels
* `pixel_height` - the height of the pane in pixels
* `title` - the title of the pane, per [pane:get_title()](pane/get_title.md) at the time the pane information was captured
+13
View File
@@ -0,0 +1,13 @@
# TabInformation
The `TabInformation` struct describes a tab. `TabInformation` is purely a
snapshot of some of the key characteristics of the tab, intended for use in
synchronous, fast, event callbacks that format GUI elements such as the window
and tab title bars.
The `TabInformation` struct contains the following fields:
* `tab_id` - the identifier for the tab
* `tab_index` - the logical tab position within its containing window, with 0 indicating the leftmost tab
* `is_active` - is true if this tab is the active tab
@@ -0,0 +1,54 @@
# `format-window-title`
*Since: nightly builds only*
The `format-window-title` event is emitted when the text for the window title
needs to be recomputed.
This event is a bit special in that it is *synchronous* and must return as
quickly as possible in order to avoid blocking the GUI thread.
The most notable consequence of this is that some functions that are
asynchronous (such as
[wezterm.run_child_process](../wezterm/run_child_process.md)) are not possible
to call from inside the event handler and will generate a `format-window-title:
runtime error: attempt to yield from outside a coroutine` error.
This example overrides the default window title with code that is equivalent
to the default processing--not very useful except as a starting point for
making your own title text:
```lua
wezterm.on("format-window-title", function(tab, pane, tabs, panes, config)
local zoomed = ""
if pane.is_zoomed then
zoomed = "[Z] "
end
local index = ""
if #tabs > 1 then
index = string.format("[%d/%d] ", tab.tab_index + 1, #tabs)
end
return zoomed .. index .. pane.title
end)
```
The parameters to the event are:
* `tab` - the [TabInformation](../TabInformation.md) for the active tab
* `pane` - the [PaneInformation](../PaneInformation.md) for the active pane in the active tab
* `tabs` - an array containing [TabInformation](../TabInformation.md) for each of the tabs in the window
* `panes` - an array containing [PaneInformation](../PaneInformation.md) for each of the panes in the active tab
* `config` - the effective configuration for the window
The return value of the event should be a string, and if it is then it will be
used as the title text in the window title bar.
If the event encounters an error, or returns something that is not a string,
then the default window title text will be computed and used instead.
Only the first `format-window-title` event will be executed; it doesn't make
sense to define multiple instances of the event with multiple
`wezterm.on("format-window-title", ...)` calls.