readline icon indicating copy to clipboard operation
readline copied to clipboard

Implement proper Windows redisplay on resize

Open maxlandon opened this issue 1 year ago • 0 comments

Resize events on Windows are sent through stdin. The key-reader code in readline currently detects and notifies the display about them, correctly.

Problem

There is a bug that is only triggered when there is no autosuggested line to display for the current input buffer: On resize event, the cursor is move at the end of the last line of completions, if any, and for no reason (no code in the display engine does such a move), which then causes the redisplay to start at the beginning of the last line of completions.

If there is an autosuggested line displayed at the moment of the resize event, the display handles the refresh just fine.

Attempts

There is commented out code in https://github.com/reeflective/readline/blob/master/internal/display/display_windows.go, which is an attempt at solving this by replacing the cursor back at the current input cursor position, before calling the engine to refresh itself. However this implementation is not stable, it does not work at times, and it is ugly anyway.

Suspicions

At the first glance, I suspect Windows of introducting a weird behavior on this (which is here to move the cursor after the last non-empty character in the terminal buffer. Therefore, help from someone with a better instinct and knowledge of Windows terminal internals would be greatly appreciated.

Related files:

  • Display engine: https://github.com/reeflective/readline/blob/master/internal/display/engine.go
  • Resize events handler: https://github.com/reeflective/readline/blob/master/internal/display/display_windows.go

maxlandon avatar Jun 02 '23 14:06 maxlandon