Terminal.Gui icon indicating copy to clipboard operation
Terminal.Gui copied to clipboard

Harden `EscSeqUtils`

Open tig opened this issue 2 years ago • 2 comments

NetDriver in v2 has bad keyboard behavior because of this.

There is a bug somewhere that is causing isEscSeq to be true with cki being null. I've added a defensive check for this as I've not been able to reliably reproduce it in a way that shows me what's causing it.

I discovered something else that indicates EscSeqUtils may need to be refactored.

If the user presses a key while the terminal is sending an esc sequence (e.g. a '[35` mouse move report), that key info is lost. The result of this is no keystrokes can happen while the user is moving the mouse.

As we move to a world where all drivers rely heavily on emitting and receiving escape sequences, we need EscSeqUtils to be very robust and flexible. It works pretty darn good right now (great job!) but it is fragile and brittle. It doesn't help that the documentation for ANSI sequences and all the implementations are so sketchy.

I still haven't figured out what I screwed up in #2612 that has broken netdriver in this regard, FWIW.

Originally posted by @tig in https://github.com/gui-cs/Terminal.Gui/issues/2745#issuecomment-1633231049

tig avatar Aug 11 '23 14:08 tig

Time to times I'm getting this error and the escape sequences always start with \u001b[04; and aleatory number at the end. I think this related with some color escape sequence that Console is reading while the mouse is moving. @tig are you sure you are sending escape sequences for colors at once and not waiting for some condition that will cause they are incomplete?

imagem

imagem

BDisp avatar Aug 22 '23 13:08 BDisp

This mainly happens on opening a scenario because they are always running Init and Shutdown and although the Application doing a disposing of public variables there are threads that are being executed on others objects, like NetEvents. On ResetState it call MainLoop?.Stop() which only set _running = false and call MainLoopDriver.Wakeup () that only wake if it's hang to force an iteration. While the IMainLoopDriver doesn't have a End as the ConsoleDriver have, it isn't possible to dispose any thread object to avoid propagating events for the new app that belong to the latest closed. For now it can be done through the ConsoleDriver by accessing the mainloop.

BDisp avatar Aug 22 '23 23:08 BDisp