Now that the toml file support is removed, we can directly
express the key actions as enum variants so remove this
intermediate type and use the enum directly.
https://github.com/AppImage/AppImageKit/issues/368 introduced a way
to maintain configuration alongside an AppImage file stored on a
flash drive:
```
wez@cube-localdomain /tmp/portable-wezterm
9:06 130 $ ls -al
total 8720
drwxrwxr-x. 4 wez wez 100 May 6 08:54 ./
drwxrwxrwt. 19 root root 580 May 6 09:05 ../
-rwxr-xr-x. 1 wez wez 8929256 May 6 08:59 WezTerm-20200505-090057-31c6155f-Fedora31.AppImage*
drwxrwxr-x. 3 wez wez 60 May 6 08:15 WezTerm-20200505-090057-31c6155f-Fedora31.AppImage.config/
drwxrwxr-x. 2 wez wez 40 May 6 08:54 WezTerm-20200505-090057-31c6155f-Fedora31.AppImage.home/
```
When launched and these `<IMAGE>.config` and/or `<IMAGE>.home` dirs
exist, the appimage machinery will redirect the HOME and XDG_CONFIG_DIR
env vars to point to those locations instead of the normal place.
We weren't respecting XDG_CONFIG_DIR (fixed in this commit), but we also
need to take care: we don't want to re-export those locations to
children of wezterm so we need to load those values and then clean
up the environment.
On windows, prevent console subsystem processes spawned by
lua (such as the `wsl -l` example configuration) from momentarily
popping up and stealing the focus. This was happening too fast
to see in most cases, but could cause the wezterm window to momentarily
repaint its title bar with lose focus before regaining it.
This commit adds some helper functions that make it possible to
dynamically discover and add WSL distributions to the launcher
menu.
refs: https://github.com/wez/wezterm/issues/159
This commit tackles a couple of things in related areas:
Makes it possible to reference the KeyAssignment type directly from the
KeyAction action type. Previously, due to limitations in how TOML is
serialized, the enum values could be used here; while the compiler would allow
it, it is impossible to construct a TOML value for this sort of enum. Now that
we have lua we have more flexibility in the table type and this is unblocked.
In practical terms this means that we can do away with the janky `arg` field
and just use the `action` field directly, which also means that we can do away
with a whole extra enum that duplicates just the enum variants and makes
maintenance easier!
Adds `wezterm.action` to lua which helps to construct these enum variants. The
helper is used like this in the `.wezterm.lua` file:
```lua
local wezterm = require 'wezterm';
return {
keys = {
{key="{", mods="SHIFT|CTRL", action=wezterm.action{ActivateTabRelative=-1}},
{key="}", mods="SHIFT|CTRL", action=wezterm.action{ActivateTabRelative=1}},
}
}
```
the above creates values like `KeyAssignment::ActivateTabRelative(-1)`
in a not totally awful syntax.
On top of this, which was the main reason for doing this work, this
commit adds two new variants to KeyAssignment that are accessible
on from lua (because of the TOML limitations mentioned above);
`SpawnCommandInNewWindow` and `SpawnCommandInNewTab` that take a
`SpawnCommand` struct as their parameter. These actions are
conceptually similar to the existing `SpawnTab` key assignment
but allow specifying the program to be run as well as its cwd
and environment.
For example, this key assignment spawns `top` in a new window:
```lua
{key="y", mods="CMD", action=wezterm.action{SpawnCommandInNewWindow={
args={"top"}
}}},
```
The intent is to use this as a building block for saved/canned
commands.
refs: https://github.com/wez/wezterm/issues/159
implementing the `ToLua` and `FromLua` traits allows `create_function`
to automatically apply the appropriate conversions to the parameters
and return values in a callback function.
That makes it possible (and nicer!) to write properly typed callbacks.
This tidies up the part of the config syntax that I most disliked:
```lua
font = {
font = {{
family = "Operator Mono SSm Lig Medium",
}},
},
```
can now be as simple as:
```lua
font = wezterm.font("Operator Mono SSm Lig Medium"),
```
Here's the font related section from my config:
```lua
local wezterm = require 'wezterm';
return {
font = wezterm.font("Operator Mono SSm Lig Medium"),
font_rules= {
{
italic = true,
font = wezterm.font("Operator Mono SSm Lig Medium Italic"),
},
{
italic = true,
intensity = "Bold",
font = wezterm.font("Operator Mono SSm Lig Book Italic"),
},
{
intensity = "Bold",
font = wezterm.font("Operator Mono SSm Lig Bold", {foreground = "tomato"}),
},
{
intensity = "Half",
font = wezterm.font("Operator Mono SSm Lig Light"),
},
},
}
```
This allows for slightly more fancy configuration in the future, but for
now it is rather simple: your lua script returns a configuration struct
with the same shape as that from the TOML file.
A `wezterm` module is provided to the script that provides some
constants to help understand the environment in which wezterm
is running.
I want to add some helpers that make setting up the fonts feel less
weird (lots of nesting in the data model makes this weird).
The ability to conditionally construct configuration is powerful
and helps to address the broader request in
refs: https://github.com/wez/wezterm/issues/152
An example config looks like this:
```lua
local wezterm = require 'wezterm';
print(wezterm.config_dir);
print(wezterm.executable_dir);
wezterm.log_error("w00t! running " .. wezterm.version
.. " on " .. wezterm.target_triple .. " " .. wezterm.home_dir);
return {
enable_scroll_bar = true,
enable_tab_bar = true,
ratelimit_output_bytes_per_second = 400000,
scrollback_lines = 350000,
font_dirs = {".dotfiles/fonts"},
window_padding = {
left = 2,
bottom = 2,
},
font = {
font = {{
family = "Operator Mono SSm Lig Medium",
}},
},
unix_domains = {
{
name = "unix",
}
},
ssh_domains = {
{
name = "localhost",
remote_address = "localhost",
username = "wez",
},
},
tls_clients = {
{
name = "cubetls",
remote_address = "cube-localdomain:8080",
bootstrap_via_ssh = "cube-localdomain",
},
},
tls_servers = {
{
bind_address = "192.168.1.8:8080",
},
},
hyperlink_rules = {
{
regex = "\\b\\w+://(?:[\\w.-]+)\\.[a-z]{2,15}\\S*\\b",
format = "$0",
},
},
font_rules= {
{
italic = true,
font = {
font = {{
family = "Operator Mono SSm Lig Medium Italic",
}}
},
},
{
italic = true,
intensity = "Bold",
font = {
font = {{
family = "Operator Mono SSm Lig Book Italic",
}}
},
},
{
intensity = "Bold",
font = {
foreground = "tomato",
font = {{
family = "Operator Mono SSm Lig Bold",
}}
},
},
{
intensity = "Half",
font = {
font = {{
family = "Operator Mono SSm Lig Light",
}}
},
},
},
}
```