wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
15.02k stars 681 forks source link

[Feature Request] Toggle ligatures in alternate-screen mode apps #5403

Closed LunarLambda closed 2 months ago

LunarLambda commented 2 months ago

Many programming fonts that feature ligatures don't generally look great when applied to typical line-based terminal output like shells, package managers etc. They do however tend to work much better in TUI/ncurses apps like vim, lazygit, mc, etc.

Those apps use a control sequence to enter the "alternate screen" mode, which does not have scrollback. This allows those apps to preserve the previous terminal output on exit. (smcup/rmcup control sequences).

It would be awesome if wezterm was able to toggle font features (or possibly even fonts) when entering/exiting the alternate screen mode, so that I could have e.g. ligatures ON in vim, but ligatures OFF otherwise.

Maybe this is something that can already be implemented in Lua, I'm not sure.

wez commented 2 months ago

I'm not going to build this into wezterm. Look at https://wezfurlong.org/wezterm/config/lua/window/set_config_overrides.html for an example of defining a key assignment that can enable/disable ligatures.

Look at https://wezfurlong.org/wezterm/config/lua/pane/is_alt_screen_active.html for a way to determine is the alt screen is active.

You could combine those and use them in your https://wezfurlong.org/wezterm/config/lua/window-events/update-status.html to get something like the effect you're asking about.

LunarLambda commented 2 months ago

Cool, I will take a look. thank you!

LunarLambda commented 2 months ago

the following does not appear to work

local w = require 'wezterm'

w.on('update-status', function(window, pane)
    local wo = window:get_config_overrides() or {}

    if pane:is_alt_screen_active() then
        print('on')
        wo.harfbuzz_features = { 'calt=1' }
    else
        print('off')
        wo.harfbuzz_features = { 'calt=0' }
    end

    window:set_config_overrides(wo)
end)

ligatures simply stayu always enabled. font setting is:

    font = w.font_with_fallback {
        {
            family = 'Berkeley Mono',
            harfbuzz_features = { },
        },
        {
            family = 'FiraCode Retina',
            harfbuzz_features = { 'ss03', 'ss05' }
        },
    },

The event does not seem to fire as documented:

13:41:57.465  INFO   logging > lua: off
13:41:57.537  INFO   logging > lua: off
13:41:57.622  INFO   logging > lua: off
13:41:57.715  INFO   logging > lua: off
13:41:57.761  INFO   logging > lua: off
13:41:57.886  INFO   logging > lua: off
13:41:57.925  INFO   logging > lua: off
13:41:58.923  INFO   logging > lua: off
13:41:59.621  INFO   logging > lua: off

is it not intended to run every 1000ms by default?

github-actions[bot] commented 1 month ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.