Skip to content

Commit 87b1415

Browse files
committed
fix(wezterm): Improved annotations, improved wezterm.font().
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
1 parent 22fb798 commit 87b1415

1 file changed

Lines changed: 149 additions & 94 deletions

File tree

lua/wezterm/types/wezterm.lua

Lines changed: 149 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
---@class Deprecated
1919
---NOTE: THIS IS DELIBERATELY LEFT EMPTY
2020

21+
---@alias ColorSpec table<"AnsiColor", AnsiColor>|table<"Color", string>
22+
2123
---@alias FormatItemAttribute
2224
---|{ Underline: "None"|"Single"|"Double"|"Curly"|"Dotted"|"Dashed" }
2325
---|{ Intensity: "Normal"|"Bold"|"Half" }
@@ -46,20 +48,6 @@
4648
---|"SHIFT"
4749
---|"SUPER"
4850

49-
---@alias IntegratedTitleButton
50-
---|"Hide"
51-
---|"Maximize"
52-
---|"Close"
53-
54-
---@alias IntegratedTitleButtonAlignment
55-
---|"Right"
56-
---|"Left"
57-
58-
---@alias IntegratedTitleButtonStyle
59-
---|"Windows"
60-
---|"Gnome"
61-
---|"MacOsNative"
62-
6351
---Configures whether the window has a title bar and/or resizable border.
6452
---
6553
---The value is a set of flags:
@@ -109,16 +97,6 @@
10997
---|string
11098
---Add other valid combinations if needed
11199

112-
---@alias TabBarIntensity
113-
---|"Normal"
114-
---|"Half"
115-
---|"Bold"
116-
117-
---@alias TabBarUnderline
118-
---|"None"
119-
---|"Single"
120-
---|"Double"
121-
122100
---@alias PaletteAnsi
123101
---|"black"
124102
---|"maroon"
@@ -169,13 +147,13 @@
169147
---
170148
---The default is `"Normal"`.
171149
---
172-
---@field intensity? TabBarIntensity
150+
---@field intensity? "Normal"|"Half"|"Bold"
173151
---Specify whether you want `"None"`, `"Single"` or `"Double"` underline for
174152
---label shown for this tab.
175153
---
176154
---The default is `"None"`.
177155
---
178-
---@field underline? TabBarUnderline
156+
---@field underline? "None"|"Single"|"Double"
179157
---Specify whether you want the text to be italic for this tab.
180158
---
181159
---The default is `false`.
@@ -201,26 +179,24 @@
201179
---The color of the strip that goes along the top of the window
202180
---(does not apply when fancy tab bar is in use).
203181
---
204-
---@field background string
182+
---@field background? string
205183
---The active tab is the one that has focus in the window.
206184
---
207-
---@field active_tab TabBarColor
185+
---@field active_tab? TabBarColor
208186
---Inactive tabs are the tabs that do not have focus.
209187
---
210-
---@field inactive_tab TabBarColor
188+
---@field inactive_tab? TabBarColor
211189
---You can configure some alternate styling when the mouse pointer
212190
---moves over inactive tabs.
213191
---
214-
---@field inactive_tab_hover TabBarColor
192+
---@field inactive_tab_hover? TabBarColor
215193
---The new tab button that let you create new tabs.
216194
---
217-
---@field new_tab TabBarColor
195+
---@field new_tab? TabBarColor
218196
---You can configure some alternate styling when the mouse pointer
219197
---moves over the new tab button.
220198
---
221-
---@field new_tab_hover TabBarColor
222-
223-
---@alias ColorSpec table<"AnsiColor", AnsiColor>|table<"Color", string>
199+
---@field new_tab_hover? TabBarColor
224200

