peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.05k stars 132 forks source link

Check winch before prompt. #91

Closed jcrussell closed 7 years ago

jcrussell commented 7 years ago

If the terminal starts out too narrow, liner never invokes s.readNext meaning that it will never receive the SIGWINCH to indicate that the terminal has been resized (and doesn't call s.getColumns otherwise). This patch checks the channel before doing the too narrow check and updates the column size, if there was an update.

Future improvement would be to detect SIGWINCH in s.tooNarrow and abort s.promptUnsupported.

peterh commented 7 years ago

Thanks for the patch.

peterh commented 7 years ago

Sorry, I had to revert this commit because it broke the build on Windows.

jcrussell commented 7 years ago

Oh, the windows State doesn't have the winch channel. I could add a dummy channel to it or we could add another OS-specific function that checks winch and resizes.

peterh commented 7 years ago

I would prefer you fix the other side. It is clearly a bug to launch an interactive application with a tty size of 0x0. (Even if it's some client-server thing that doesn't know the final size yet, the initial value should be some standard size like 80x25, or at least the CGA 40x25).

If you must work around their bug by modifying liner, I suggest calling s.getColumns() unconditionally instead of trying to detect SIGWINCH. (There's already a call to s.getColumns(); you may be able to move it instead of adding a 2nd one)

jcrussell commented 7 years ago

I ran into kr/pty#24 -- the default size is 0x0. I'm not sure that there's really a work around.

Restructuring some of the code might be a good idea. I get similar issues if I resize a terminal too small and enter a line -- it permanently gets stuck in the tooNarrow state.

A somewhat related issue is that the tooNarrow terminal may need to be invoked between restartPrompt and mainLoop if the terminal becomes too narrow (or the prompt is too long).