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

MessageBox not closing in PowerShell #885

Closed
domhnal opened this issue Aug 28, 2020 · 13 comments
Closed

MessageBox not closing in PowerShell #885

domhnal opened this issue Aug 28, 2020 · 13 comments

Comments

@domhnal
Copy link

domhnal commented Aug 28, 2020

First time user. I have a simple class created to display a Message box.

public class Msg : IDisposable
    {
        public Msg(string Message)
        {
            Application.Init();
            var msg = MessageBox.Query(20, 10, "Test", Message, "Yes", "No");
        }

        public void Dispose()
        {
            Console.Write("\u001b[?1h");
        }
    }

When I use the class from within PowerShell, the MessageBox opens but does not disappear once a option is chosen. What am I missing?

@BDisp
Copy link
Collaborator

BDisp commented Aug 28, 2020

How you are calling the Msg class? You don't need to use Application.Init() because MessageBox class already open a Dialog. You also need to return the right response from it which is the button used from 0 to number of used buttons and the constructor isn't an ideal place to get it.

@domhnal
Copy link
Author

domhnal commented Aug 28, 2020 via email

@BDisp
Copy link
Collaborator

BDisp commented Aug 28, 2020

I don't know what you have in fwTextGUI.dll module. Try putting Application.RequestStop (); after the call to the var msg = MessageBox.Query (20, 10, "Test", message, "Yes", "No");

Since you call Application.Init Terminal.Gui has control over it and you have to call Application.RequestStop to return to the PowerShell console. So you must control it on your Msg class or on your fwTextGUI class. Without seeing the code I can't provide more information.

@BDisp
Copy link
Collaborator

BDisp commented Aug 28, 2020

A little sample:

static class Program {
	public static void Main ()
	{
		Application.Init ();
		var msg = new Msg ("Test Message!");
		msg.Response = (e) => {
			if (e == 0) {
				Console.Write ("Yes");
			} else {
				Console.Write ("No");
			}
			// Exit
			Application.RequestStop ();
		};
		Application.Top.Ready = () => msg.DisplayMsg ();

		Application.Run ();
		msg.Dispose ();
	}
}
public class Msg : IDisposable {
	string message;
	public Action<int> Response;

	public Msg (string message)
	{
		this.message = message;
	}
	public void DisplayMsg ()
	{
		var msg = MessageBox.Query (20, 10, "Test", message, "Yes", "No");
		Response?.Invoke (msg);
	}

	public void Dispose ()
	{
		Console.Write ("\u001b[?1h");
	}
}

@domhnal
Copy link
Author

domhnal commented Aug 28, 2020

Yes, I've gotten it to work with a console application, but it won't work from within PowerShell. End goal is to write a PowerShell CmdLet that uses the Terminal.Gui API. Calling the MessageBox class directly from PowerShell using the alternative method outlined above fails (as well as using the simple single class DLL I had in my original post).

@TylerLeonhardt
Copy link

@domhnal you may want to look at our ConsoleGuiTools project which exposes an Out-ConsoleGridView:
https://github.com/PowerShell/GraphicalTools/tree/master/src/Microsoft.PowerShell.ConsoleGuiTools

@domhnal
Copy link
Author

domhnal commented Aug 28, 2020

Yes, I was looking at that yesterday, and that is ultimately where I'm headed, but my first example program left me scratching my head. I've done some debugging and it's not that the application hangs, output will continue to be printed to the screen, it's just that any new output is obscured by the modal message box. I can type 'exit' and the PowerShell window will close, you will just never see anything but the Message Box up until the window closes, at which point you get a very brief glimpse of what was printed to the display.

@BDisp
Copy link
Collaborator

BDisp commented Aug 29, 2020

@domhnal try this please:

public class Msg : IDisposable {
	public Msg (string Message)
	{
		Application.Init ();
		var msg = MessageBox.Query (20, 10, "Test", Message, "Yes", "No");
		Application.Shutdown ();
	}

	public void Dispose ()
	{
		Console.Write ("\u001b[?1h");
	}
}

@domhnal
Copy link
Author

domhnal commented Aug 30, 2020

OK, That worked. Mouse support doesn't work in the new windows terminal app, but works fine in the standard powershell 7 console. Thank you for your help.

@BDisp
Copy link
Collaborator

BDisp commented Aug 30, 2020

I still don't understand how that gap in mouse functionality still persists in the new Windows Terminal.

@wgross
Copy link

wgross commented Sep 18, 2020

Since this is a gui.cs<->Powershell issue/discussion....

I spiked a possible powershell integration for gui.cs at https://github.com/wgross/gui.ps1.
I did this out of curiosity and don't have a real-world application currently to drive further implementation but maybe it can serve as a stimulus or starting point for other people?

@BDisp
Copy link
Collaborator

BDisp commented Sep 19, 2020

@wgross I only managed to get it to work by changing the netstandard to version 2.0. I think that is because the Terminal.Gui is configured to run that version. See my PR at wgross/gui.ps1#1

@wgross wgross mentioned this issue Sep 21, 2020
@tig
Copy link
Collaborator

tig commented Sep 22, 2020

I still don't understand how that gap in mouse functionality still persists in the new Windows Terminal.

Me either: I guess they are working on it. This is tracked here: #332

@tig tig closed this as completed Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants