Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux terminal hangs after quit the GUI on Net5.0 #931

Closed
BDisp opened this issue Sep 30, 2020 · 48 comments
Closed

Linux terminal hangs after quit the GUI on Net5.0 #931

BDisp opened this issue Sep 30, 2020 · 48 comments
Labels

Comments

@BDisp
Copy link
Collaborator

BDisp commented Sep 30, 2020

Run UICatalog in WSL and quit. Try to type and it's hang and you have to close WSL. Do the same with the Example and you can type normally. May be it's related with Shutdown already related before.

@tig
Copy link
Collaborator

tig commented Sep 30, 2020

I can't repro this either in Windows Terminal with Ubuntu or ConEmu.

What terminal are you using?

@tig
Copy link
Collaborator

tig commented Sep 30, 2020

That said, almost nothing else works in WSL for me. Tab key works to move between panes, but arrows don't nav. Hmm....

@tig
Copy link
Collaborator

tig commented Sep 30, 2020

Also not working with CMD and WSL2.

@tig
Copy link
Collaborator

tig commented Sep 30, 2020

Example has same issue for me.

@BDisp
Copy link
Collaborator Author

BDisp commented Sep 30, 2020

I use the default WSL2 terminal. I'm not sure what which open. How can I check that? I'm going test in VMWare to see if it's fail too. It's all messed up. With the Ubuntu 20.04 I seen the Example is fail too.

@tig
Copy link
Collaborator

tig commented Sep 30, 2020

Ahhh...

If I start it from bash it works fine (and exits fine). but if I run it from pwsh most keystrokes don't work (but it exits fine).

@tig
Copy link
Collaborator

tig commented Sep 30, 2020

Weird thing is, ocgv works fine everywhere!

@BDisp
Copy link
Collaborator Author

BDisp commented Oct 8, 2020

The hangs after quit only happens with the Net5.0. The mouse issues only happens with Ubuntu which has the libncurses 6.2 version.

BDisp added a commit to BDisp/Terminal.Gui that referenced this issue Oct 12, 2020
@BDisp BDisp changed the title WSL hangs after quit the UICatalog but not with Example. Linux terminal hangs after quit the GUI on Net5.0 Oct 16, 2020
@BDisp
Copy link
Collaborator Author

BDisp commented Oct 16, 2020

Writing reset or stty sane, even if I can't see it, the terminal returns to normal. The problem is to code this in ncurses.

@BDisp
Copy link
Collaborator Author

BDisp commented Oct 16, 2020

I already discovered what is causing this. Are the StartReportingMouseMoves and StopReportingMouseMoves methods.


		public override void StartReportingMouseMoves ()
		{
			Console.Out.Write ("\x1b[?1003h");
			Console.Out.Flush ();
		}

		public override void StopReportingMouseMoves ()
		{
			Console.Out.Write ("\x1b[?1003l");
			Console.Out.Flush ();
		}

Commenting them the behavior issue stops but the problem it's the mouse movement also stops too.

@BDisp
Copy link
Collaborator Author

BDisp commented Oct 28, 2020

I won't waste any more time on this problem because it only happens with Net5.0. With netcoreapp3.1 this problem does not happen, so until the final version of Net5.0 this problem can be corrected.

@markusr
Copy link

markusr commented Nov 26, 2020

The problem still exists. I just tested with Net5.0 and gui.cs 1.0.0-pre.6 .

@BDisp
Copy link
Collaborator Author

BDisp commented Nov 26, 2020

Yes indeed. But if you test with the NetDriver with the Application.UseSystemConsole = true the hangs don't happens, neither on Windows, WSL or Linux.

@markusr
Copy link

markusr commented Nov 26, 2020

