Bug when closing "micro" editor #4190

Closed
opened 2026-01-30 23:40:31 +00:00 by claunia · 7 comments
Owner

Originally created by @jeffrson on GitHub (Oct 1, 2019).

Environment

Windows build number: 10.0.18362.295
Windows Terminal version (if applicable): 0.5.2681.0

Any other software? Micro (https://micro-editor.github.io/)

Steps to reproduce

Run "micro test", press Ctrl-Q to close

Expected behavior

Terminal should show prompt and be ready for next command.

Actual behavior

Window is empty, first input key is ignored - say, I type "ver" - prompt appears after 'v', which is swallowed, leaving "er" in command.

Originally created by @jeffrson on GitHub (Oct 1, 2019). # Environment ```none Windows build number: 10.0.18362.295 Windows Terminal version (if applicable): 0.5.2681.0 Any other software? Micro (https://micro-editor.github.io/) ``` # Steps to reproduce Run "micro test", press Ctrl-Q to close # Expected behavior Terminal should show prompt and be ready for next command. # Actual behavior Window is empty, first input key is ignored - say, I type "ver" - prompt appears after 'v', which is swallowed, leaving "er" in command.
Author
Owner

@zadjii-msft commented on GitHub (Oct 1, 2019):

@jeffrson Does this repro in conhost.exe (launch cmd.exe, powershell.exe, wsl.exe directly), or only in Windows Terminal?

@zadjii-msft commented on GitHub (Oct 1, 2019): @jeffrson Does this repro in `conhost.exe` (launch `cmd.exe`, `powershell.exe`, `wsl.exe` directly), or only in Windows Terminal?
Author
Owner

@jeffrson commented on GitHub (Oct 1, 2019):

It only happens in Windows Terminal.

@jeffrson commented on GitHub (Oct 1, 2019): It only happens in Windows Terminal.
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 29, 2019):

Yeah: it looks like micro waits for a keypress before exiting, but only in Terminal?

@DHowett-MSFT commented on GitHub (Oct 29, 2019): Yeah: it looks like micro waits for a keypress before exiting, but only in Terminal?
Author
Owner

@jeffrson commented on GitHub (Oct 29, 2019):

Yes - "pure" PowerShell and cmd show prompt after exiting with Ctrl-Q

@jeffrson commented on GitHub (Oct 29, 2019): Yes - "pure" PowerShell and cmd show prompt after exiting with Ctrl-Q
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 30, 2019):

So, this is a fun one!

At the end of the day, micro is doing something strange. They are trying to read from the console one last time before quitting. When they read from the console, they get a bunch of individual keypress events in four different Read operations.

Here's what they do when they read from the console outside of Windows Terminal:

READ 1
 KEY_EVENT [Ctrl, Down]

READ 2
 KEY_EVENT [Q, Down]

Micro begins exiting because Ctrl+Q was pressed.
tcell (the terminal library they use) begins shutting down.
It waits for one more console event.

READ 3
 KEY_EVENT [Q, Up]

tcell finishes its final read.
Micro exits.
PowerShell or CMD takes over, and reads the console.

READ 4
 KEY_EVENT [Ctrl, Up]

PowerShell/CMD ignore the stray Ctrl key release, because they don't care.

Now, when they read and are attached to a terminal using ConPTY they get everything in a single read. Here's what that looks like.

READ 1
 KEY_EVENT [Ctrl, Down]
 KEY_EVENT [Q, Down]
 KEY_EVENT [Q, Up]
 KEY_EVENT [Ctrl, Up]

Micro begins exiting because Ctrl+Q were pressed.
tcell (the terminal library they use) begins shutting down.
It waits for one more console event.

Since the console was too "fast" for tcell/micro, it never got the last console event it was waiting for. It exits when the next one comes in.

This seems to be a design flaw in tcell... so I'm going to have to close it here.

@DHowett-MSFT commented on GitHub (Oct 30, 2019): So, this is a fun one! At the end of the day, micro is doing something strange. They are trying to read from the console one last time before quitting. When they read from the console, they get a bunch of individual keypress events in four different Read operations. Here's what they do when they read from the console outside of Windows Terminal: ``` READ 1 KEY_EVENT [Ctrl, Down] READ 2 KEY_EVENT [Q, Down] Micro begins exiting because Ctrl+Q was pressed. tcell (the terminal library they use) begins shutting down. It waits for one more console event. READ 3 KEY_EVENT [Q, Up] tcell finishes its final read. Micro exits. PowerShell or CMD takes over, and reads the console. READ 4 KEY_EVENT [Ctrl, Up] PowerShell/CMD ignore the stray Ctrl key release, because they don't care. ``` Now, when they read and are attached to a terminal using ConPTY they get everything in a single read. Here's what that looks like. ``` READ 1 KEY_EVENT [Ctrl, Down] KEY_EVENT [Q, Down] KEY_EVENT [Q, Up] KEY_EVENT [Ctrl, Up] Micro begins exiting because Ctrl+Q were pressed. tcell (the terminal library they use) begins shutting down. It waits for one more console event. ``` Since the console was too "fast" for tcell/micro, it never got the last console event it was waiting for. It exits when the _next_ one comes in. This seems to be a design flaw in tcell... so I'm going to have to close it here.
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 30, 2019):

This will reproduce in VSCode, Alacritty (with experimental backend), and putty-wincon as well.

@DHowett-MSFT commented on GitHub (Oct 30, 2019): This will reproduce in VSCode, Alacritty (with experimental backend), and putty-wincon as well.
Author
Owner

@jeffrson commented on GitHub (Oct 30, 2019):

Really great analysis!

Bringing the attention to tcell reveals this issue: https://github.com/gdamore/tcell/issues/194 (linking it here).

@jeffrson commented on GitHub (Oct 30, 2019): Really great analysis! Bringing the attention to tcell reveals this issue: https://github.com/gdamore/tcell/issues/194 (linking it here).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4190