225201
---@class Palette
226202
---The text color to use when the attributes are reset to default.
@@ -252,7 +228,7 @@
252228
---@field brights? table<integer, PaletteBrights>
253229
---A map for setting arbitrary colors ranging from 16 to 256 in the color palette.
254230
---
255-
---@field indexed? string[]|table
231+
---@field indexed? string[]
256232
---The color of the "thumb" of the scrollbar; the segment that represents
257233
---the current viewable area.
258234
---
@@ -289,11 +265,11 @@
289265
--- - `"White"`
290266
---
291267
---@field copy_mode_active_highlight_fg? ColorSpec
292-
---Colors for copy_mode and quick_select.
268+
---Colors for `copy_mode` and `quick_select`.
293269
---
294-
---In copy_mode, the color of the active text is:
295-
---1. `copy_mode_active_highlight` if additional text was selected using the mouse
296-
---2. `selection` otherwise
270+
---In `copy_mode`, the color of the active text is:
271+
--- 1. `copy_mode_active_highlight` if additional text was selected using the mouse
272+
--- 2. `selection` otherwise
297273
---
298274
---@field copy_mode_active_highlight_bg? ColorSpec
299275
---Use [`AnsiColor`](lua://AnsiColor) to specify one of the ansi color palette values
@@ -317,11 +293,12 @@
317293
--- - `"White"`
318294
---
319295
---@field copy_mode_inactive_highlight_fg? ColorSpec
320-
---Colors for copy_mode and quick_select.
296+
---Colors for `copy_mode` and `quick_select`.
321297
---
322-
---In copy_mode, the color of the active text is:
323-
---1. `copy_mode_active_highlight` if additional text was selected using the mouse
324-
---2. `selection` otherwise
298+
---In `copy_mode`, the color of the active text is:
299+
---
300+
--- 1. `copy_mode_active_highlight` if additional text was selected using the mouse
301+
--- 2. `selection` otherwise
325302
---
326303
---@field copy_mode_inactive_highlight_bg? ColorSpec
327304
---@field quick_select_label_fg? ColorSpec
@@ -359,11 +336,6 @@
359336
---|"UltraCondensed"
360337
---|"UltraExpanded"
361338

362-
---@alias FontStyle
363-
---|"Normal"
364-
---|"Italic"
365-
---|"Oblique"
366-
367339
---@alias FreeTypeLoadTarget
368340
---|"Normal"
369341
---|"HorizontalLcd"
@@ -380,6 +352,7 @@
380352
---|"NO_AUTOHINT"
381353

382354
---TODO: Find out what do the undocumented options do
355+
383356
---@alias HarfbuzzFeatures
384357
---|"calt=0"
385358
---|"clig=0"
@@ -439,7 +412,7 @@
439412
---@field stretch? FontStretch
440413
---Whether the font should be an italic variant.
441414
---
442-
---@field style? FontStyle
415+
---@field style? "Normal"|"Italic"|"Oblique"
443416
---@field is_fallback? boolean
444417
---@field is_synthetic? boolean
445418
---@field scale? number
@@ -448,8 +421,6 @@
448421
---
449422
---@class FontFamilyAttributes: FontAttributes
450423
---@field family string
451-
452-
---@class FontFamilyExtendedAttributes: FontFamilyAttributes
453424
---@field harfbuzz_features? HarfbuzzFeatures[]
454425
---@field freetype_load_target? FreeTypeLoadTarget
455426
---@field freetype_render_target? FreeTypeLoadTarget
@@ -992,8 +963,10 @@
992963
---
993964
---@field battery_info fun(): BatteryInfo[]
994965
---Given a `string` parameter, returns the number of columns that text occupies
995-
---in the terminal, which is useful together with `format-tab-title` and `update-right-status`
996-
---to compute/layout tabs and status information.
966+
---in the terminal.
967+
---
968+
---This is useful together with the `"format-tab-title"` and `"update-right-status"`
969+
---events to compute/layout tabs and status information.
997970
---
998971
---@field column_width fun(value: string): number
999972
---Returns a `Config` object that can be used to define your configuration.
@@ -1034,7 +1007,23 @@
10341007
---but with `"WSL:"` prefixed to it.
10351008
---
10361009
---@field default_wsl_domains fun(): WslDomain[]
1037-
---@field emit fun(event: string, ...: any)
1010+
---`wezterm.emit` resolves the registered callback(s) for the specified event name
1011+
---and calls each of them in turn, passing the additional arguments
1012+
---through to the callback.
1013+
---
1014+
---If a callback returns `false` then it prevents later callbacks from being called
1015+
---for this particular call to `wezterm.emit`, and `wezterm.emit` will return `false`
1016+
---to indicate that no additional/default processing should take place.
1017+
---
1018+
---If none of the callbacks returned `false` then `wezterm.emit` will itself return `true`
1019+
---to indicate that default processing should take place.
1020+
---
1021+
---This function has no special knowledge of which events are defined by wezterm,
1022+
---or what their required arguments might be.
1023+
---
1024+
---See [`wezterm.on`](lua://Wezterm.on) for more information about event handling.
1025+
---
1026+
---@field emit fun(event: string, ...: any): boolean
10381027
---This function will parse your ssh configuration file(s) and extract from them
10391028
---the set of literal (non-pattern, non-negated) host names that are specified
10401029
---in `Host` and `Match` stanzas contained in those configuration files
@@ -1047,36 +1036,6 @@
10471036
---This constant is set to the directory containing the wezterm executable file.
10481037
---
10491038
---@field executable_dir string
1050-
---This function constructs a Lua table that corresponds to the internal [`FontAttributes`](lua://FontAttributes) struct
1051-
---that is used to select a single named font:
1052-
---
1053-
---```lua
1054-
---local wezterm = require 'wezterm'
1055-
---
1056-
---return {
1057-
--- font = wezterm.font 'JetBrains Mono',
1058-
---}
1059-
---```
1060-
---
1061-
---The first parameter is the name of the font; the name can be one of the following types of names:
1062-
---
1063-
--- - The font family name, e.g. `"JetBrains Mono"`. The family name doesn't include any style information
1064-
--- (such as `weight`, `stretch` or `italic`), which can be specified via the `attributes` parameter.
1065-
--- This is the recommended name to use for the font, as it the most compatible way to resolve
1066-
--- an installed font.
1067-
--- - The computed full name, which is the family name with the sub-family
1068-
--- (which incorporates style information) appended, e.g. `"JetBrains Mono Regular"`.
1069-
--- - The postscript name, which is an ostensibly unique name identifying a given font and style
1070-
--- that is encoded into the font by the font designer.
1071-
---
1072-
---When specifying a font using its family name, the second attributes parameter is
1073-
---an **optional** table that can be used to specify style attributes.
1074-
---
1075-
---See [`FontAttributes`](lua://FontAttributes)
1076-
---See [`FontFamilyAttributes`](lua://FontFamilyAttributes)
1077-
---See [`FontFamilyExtendedAttributes`](lua://FontFamilyExtendedAttributes)
1078-
---
1079-
---@field font (fun(attributes: FontFamilyAttributes|FontFamilyExtendedAttributes): FontFamilyAttributes)|(fun(name: string, attributes: FontAttributes?): FontFamilyAttributes)
10801039
---TODO: Complete description.
10811040
---
10821041
---[Info](https://wezterm.org/config/lua/wezterm/font_with_fallback.html).
@@ -1117,9 +1076,15 @@
11171076
---@field log_info fun(msg: string, ...: any)
11181077
---@field log_warn fun(msg: string, ...: any)
11191078
---@field open_with fun(path_or_url: string, application: string?)
1120-
---@field pad_left fun(string: string, min_width: integer): string Returns a copy of string that is at least min_width columns (as measured by wezterm.column_width)
1121-
---@field pad_right fun(string: string, min_width: integer): string Returns a copy of string that is at least min_width columns (as measured by wezterm.column_width).
1122-
---@field permute_any_or_no_mods any #TODO
1079+
---Returns a copy of a string that is at least `min_width` columns
1080+
---(as measured by `wezterm.column_width()`).
1081+
---
1082+
---@field pad_left fun(string: string, min_width: integer): string
1083+
---Returns a copy of a string that is at least min_width columns
1084+
---(as measured by `wezterm.column_width()`).
1085+
---
1086+
---@field pad_right fun(string: string, min_width: integer): string
1087+
---@field permute_any_or_no_mods any
11231088
---@field permute_any_mods (fun(tbl: MouseBindingBase): MouseBinding)|(fun(tbl: KeyBindingBase): KeyBinding)
11241089
---@field read_dir fun(path: string): string Returns an array containing the absolute file names of the directory specified. Due to limitations in the Lua bindings, all of the paths must be able to be represented as UTF-8 or this function will generate an error.
11251090
---@field reload_configuration fun(): nil Immediately causes the configuration to be reloaded and re-applied.
@@ -1130,16 +1095,43 @@
11301095
---@field shell_split fun(line: string): string[] Splits a command line into an argument array according to posix shell rules.
11311096
---@field sleep_ms fun(milliseconds: number): nil wezterm.sleep_ms suspends execution of the script for the specified number of milliseconds. After that time period has elapsed, the script continues running at the next statement.
11321097
---@field split_by_newlines fun(string: string): string[] takes the input string and splits it by newlines (both \n and \r\n are recognized as newlines) and returns the result as an array of strings that have the newlines removed.
1133-
---@field strftime fun(format: string): string Formats the current local date/time into a string using the Rust chrono strftime syntax.
1134-
---@field strftime_utc fun(format: string): string Formats the current UTC date/time into a string using the Rust chrono strftime syntax.
1135-
---@field target_triple string This constant is set to the Rust target triple for the platform on which wezterm was built. This can be useful when you wish to conditionally adjust your configuration based on the platform.
1136-
---@field truncate_left fun(string: string, max_width: number): string Returns a copy of string that is no longer than max_width columns (as measured by wezterm.column_width). Truncation occurs by reemoving excess characters from the left end of the string.
1137-
---@field truncate_right fun(string: string, max_width: number): string Returns a copy of string that is no longer than max_width columns (as measured by wezterm.column_width). Truncation occurs by reemoving excess characters from the right end of the string.
1138-
---@field utf16_to_utf8 fun(string: string): string Overly specific and exists primarily to workaround this wsl.exe issue. It takes as input a string and attempts to convert it from utf16 to utf8.
1098+
---Formats the current local date/time into a string using
1099+
---the Rust `chrono strftime` syntax.
1100+
---
1101+
---@field strftime fun(format: string): string
1102+
---Formats the current UTC date/time into a string using
1103+
---the Rust `chrono strftime` syntax.
1104+
---
1105+
---@field strftime_utc fun(format: string): string
1106+
---This constant is set to the Rust target triple for
1107+
---the platform on which wezterm was built.
1108+
---
1109+
---This can be useful when you wish to conditionally adjust your configuration
1110+
---based on the platform.
1111+
---
1112+
---@field target_triple string
1113+
---Returns a copy of a string that is no longer than `max_width` columns
1114+
---(as measured by `wezterm.column_width()`).
1115+
---
1116+
---Truncation occurs by reemoving excess characters from the left end of the string.
1117+
---
1118+
---@field truncate_left fun(string: string, max_width: number): string
1119+
---Returns a copy of a string that is no longer than `max_width` columns
1120+
---(as measured by `wezterm.column_width()`).
1121+
---
1122+
---Truncation occurs by reemoving excess characters from the right end of the string.
1123+
---
1124+
---@field truncate_right fun(string: string, max_width: number): string
1125+
---Overly specific and exists primarily to workaround this wsl.exe issue.
1126+
---It takes as input a string and attempts to convert it from utf16 to utf8.
1127+
---
1128+
---@field utf16_to_utf8 fun(string: string): string
11391129
---This constant is set to the wezterm version string that is also reported
11401130
---by running `wezterm -V`.
11411131
---
1142-
---This can potentially be used to adjust configuration according to the installed version
1132+
---This can potentially be used to adjust configuration according to
1133+
---the installed version.
1134+
---
11431135
---@field version string
11441136
---@field gradient_colors fun(gradient: Gradient, num_colors: number): Color[]
11451137
local Wezterm = {}
@@ -1437,3 +1429,66 @@ function Wezterm.on(event, callback) end
14371429
---@param event "window-resized"
14381430
---@param callback CallbackWindowPane
14391431
function Wezterm.on(event, callback) end
1432+
1433+
---This function constructs a Lua table that corresponds to the internal
1434+
---[`FontFamilyAttributes`](lua://FontFamilyAttributes) struct that is used to select a single named font:
1435+
---
1436+
---```lua
1437+
---local wezterm = require 'wezterm'
1438+
---
1439+
---return {
1440+
--- font = wezterm.font 'JetBrains Mono',
1441+
---}
1442+
---```
1443+
---
1444+
---The first parameter is the name of the font; the name can be one of the following types of names:
1445+
---
1446+
--- - The font family name, e.g. `"JetBrains Mono"`. The family name doesn't include any style information
1447+
--- (such as `weight`, `stretch` or `italic`), which can be specified via the `attributes` parameter.
1448+
--- This is the recommended name to use for the font, as it the most compatible way to resolve
1449+
--- an installed font.
1450+
--- - The computed full name, which is the family name with the sub-family
1451+
--- (which incorporates style information) appended, e.g. `"JetBrains Mono Regular"`.
1452+
--- - The postscript name, which is an ostensibly unique name identifying a given font and style
1453+
--- that is encoded into the font by the font designer.
1454+
---
1455+
---When specifying a font using its family name, the second attributes parameter is
1456+
---an **optional** table that can be used to specify style attributes.
1457+
---
1458+
---See [`FontAttributes`](lua://FontAttributes) and [`FontFamilyAttributes`](lua://FontFamilyAttributes).
1459+
---
1460+
---@param name string
1461+
---@param attributes? FontAttributes
1462+
---@return Fonts|FontFamilyAttributes
1463+
function Wezterm.font(name, attributes) end
1464+
1465+
---This function constructs a Lua table that corresponds to the internal
1466+
---[`FontFamilyAttributes`](lua://FontFamilyAttributes) struct that is used to select a single named font.
1467+
---
1468+
---You can use the expanded form mentioned above to override freetype and harfbuzz settings
1469+
---just for the specified font.
1470+
---
1471+
---This example shows how to disable the default ligature feature just for this particular font:
1472+
---
1473+
---```lua
1474+
---local wezterm = require 'wezterm'
1475+
---return {
1476+
--- font = wezterm.font {
1477+
--- family = 'JetBrains Mono',
1478+
--- harfbuzz_features = { 'calt=0', 'clig=0', 'liga=0' },
1479+
--- },
1480+
---}
1481+
---```
1482+
---
1483+
---The following options can be specified in the same way:
1484+
---
1485+
--- - [`harfbuzz_features`](lua://FontFamilyAttributes.harfbuzz_features)
1486+
--- - [`freetype_load_target`](lua://FontFamilyAttributes.freetype_load_target)
1487+
--- - [`freetype_render_target`](lua://FontFamilyAttributes.freetype_render_target)
1488+
--- - [`freetype_load_flags`](lua://FontFamilyAttributes.freetype_load_flags)
1489+
--- - [`assume_emoji_presentation`](lua://FontFamilyAttributes.assume_emoji_presentation) to control
1490+
--- whether a font is considered to have emoji (rather than text) presentation glyphs for emoji
1491+
---
1492+
---@param attributes FontFamilyAttributes
1493+
---@return Fonts|FontFamilyAttributes
1494+
function Wezterm.font(attributes) end

0 commit comments

Comments
 (0)