I confirm that it does not hang any more. However, after I close the application and I use a mouse button in the terminal I get strange text like:
�,`�(`�(a�(a�(a�(a�(a�(`�-`�-`�.`�.a�.a�.a�.`�.`�.`�.`�.a�.a�.a�.a�.a�.a
on the terminal.

My environment is: Kubuntu 20.04, Konsole Version 19.12.3

@BDisp
Copy link
Collaborator Author

BDisp commented Nov 26, 2020

Ah I see. I am using CSI in the Unix for resizing and perhaps it is not clearing on exit.

@markusr
Copy link

markusr commented Nov 26, 2020

Is this another bug or related? Shall I open another issue?

@BDisp
Copy link
Collaborator Author

BDisp commented Nov 26, 2020

No, it is still under development in this PR #1021.

@rgl
Copy link

rgl commented Dec 6, 2020

I just did a dotnet build -c Release && ./UICatalog/bin/Release/net5.0/UICatalog of 62b5800 on Ubuntu 20.04 gnome-terminal and after quitting the application, the terminal is fubar.

@BDisp
Copy link
Collaborator Author

BDisp commented Dec 6, 2020

Comment the Application.HeightAsBuffer = true; or set Application.HeightAsBuffer = false; and see the difference, please. Thanks.

@rgl
Copy link

rgl commented Dec 6, 2020

Tried both, but it did not fix the problem.

@BDisp
Copy link
Collaborator Author

BDisp commented Dec 6, 2020

Can you post a print screen, please? Thanks.

@rgl
Copy link

rgl commented Dec 6, 2020

Oh, I'm now noticing that I didn't explain the problem before... sorry! After the application quits, when I press the left (or right) cursor key, the cursor caret moves a whole word at a time instead of a character at a time. It seems the ctrl key is stuck. Hummm, I'm also noticing this after running the dotnet command... maybe this is a problem with the dotnet runtime? anyhow, whatever it is, its messing the terminal.

Its not just the left/right cursor keys; up/down are also messed up. I'm not sure if this will help anything, but this is my .inputrc file:

"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOD": backward-word
"\eOC": forward-word
set show-all-if-ambiguous on
set completion-ignore-case on

Interesting enough, if I immediately open vim and quit it, the terminal cursor keys start working normally again.

@BDisp
Copy link
Collaborator Author

BDisp commented Dec 6, 2020

Ah. Ok. The terminal is not restoring properly. It is a issue not solved yet.

@BDisp
Copy link
Collaborator Author

BDisp commented Dec 6, 2020

To bypass this without close the terminal, I do:
Ctrl+C
reset

With Application.UseSystemConsole, running with the -usc argument that behaviour don't happens.

@markusr
Copy link

markusr commented Mar 9, 2021

Yes. My terminal is broken after
dotnet build -c Release && ./UICatalog/bin/Release/net5.0/UICatalog
then CTRL+Q
Tested with master.

@tig tig added the 1.0 label Mar 9, 2021
@tig
Copy link
Collaborator

tig commented Mar 9, 2021

Ok, this is a blocking bug for releasing 1.0.

I've labeled it as such.

@migueldeicaza
Copy link
Collaborator

tagging myself, so I can review later
@migueldeicaza

@tig
Copy link
Collaborator

tig commented Apr 19, 2021

I can no longer repro this in WSL (Debian) from main.

I can no longer repro this in WSL (Ubuntu 20.04) from main.

Anyone else?

@BDisp
Copy link
Collaborator Author

BDisp commented Apr 19, 2021

On WSL (Ubuntu 20.04.2 LTS) and on a Linux (VirtualBox) still happens with Curses. I have to type reset to restore.
With the NetDriver there is no hang.
Tested with the latest main.

@tig
Copy link
Collaborator

tig commented Apr 19, 2021

On WSL (Ubuntu 20.04.2 LTS) and on a Linux (VirtualBox) still happens with Curses. I have to type reset to restore.
With the NetDriver there is no hang.
Tested with the latest main.

Can you repro it with WSL as well?

@BDisp
Copy link
Collaborator Author

BDisp commented Apr 19, 2021

Yes @tig

@tig
Copy link
Collaborator

tig commented Apr 19, 2021

I wonder what's different on my machine.

@BDisp
Copy link
Collaborator Author

BDisp commented Apr 19, 2021

Maybe your Linux version (Debian) but I doubt. It's not affecting only to me, because others are already say the same. It's only happens using he CursesDriver.
I already tried to resolve but without success. I only only run through SSH with remote access to shared folders. I don't build inside Linux.

@Artemigos
Copy link

I can also reproduce this on linux with both alacritty and xterm. After quitting the app, the terminal keeps adding characters with just the mouse moving over it. Even in the app the mouse behaves wrong - just moving it seems to be reporting mouse clicks to the app. Can I help somehow with this issue?

@BDisp
Copy link
Collaborator Author

BDisp commented Apr 22, 2021

Hi, yes, I know. Although stopping mouse repporting at exit, the terminal continues to report these movements and hangs the terminal. I think the problem is not from .NET because with NetDriver this does not happen. If you can help, I'll thank you very much, you do not even have to ask :-)

@Artemigos
Copy link

I'll try to take a look sometime this week, we'll see how that goes :)

@Artemigos
Copy link

"this week" became "next week" :)

I don't have much success so far, the mouse situation seems to be putting ncurses in a weird state - if I click with the left mouse button, then mouse movement starts reporting left mouse clicks, if I use the mouse wheel, then mouse movement starts reporting mouse wheel events, but much faster than before.

I tried to regenerate the constants.cs file for ncurses with the original code from mono-ncurses, the differences mostly weren't interesting except for maybe Button4 codes (they are different) and AllEvents - it generated 0xfffffff but there's 0x7ffffff in code. I changed it, but I didn't notice any difference in functionality.

On the topic of interesting observations - the ncurses library gets loaded dynamically twice. I'm not sure if this causes any side effects yet, this might be the next thing I verify.

Long story short I'm worried that the native binding isn't completely correct, but I haven't found what exactly is wrong (yet).

@BDisp
Copy link
Collaborator Author

BDisp commented Apr 27, 2021

I finally fixed it, I hope :-) #931

@tig tig closed this as completed in c4e744a Apr 27, 2021
@tig
Copy link
Collaborator

tig commented Apr 27, 2021

Leaving open until we verify.

@tig tig reopened this Apr 27, 2021
@Artemigos
Copy link

For me, quitting the UICatalog now works a lot better, but still not completely correctly. After exiting, the terminal behaves as if only 25 lines of text could be visible on the screen, which is much less that is actually available. I can reproduce this in both alacritty and xterm. To maybe visualize better:

Normal terminal in the gui.cs repo runing ll three times:
image

The same situation right after quitting the UICatalog:
image

The output just scrolls up as if it didn't have more lines available. Resizing the terminal fixes this immediately.

Also, it's starting to look like my problem with crazy mouse behavior is a different issue.

@BDisp
Copy link
Collaborator Author

BDisp commented Apr 27, 2021

Maybe is due to this:

Console.Out.Write ("\x1b[1;25r");

Can you please check it?

@Artemigos
Copy link

Commenting out this and the flush right after seems to fix it :D
The prompt after that is at the bottom at the terminal, but this is a nitpick:
image

For comparison, this is what it looks like after I exit neovim:
image

Not sure if this is worth doing, though.

@BDisp
Copy link
Collaborator Author

BDisp commented Apr 27, 2021

Try commenting all this:

Console.Out.Write ("\x1b[2J");
Console.Out.Flush ();
Console.Out.Write ("\x1b[1;25r");
Console.Out.Flush ();

@Artemigos
Copy link

Perfect:
image

@BDisp
Copy link
Collaborator Author

BDisp commented Apr 27, 2021

Ok thanks. I'll send a PR with that lines commented.

BDisp added a commit to BDisp/Terminal.Gui that referenced this issue Apr 27, 2021
@tig
Copy link
Collaborator

tig commented Apr 27, 2021

This is great sluthing folks!

This stuff is black-art level stuff. The more documentation on why these changes work, the better.

@BDisp
Copy link
Collaborator Author

BDisp commented Apr 27, 2021

I added this to the code:

// I'm commenting this because was used in a trying to fix the Linux hanging and forgot to exclude it.
// Clear and reset entire screen.
//Console.Out.Write ("\x1b[2J");
//Console.Out.Flush ();

// Reports current cursor line and column.
//Console.Out.Write ("\x1b[1;25r");
//Console.Out.Flush ();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants