dankamongmen / notcurses

blingful character graphics/TUI library. definitely not curses.
https://nick-black.com/dankwiki/index.php/Notcurses
Other
3.48k stars 112 forks source link

Pressing bare Escape results in busy loop on input until regular input is seen #2647

Closed dankamongmen closed 2 years ago

dankamongmen commented 2 years ago

Launch notcurses-input -v. Press Escape. Output suddenly becomes pretty much continuous (there might be some small delays?) until you press a letter or something else. Pressing Escape again does not resolve the problem.

dankamongmen commented 2 years ago

this was seen in Alacritty. i'm not sure if it happens everywhere else, particularly Kitty. also, see #2646 .

dankamongmen commented 2 years ago

this does not appear to happen with Kitty. so it's probably closely related to #2646.

dankamongmen commented 2 years ago

looping starts here:

block_on_input:2461:poll returned 1
block_on_input:2479:got events: tI
read_input_nblock:2091:read 1B from 0 (8191B left)
process_melange:2293:input 0 (0)/1 [0x1b] ( )
process_escape:2128:initialized automaton to 1
block_on_input:2377:blocking on input availability
block_on_input:2381:nonblocking read to check for completion
block_on_input:2434:waiting on 1 fds (ibuf: 1/8192)
block_on_input:2461:poll returned 0
block_on_input:2479:got events: ti
process_melange:2293:input 0 (1)/1 [0x1b] ( )
block_on_input:2377:blocking on input availability
block_on_input:2381:nonblocking read to check for completion
block_on_input:2434:waiting on 1 fds (ibuf: 1/8192)
block_on_input:2461:poll returned 0
block_on_input:2479:got events: ti
process_melange:2293:input 0 (1)/1 [0x1b] ( )
block_on_input:2377:blocking on input availability
block_on_input:2381:nonblocking read to check for completion
block_on_input:2434:waiting on 1 fds (ibuf: 1/8192)
block_on_input:2461:poll returned 0
block_on_input:2479:got events: ti
process_melange:2293:input 0 (1)/1 [0x1b] ( )
block_on_input:2377:blocking on input availability
dankamongmen commented 2 years ago

so why are we getting such fast returns from poll() despite it returning 0? and why aren't we returning this bare Escape?

dankamongmen commented 2 years ago

so what's going on here is tied tightly in with #2646, in that we ought be doing a nonblocking (as opposed to our normal blocking) read when in the middle of an escape, yes, but we're doing constant nonblocking reads. if the first one comes back and doesn't continue our escape, we need reset midescape. that ought fix both this and #2646.

dankamongmen commented 2 years ago

so we do reset midescape high in block_on_input(), which suggests to me that the failure is in process_escapes() -- we ought be setting midescape high only when at the end of a full input buffer.

dankamongmen commented 2 years ago

yeah we're missing that logic, it appears. fixing it up now and updating #2648