-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Crash after window resize #28
Comments
sounds like it should be easy enough to reproduce. (simple to reproduce but quite a big update to fix). |
was actually looking at it myself to try to see if there was a reasonable way to be alerted to the change in console size to maybe take some sort of corrective action. But didn't find any. Most of the googling had people saying you might as well implement a UI. I don't know anything about porting to mac or linux so it might be an interesting thing to watch as it evolves. I can't say that I'd have anything useful to add in that respect but I'll poke my head in when I can. |
looking at all these now in the following order |
This has been fixed in package |
I will close this issue if I don't hear back from you in a little while, or if you tell me this is working. |
I have not tested this, but if you want to stop the user from resizing a console window, this may work class Program
{
private const int MF_BYCOMMAND = 0x00000000;
public const int SC_CLOSE = 0xF060;
public const int SC_MINIMIZE = 0xF020;
public const int SC_MAXIMIZE = 0xF030;
public const int SC_SIZE = 0xF000;
[DllImport("user32.dll")]
public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("kernel32.dll", ExactSpelling = true)]
private static extern IntPtr GetConsoleWindow();
static void Main(string[] args)
{
IntPtr handle = GetConsoleWindow();
IntPtr sysMenu = GetSystemMenu(handle, false);
if (handle != IntPtr.Zero)
{
DeleteMenu(sysMenu, SC_CLOSE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_MINIMIZE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_SIZE, MF_BYCOMMAND);
}
Console.Read();
}
} code is from here : https://social.msdn.microsoft.com/Forums/vstudio/en-US/1aa43c6c-71b9-42d4-aa00-60058a85f0eb/c-console-window-disable-resize?forum=csharpgeneral |
By the way, I ran your sample code and I noticed that the windows are rendered incorrectly when the height of a window is 3 lines high, and they render correctly if 4 or more lines. I also saw the code needed to generate the layout you wanted (a common design) is not very elegant. Or more accurately, Konsole is not fluid enough to make creating the layout more elegantly, so I've got a draft of a new version committed (needs more tests), and will release that soon. You will be able to do the following; private static void QuickTest()
{
Console.CursorVisible = false;
var c = new Window();
var consoles = c.SplitRows(
new Split(4, "headline", LineThickNess.Single, ConsoleColor.Yellow),
new Split(0, "content", LineThickNess.Single),
new Split(4, "status", LineThickNess.Single, ConsoleColor.Red)
);
var headline = consoles[0];
var content = consoles[1];
var status = consoles[2];
headline.Write("my headline");
content.WriteLine("content goes here");
status.Write("System offline!");
Console.ReadLine();
} this produces the following output |
I'll give it a try shortly. Thank you for the fast response. Also I'll look at the way I'm creating the windows and rework. |
I'm busy testing the final changes for columns, so you can now create any shape UI using rows and columns, passing a width or height of Console.CursorVisible = false;
var c = new Window();
var consoles = c.SplitRows(
new Split(4, "heading", LineThickNess.Single),
new Split(0),
new Split(4, "status", LineThickNess.Single)
); ; ;
var headline = consoles[0];
var status = consoles[2];
var contents = consoles[1].SplitColumns(
new Split(20),
new Split(0, "content") { Foreground = ConsoleColor.White, Background = ConsoleColor.Cyan },
new Split(20)
);
var menu = contents[0];
var content = contents[1];
var sidebar = contents[2];
headline.Write("my headline");
content.WriteLine("content goes here");
menu.WriteLine("Options A");
menu.WriteLine("Options B");
sidebar.WriteLine("20% off all items between 11am and midnight tomorrow!");
status.Write("System offline!"); gives you the following UI. This will be available in version |
done, fix should be available shortly. Package is being verified |
That worked pretty well actually.
IConsoles don't seem to retain their name, is that true? |
Bugger... nope it happened again when I resized the window to a smaller size
|
Can confirm this works. I added it to my ConsoleWrapper interface and implementation. |
@eiredrake I think I have a really nice solution to your resizing problem |
Been testing the Goblinfactory console classes and so far I'm pretty happy with them. I have a console app that needs progress bars and a section where a log will be displayed. I was able to do all that fairly easily. As long as I don't mess with the window size everything runs just fine.
But I'm having an issue wherein the console window gets resized and causes an exception. At first I did this accidentally when I grabbed the wrong console but it occurs most of the time when I resize the window whenI do so manually not by using minimize/maximize.
Edit: Also seems to be when I make the window smaller. Making the window larger just makes a mess of the screen.
I'm getting an argument out of range exception. This occurs when the log sink I am using attempts to update the log IConsole. I'm using dependency injection, though I don't know if that really matters from your prospective. The IConsoleWrapper is just a class I use to hold on to the individual parts of the 'window'
I instantiate the IConsoles like this:
and the log update happens here....it's triggered by a Serilog log write.
The exception details are the following:
The text was updated successfully, but these errors were encountered: