Adopting WezTerm

I’ve recently discovered WezTerm, also known as “Wez’s Terminal Emulator” by Wez Furlong, and I’ve adopted it completely, becoming my default terminal application.

How did I find this tool? Reading the documentation of presenterm, an open source tool used to create presentation slides on the terminal. Following the same documentation, I had already tried kitty (made by Kovid Goyal, the creator of the Calibre e-book management tool) but I was not convinced and stopped using it.

Visually, well, WezTerm just looks exactly as you would expect. The differences with other similar terminal emulators are more subtle, as always.

As explained in the website,

WezTerm is a powerful cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust

WezTerm has plenty of interesting features, including that of being available for Windows, Mac, FreeBSD, and Linux (Flatpak, AppImage, as a raw binary, and for plenty of popular distributions). I appreciate being able to use the same terminal with the same settings in various operating systems.

Oh, and it has a great name.

In my testing, WezTerm appears as very stable, extremely fast, and with countless configuration options. Just to give you an idea, it comes bundled with its own default fonts, and has literally almost a thousand color schemes available. Also noteworthy, the documentation website provided by the author is simply extraordinary in depth and quality.

And, needless to say, it’s open source.

WezTerm uses the Lua programming languages for its configuration. One neat feature is that it reloads the configuration automatically upon edition, which is very handy, particularly when testing color schemes. And by the way, this is how my own configuration file looks like at the time of the publication of this article:

-- Pull in the wezterm API
local wezterm = require 'wezterm'

-- This will hold the configuration.
local config = wezterm.config_builder()

-- Set the color scheme depending on the system setting
function get_appearance()
  if wezterm.gui then
    return wezterm.gui.get_appearance()
  end
  return 'Dark'
end

function scheme_for_appearance(appearance)
  if appearance:find 'Dark' then
    return 'iTerm2 Dark Background'
  else
    return 'Alabaster'
  end
end

config.color_scheme = scheme_for_appearance(get_appearance())

-- Remove all padding
config.window_padding = { left = 0, right = 0, top = 0, bottom = 0 }

-- F11 to toggle fullscreen mode
config.keys = {
  { key = 'F11', action = wezterm.action.ToggleFullScreen },
}

-- URLs in Markdown files are not handled properly by default
-- Source: https://github.com/wez/wezterm/issues/3803#issuecomment-1608954312
config.hyperlink_rules = {
  -- Matches: a URL in parens: (URL)
  {
    regex = '\\((\\w+://\\S+)\\)',
    format = '$1',
    highlight = 1,
  },
  -- Matches: a URL in brackets: [URL]
  {
    regex = '\\[(\\w+://\\S+)\\]',
    format = '$1',
    highlight = 1,
  },
  -- Matches: a URL in curly braces: {URL}
  {
    regex = '\\{(\\w+://\\S+)\\}',
    format = '$1',
    highlight = 1,
  },
  -- Matches: a URL in angle brackets: <URL>
  {
    regex = '<(\\w+://\\S+)>',
    format = '$1',
    highlight = 1,
  },
  -- Then handle URLs not wrapped in brackets
  {
    -- Before
    --regex = '\\b\\w+://\\S+[)/a-zA-Z0-9-]+',
    --format = '$0',
    -- After
    regex = '[^(]\\b(\\w+://\\S+[)/a-zA-Z0-9-]+)',
    format = '$1',
    highlight = 1,
  },
  -- implicit mailto link
  {
    regex = '\\b\\w+@[\\w-]+(\\.[\\w-]+)+\\b',
    format = 'mailto:$0',
  },
}

-- Font configuration
config.font = wezterm.font 'IBM Plex Mono'
config.freetype_load_target = 'Light'
config.freetype_render_target = 'HorizontalLcd'

-- Remove the title bar from the window
config.window_decorations = "INTEGRATED_BUTTONS | RESIZE"

-- Use zsh by default
config.default_prog = { '/usr/bin/zsh' }

-- Don't hide cursor when typing
config.hide_mouse_cursor_when_typing = false

-- Return the configuration to wezterm
return config