/// <summary> /// Initializes the Terminal.Gui application /// </summary> static void Init(Func <Toplevel> topLevelFactory, ConsoleDriver driver = null, IMainLoopDriver mainLoopDriver = null) { if (_initialized && driver == null) { return; } if (_initialized) { throw new InvalidOperationException("Init must be bracketed by Shutdown"); } // Used only for start debugging on Unix. //#if DEBUG // while (!System.Diagnostics.Debugger.IsAttached) { // System.Threading.Thread.Sleep (100); // } // System.Diagnostics.Debugger.Break (); //#endif // Reset all class variables (Application is a singleton). ResetState(); // This supports Unit Tests and the passing of a mock driver/loopdriver if (driver != null) { if (mainLoopDriver == null) { throw new ArgumentNullException("mainLoopDriver cannot be null if driver is provided."); } Driver = driver; Driver.Init(TerminalResized); MainLoop = new MainLoop(mainLoopDriver); SynchronizationContext.SetSynchronizationContext(new MainLoopSyncContext(MainLoop)); } if (Driver == null) { var p = Environment.OSVersion.Platform; if (UseSystemConsole) { Driver = new NetDriver(); mainLoopDriver = new NetMainLoop(Driver); } else if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) { Driver = new WindowsDriver(); mainLoopDriver = new WindowsMainLoop(Driver); } else { mainLoopDriver = new UnixMainLoop(); Driver = new CursesDriver(); } Driver.Init(TerminalResized); MainLoop = new MainLoop(mainLoopDriver); SynchronizationContext.SetSynchronizationContext(new MainLoopSyncContext(MainLoop)); } Top = topLevelFactory(); Current = Top; _initialized = true; }
/// <summary> /// Initializes a new instance of <see cref="Terminal.Gui"/> Application. /// </summary> /// <remarks> /// <para> /// Call this method once per instance (or after <see cref="Shutdown"/> has been called). /// </para> /// <para> /// Loads the right <see cref="ConsoleDriver"/> for the platform. /// </para> /// <para> /// Creates a <see cref="Toplevel"/> and assigns it to <see cref="Top"/> /// </para> /// </remarks> public static void Init(ConsoleDriver driver = null, IMainLoopDriver mainLoopDriver = null) => Init(() => Toplevel.Create(), driver, mainLoopDriver);