Skip to content

Commit

Permalink
feat(plugins): wezterm integration (folke#61)
Browse files Browse the repository at this point in the history
* feat: wezterm integration

This adds support for font-size adaptation in the wezterm terminal.

References:
- wez/wezterm#2550
- https://www.reddit.com/r/neovim/comments/xn1q75/comment/iprdrpr

* Update wezterm integration docs

* Fix markdown codeblock
  • Loading branch information
mrossinek authored Apr 17, 2023
1 parent d907e63 commit 6b9c522
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Distraction-free coding for Neovim >= 0.5
- hide [tmux](https://github.com/tmux/tmux) status line
- increase [Kitty](https://sw.kovidgoyal.net/kitty/) font-size
- increase [Alacritty](https://alacritty.org/) font-size
- increase [wezterm](https://wezfurlong.org/wezterm/) font-size
- **Zen Mode** is automatically closed when a new non-floating window is opened
- works well with plugins like [Telescope](https://github.com/nvim-telescope/telescope.nvim) to open a new buffer inside the Zen window
- close the Zen window with `:ZenMode`, `:close` or `:quit`
Expand Down Expand Up @@ -118,6 +119,13 @@ EOF
enabled = false,
font = "14", -- font size
},
-- this will change the font size on wezterm when in zen mode
-- See alse also the Plugins/Wezterm section in this projects README
wezterm = {
enabled = false,
-- can be either an absolute font size or the number of incremental steps
font = "+4", -- (10% increase per step)
},
},
-- callback where you can add custom code when the Zen window opens
on_open = function(win)
Expand All @@ -142,6 +150,40 @@ require("zen-mode").toggle({
})
```

## 🧩 Plugins

### Wezterm

In order to make the integration with wezterm work as intended, you need to add
the following function to your wezterm config:

```lua
wezterm.on('user-var-changed', function(window, pane, name, value)
local overrides = window:get_config_overrides() or {}
if name == "ZEN_MODE" then
local incremental = value:find("+")
local number_value = tonumber(value)
if incremental ~= nil then
while (number_value > 0) do
window:perform_action(wezterm.action.IncreaseFontSize, pane)
number_value = number_value - 1
end
overrides.enable_tab_bar = false
elseif number_value < 0 then
window:perform_action(wezterm.action.ResetFontSize, pane)
overrides.font_size = nil
overrides.enable_tab_bar = true
else
overrides.font_size = number_value
overrides.enable_tab_bar = false
end
end
window:set_config_overrides(overrides)
end)
```

See also: https://github.com/wez/wezterm/discussions/2550

## Inspiration

- Visual Studio Code [Zen Mode](https://code.visualstudio.com/docs/getstarted/userinterface#_zen-mode)
Expand Down
7 changes: 7 additions & 0 deletions lua/zen-mode/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ local defaults = {
enabled = false,
font = "14", -- font size
},
-- this will change the font size on wezterm when in zen mode
-- See alse also the Plugins/Wezterm section in this projects README
wezterm = {
enabled = false,
-- can be either an absolute font size or the number of incremental steps
font = "+4", -- (10% increase per step)
},
},
-- callback where you can add custom code when the zen window opens
on_open = function(_win) end,
Expand Down
11 changes: 11 additions & 0 deletions lua/zen-mode/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ function M.alacritty(state, disable, opts)
vim.cmd([[redraw]])
end

-- changes the wezterm font size
function M.wezterm(state, disable, opts)
local stdout = vim.loop.new_tty(1, false)
if disable then
stdout:write(('\x1b]1337;SetUserVar=%s=%s\b'):format('ZEN_MODE', vim.fn.system({ 'base64' }, tostring(opts.font))))
else
stdout:write(('\x1b]1337;SetUserVar=%s=%s\b'):format('ZEN_MODE', vim.fn.system({ 'base64' }, '-1')))
end
vim.cmd([[redraw]])
end

function M.twilight(state, disable)
if disable then
state.enabled = require("twilight.view").enabled
Expand Down

0 comments on commit 6b9c522

Please sign in to comment.