kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.13k stars 971 forks source link

Scrollback buffer corruption when resizing and font: misplaced newline #7033

Closed adamdicarlo closed 8 months ago

adamdicarlo commented 8 months ago

Describe the bug

A scrollback line is broken (line-broken) several characters too soon, somewhere in the process of:

To Reproduce

kitty --config NONE -o allow_remote_control=y bash -c '
  sleep 1
  cols=$(tput cols)
  rows=$(tput lines)
  for (( y = 0 ; y < $rows; y++ )); do
    printf "["
    for (( x = 2; x < $cols; x++ )); do
      if (( y % 2 == 0 )); then
        printf "="
      else
        printf "."
      fi
    done
    printf "]"
  done
  sleep 0.5
  kitty @ set-font-size +1
  kitty @ set-font-size -- -1
  kitty @ scroll-window start
  read
'

(I got the idea to write this from the repro script in https://github.com/kovidgoyal/kitty/issues/2619 👍🏼 )

You may not need the leading sleep 1 in the script. I seemed to need it to allow Sway time enough to get the new window into its final size.

I experimented with the rows setting in the script and found interesting things. For instance:

  # The errantly inserted line break occurs one line before it does normally
  rows=$(( $(tput lines) - 1 ))

  # No bug happens -- I guess there are not enough lines for output to scroll
  # off the top of the viewport?
  rows=$(( $(tput lines) / 2 ))

P.S. Thank you for kitty! I've been using it for several years, and I :heart: it! :)

Screenshots

20240120-192133-screen

Environment details

Press Ctrl+Shift+F6 [...]

This didn't work for me; I just got the message below. I'm on a fairly crusty Arch system that's been installed for about four years, so maybe something is misconfigured due to too much experimentation over the years. I can reproduce and post debug info from my work machine, too, though, if that's helpful!

Failed to launch child: usr/bin/less
With error: No such file or directory
Press Enter or Esc to exit
adamdicarlo commented 8 months ago

Oh hey, after thinking about the Ctrl+Shift+F6 error, I tried it again from / directory, and it worked. Then I realized the error was due to my config file, and went and fixed it, lol...

Ctrl+Shift+F6 debug output kitty 0.30.1 created by Kovid Goyal Linux carbo 6.5.9-arch2-1 #1 SMP PREEMPT_DYNAMIC Thu, 26 Oct 2023 00:52:20 +0000 x86_64 Arch Linux 6.5.9-arch2-1 (/dev/tty) Running under: Wayland Frozen: False Paths: kitty: /usr/bin/kitty base dir: /usr/lib/kitty extensions dir: /usr/lib/kitty/kitty system shell: /usr/bin/zsh Loaded config files: /home/adam/.config/kitty/kitty.conf Config options different from defaults: active_tab_font_style (True, False) allow_remote_control yes click_interval 0.5 copy_on_select clipboard cursor_shape 2 cursor_stop_blinking_after 0 cursor_text_color None enable_audio_bell False font_family JetBrains Mono font_size 10.0 initial_window_height (1100, 'px') initial_window_width (1400, 'px') input_delay 2 modify_font: cell_height 0 cell_width 0 mouse_hide_wait 0.0 remember_window_size False repaint_delay 20 scrollback_lines 30000 scrollback_pager ['usr/bin/less'] select_by_word_characters :@-./_~?&=%+# sync_to_monitor False tab_bar_style powerline tab_separator ┇ url_style 2 visual_bell_duration 0.12 wheel_scroll_multiplier 6.0 window_border_width (0, 'pt') window_padding_width FloatEdges(left=4.0, top=4.0, right=4.0, bottom=4.0) Changed shortcuts: kitty_mod+- → decrease_font_size kitty_mod+= → increase_font_size kitty_mod+backspace → restore_font_size kitty_mod+h → scroll_line_up kitty_mod+j → show_scrollback kitty_mod+k → scroll_line_down Colors: active_tab_background #f8f8f2 active_tab_foreground #44475a background #282a36 color0 #21222c color1 #ff5555 color10 #69ff94 color11 #ffffa5 color12 #d6acff color13 #ff92df color14 #a4ffff color2 #50fa7b color3 #f1fa8c color4 #bd93f9 color5 #ff79c6 color6 #8be9fd color7 #f8f8f2 color8 #6272a4 color9 #ff6e6e cursor #f8f8f2 foreground #f8f8f2 inactive_tab_background #6272a4 inactive_tab_foreground #282a36 selection_background #f8f8f2 selection_foreground #44475a url_color #ffb86c Important environment variables seen by the kitty process: PATH /usr/local/bin:/usr/bin LANG en_US.utf8 SHELL /usr/bin/zsh DISPLAY :0 WAYLAND_DISPLAY wayland-1 USER adam XCURSOR_SIZE 24 XDG_SEAT seat0 XDG_SESSION_DESKTOP sway XDG_SESSION_TYPE wayland XDG_CURRENT_DESKTOP sway XDG_SESSION_CLASS user XDG_VTNR 2 XDG_SESSION_ID 10 XDG_RUNTIME_DIR /run/user/1000 XDG_DATA_DIRS /home/adam/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/
kovidgoyal commented 8 months ago

This is expected. History and screen are different buffers. So when you end up with a line split between them, on reflow that line doesnt get re-stitched. In general, re-stitching is a pretty complex operation, you would need to move part of the first line of the screen into the last line of history, and then that move might well cascade all the way down to the rest of the screen (when the first line of the screen has more content than will fit in the last line of history and is itself wrapped). As such, the complexity is not worth it, IMO. But if you feel differently, patches are most welcome. Relevant code is in rewrap.h