wez / wezterm

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

Screen redraw on macOS when using (Neo)vim #4102

Open omar25h opened 1 year ago

omar25h commented 1 year ago

What Operating System(s) are you seeing this problem on?

macOS

Which Wayland compositor or X11 Window manager(s) are you using?

yabai

WezTerm version

20230806-091840-2a7167a0

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

It seems that there is an issue with the redrawing of the screen whenever scrolling in neovim.

https://github.com/wez/wezterm/assets/5558211/6c5646cb-1330-4470-aef6-f891627da1c6

To Reproduce

wezterm-recording-REMpIT.cast.txt

Configuration

local wezterm = require 'wezterm'
local act = wezterm.action

local function font_with_fallback(name, params)
  local names = { name, 'Noto Color Emoji', 'JetBrains Mono' }
  return wezterm.font_with_fallback(names, params)
end

local function get_appearance()
  if wezterm.gui then return wezterm.gui.get_appearance() end
  return 'Dark'
end

local function scheme_for_appearance(appearance)
  if appearance:find 'Dark' then return 'GruvboxDark' end
  return 'Gruvbox (Gogh)'
end

local function colors_for_appearance(appearance)
  if appearance == nil then return {} end
  if appearance:find 'Dark' then
    return {
      foreground = '#ebdbb2',
      background = '#282828',

      cursor_bg = '#bdae93',
      cursor_fg = '#665c54',

      selection_fg = '#ebdbb2',
      selection_bg = '#d65d0e',

      scrollbar_thumb = '#222222',

      split = '#444444',

      ansi = {
        '#3c3836',
        '#cc241d',
        '#98971a',
        '#d79921',
        '#458588',
        '#b16286',
        '#689d6a',
        '#a89984',
      },
      brights = {
        '#928374',
        '#fb4934',
        '#b8bb26',
        '#fabd2f',
        '#83a598',
        '#d3869b',
        '#8ec07c',
        '#fbf1c7',
      },

      indexed = { [136] = '#af8700' },
      compose_cursor = 'orange',
    }
  else
    return {}
  end
end

wezterm.on('update-status', function(window, pane)
  local leader = ''
  if window:leader_is_active() then leader = '(L)  ' end

  window:set_right_status(wezterm.format {
    { Text = leader .. window:active_workspace() .. '    ' },
  })
end)

wezterm.on(
  'window-config-reloaded',
  function(window, pane) window:toast_notification('wezterm', 'Configuration reloaded!', nil, 4000) end
)

local function tab_title(tab_info)
  local title = tab_info.tab_title
  local zoom = ''
  if tab_info.active_pane.is_zoomed then zoom = ' (Z)' end

  if title and #title > 0 then return title .. zoom end
  return tab_info.active_pane.title .. zoom
end

wezterm.on('format-tab-title', function(tab, tabs, panes, config, hover, max_width)
  local title = tab_title(tab)

  if tab.is_active then return {
    { Background = { Color = 'Black' } },
    { Text = ' ' .. title .. ' ' },
  } end
  return title
end)

local config = {}
if wezterm.config_builder then config = wezterm.config_builder() end

config.term = 'wezterm'
config.adjust_window_size_when_changing_font_size = false
config.font = font_with_fallback('Maple Mono', { weight = 'Regular' })
config.font_size = 17.0
config.line_height = 1.45
config.font_rules = {
  { italic = true, font = font_with_fallback('Maple Mono', { weight = 'Regular', style = 'Italic' }) },
  {
    italic = true,
    intensity = 'Bold',
    font = font_with_fallback('Maple Mono', { weight = 'Bold', style = 'Italic' }),
  },
  { intensity = 'Bold', font = font_with_fallback('Maple Mono', { weight = 'Bold', style = 'Normal' }) },
}

config.use_resize_increments = false
config.use_fancy_tab_bar = true
config.hide_tab_bar_if_only_one_tab = false
config.window_decorations = 'INTEGRATED_BUTTONS | RESIZE| MACOS_FORCE_DISABLE_SHADOW'
config.allow_square_glyphs_to_overflow_width = 'Always'
config.command_palette_font_size = 16.0
config.front_end = 'WebGpu'
config.webgpu_power_preference = 'HighPerformance'
config.default_cursor_style = 'SteadyBlock'

config.window_frame = {
  font = wezterm.font { family = 'Roboto', weight = 'Bold' },
  font_size = 14.0,
  active_titlebar_bg = '#333333',
  inactive_titlebar_bg = '#333333',
}

config.color_scheme = scheme_for_appearance(get_appearance())
config.colors = colors_for_appearance(get_appearance())

config.leader = { key = '/', mods = 'SUPER', timeout_milliseconds = 2000 }

config.keys = {
  { key = 'UpArrow', mods = 'SUPER', action = act.ActivatePaneDirection 'Up' },
  { key = 'DownArrow', mods = 'SUPER', action = act.ActivatePaneDirection 'Down' },
  { key = 'LeftArrow', mods = 'SUPER', action = act.ActivatePaneDirection 'Left' },
  { key = 'RightArrow', mods = 'SUPER', action = act.ActivatePaneDirection 'Right' },
  { key = 'p', mods = 'SUPER', action = act.ActivateCommandPalette },
  { key = 'z', mods = 'LEADER', action = act.TogglePaneZoomState },
  { key = 'e', mods = 'LEADER|CTRL', action = act.PaneSelect },
  { key = '%', mods = 'LEADER|SHIFT', action = act.SplitHorizontal { domain = 'CurrentPaneDomain' } },
  { key = '"', mods = 'LEADER|SHIFT', action = act.SplitVertical { domain = 'CurrentPaneDomain' } },
  { key = '/', mods = 'LEADER|SUPER', action = act.ActivateLastTab },
  { key = 'i', mods = 'CTRL|SHIFT', action = act.SwitchToWorkspace },
  { key = 's', mods = 'LEADER', action = act.ShowLauncherArgs { flags = 'FUZZY|WORKSPACES' } },
  { key = '[', mods = 'SUPER', action = act.ActivateTabRelative(-1) },
  { key = ']', mods = 'SUPER', action = act.ActivateTabRelative(1) },
  {
    key = ',',
    mods = 'LEADER',
    action = act.PromptInputLine {
      description = 'Enter new name for tab',
      action = wezterm.action_callback(function(window, pane, line)
        -- line is set only if enter is entered
        if line then window:active_tab():set_title(line) end
      end),
    },
  },
}

config.unix_domains = {
  { name = 'unix' },
}

config.default_gui_startup_args = { 'connect', 'unix' }

config.window_padding = {
  left = '1cell',
  right = '1cell',
  top = '0.5cell',
  bottom = '0.25cell',
}

return config

Expected Behavior

No response

Logs

No response

Anything else?

No response

wez commented 1 year ago

Please capture a terminal recording:

*** Finished recording to /var/tmp/wezterm-recording-sF6B3u.cast.txt

The file is an asciicast (compatible with https://asciinema.org/) and can also be replayed using wezterm replay.

The terminal recording allows me to replicate what is being sent to the terminal without requiring me to install the same applications as you and replicate your configuration for everything.

omar25h commented 1 year ago

@wez recording added

omar25h commented 1 year ago

I got to realize that this happens only when connected to a UNIX domain. It does not happen when config.default_gui_startup_args = {}

tjex commented 11 months ago

Also happening to me.

version nightly: wezterm 20231128-074654-90ca1117

mac os 13.5 (going to upgrade soon...)

Also using yabai. But it happens with yabai disabled as well.

term.cast.txt

shahamran commented 10 months ago

Happens to me as well, both on UNIX and SSHMUX sessions.

eratio08 commented 9 months ago

Same issue

I'm also using the unix domain (like https://github.com/wez/wezterm/issues/4102#issuecomment-1732358322)

config.unix_domains = { { name = 'unix' } }
config.default_gui_startup_args = { 'connect', 'unix' }
tjex commented 6 months ago

Update. This is also effecting windows in general throughout various TUI apps of mine. Closed screens are simply left in place visually, and then drawn over once I start to move around / edit within the actual screen I'm supposed to be seeing.

Disabling mux totally for the moment as well which has rendered my launcher unusable as well as skhd spawn window global commands :( If anyone can point me towards where I can:

shahamran commented 5 months ago

Did anyone find a workaround? I really prefer (and rely on) wezterm's mux feature over tmux, but I can't use neovim inside it, which makes it unusable :(

etiennecollin commented 5 months ago

Hello! Simply adding a comment because I too am affected by this issue on macOS 14.4.1. It makes wezterm unusable with neovim.

When I go into insert mode and make modifications, nothing appears/updates on the screen until I hit esc a few times which redraws the screen. Even in normal mode, when I move the cursor with hjkl or the arrows, the cursor does not move and only jumps to where it should be when I go into insert mode (moves are registered, but only drawn when changing mode redraws the window).

Note that this issue does not happen immediately for me, but after a certain amount of time (I haven't timed it). It makes me think of the way a memory leak makes an app crash after a while.

I do not have this issue in iTerm2 with the same exact config otherwise. Thank you if you are able to fix this and thank you for your amazing work!

Here is my config:

local config = {}

local wezterm = require("wezterm")
if wezterm.config_builder then
    config = wezterm.config_builder()
end

-- Configure looks
config.color_scheme = "Sonokai (Gogh)"
config.font = wezterm.font("JetBrains Mono", { weight = "Regular" })
config.font_size = 16

-- Configure window opacity
config.window_background_opacity = 1

config.inactive_pane_hsb = {
    saturation = 0.8,
    brightness = 0.7,
}

-- Config for window
config.hide_tab_bar_if_only_one_tab = true
config.window_frame = {
    font_size = 16,
}
config.window_decorations = "RESIZE"
config.window_padding = { left = 10, right = 10, top = 10, bottom = 0 }

-- Other settings
config.use_dead_keys = true
config.enable_scroll_bar = true
config.adjust_window_size_when_changing_font_size = false

return config
artagnon commented 5 months ago

As described in #5481, this bug reproduces with a simple sequence of dd and u (although up to five or six attempts may be required): unfortunately, the ascii screen capture doesn't show the bug. The bug is not reproducible on vim with the multiplexer, or on neovim without the multiplexer.

etiennecollin commented 4 months ago

I have recorded a brief example of the issue (I'll try to post a better one when I can, but as usual, these problems tend to occur when I'm not recording!). The issue is intermittent and challenging to diagnose, yet it happens quite frequently.

In my situation, everything is up to date, and I have encountered this issue on both macOS and Arch Linux.

This behavior occurs in both Neovim and the terminal itself. My recording is in Neovim, with an on-screen keylogger. If you play the video slowly, you can see that some actions are not displayed until another action is performed.

Here are some specifics from the recording:

When this issue occurs in the terminal, I can type commands, but the letters do not appear until I hit enter a few times. Additionally, when a command produces output, the output does not appear unless I press a key on the keyboard.

Thank you for your help and your amazing terminal! Here is the recording link for reference:

https://github.com/wez/wezterm/assets/99756528/f9699e26-0aa5-484f-acaa-4170c35963b8

Abdiramen commented 3 months ago

Happens to me as well, but on ssh sessions and on a different OS.

Worked around by setting multiplexing to None

config.ssh_domains = {
  -- rest of config here...
  multiplexing = 'None',
}
lucasrabiec commented 1 month ago

Same issue

  • macOS 14.2.1 (23C71)
  • wezterm wezterm 20230712-072601-f4abf8fd
  • neovim v0.9.5

I'm also using the unix domain (like #4102 (comment))

config.unix_domains = { { name = 'unix' } }
config.default_gui_startup_args = { 'connect', 'unix' }

Same for:

jacobb commented 2 weeks ago

I also had this affecting me for quite a while.

I'm wondering if anyone has experienced this with a recent-ish nightly/main build.

4607 has discussion around a similar combination (mux + neovim drawing) that has been resolved. I'm working against the source-built version from https://github.com/wez/wezterm/pull/5576 to test floating panes, and thought I would turn mux back on to see if it happened to fix this, and so far I have not hit it. Only a few hours of driving, though, so it's possible I'll hit it again. If so I can report back here.