diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs index 26515caee..bc222f3a2 100644 --- a/Terminal.Gui/Core.cs +++ b/Terminal.Gui/Core.cs @@ -243,7 +243,7 @@ namespace Terminal.Gui { /// Points to the current driver in use by the view, it is a convenience property /// for simplifying the development of new views. /// - public static ConsoleDriver Driver = Application.Driver; + public static ConsoleDriver Driver { get { return Application.Driver; } } static IList empty = new List (0).AsReadOnly (); @@ -1741,13 +1741,15 @@ namespace Terminal.Gui { /// public static void Init () => Init (() => Toplevel.Create ()); + static bool _initialized = false; + /// /// Initializes the Application /// static void Init (Func topLevelFactory) { - if (Top != null) - return; + if (_initialized) return; + _initialized = true; var p = Environment.OSVersion.Platform; Mono.Terminal.IMainLoopDriver mainLoopDriver; @@ -1978,9 +1980,10 @@ namespace Terminal.Gui { runState.Dispose (); } - static void Shutdown () + public static void Shutdown () { Driver.End (); + _initialized = false; } static void Redraw (View view) diff --git a/Terminal.Gui/Drivers/WindowsDriver.cs b/Terminal.Gui/Drivers/WindowsDriver.cs index 6ad870c92..0074181c7 100644 --- a/Terminal.Gui/Drivers/WindowsDriver.cs +++ b/Terminal.Gui/Drivers/WindowsDriver.cs @@ -100,6 +100,11 @@ namespace Terminal.Gui { var err = Marshal.GetLastWin32Error (); Console.WriteLine ("Error: {0}", err); } + + if (ScreenBuffer != IntPtr.Zero) + CloseHandle(ScreenBuffer); + + ScreenBuffer = IntPtr.Zero; } private bool ContinueListeningForConsoleEvents = true; @@ -352,6 +357,9 @@ namespace Terminal.Gui { [DllImport ("kernel32.dll", SetLastError = true)] static extern IntPtr GetStdHandle (int nStdHandle); + [DllImport("kernel32.dll", SetLastError = true)] + static extern bool CloseHandle(IntPtr handle); + [DllImport ("kernel32.dll", EntryPoint = "ReadConsoleInputW", CharSet = CharSet.Unicode)] public static extern bool ReadConsoleInput ( IntPtr hConsoleInput,