/// <summary> /// Initializes the Terminal.Gui application /// </summary> static void Init(Func <Toplevel> topLevelFactory, ConsoleDriver driver = null, IMainLoopDriver mainLoopDriver = null) { if (_initialized) { return; } // 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) { mainLoopDriver = new NetMainLoop(() => Console.ReadKey(true)); Driver = new NetDriver(); } else if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) { var windowsDriver = cols == 0 && rows == 0 ? new WindowsDriver() : new WindowsDriver(cols, rows); mainLoopDriver = windowsDriver; Driver = windowsDriver; } else { if (oldMainLoopDriver == null && oldDriver == null) { mainLoopDriver = new UnixMainLoop(); Driver = new CursesDriver(); oldMainLoopDriver = mainLoopDriver; oldDriver = Driver; } else { mainLoopDriver = oldMainLoopDriver; Driver = oldDriver; } } Driver.Init(TerminalResized); MainLoop = new MainLoop(mainLoopDriver); SynchronizationContext.SetSynchronizationContext(new MainLoopSyncContext(MainLoop)); } Top = topLevelFactory(); Current = Top; CurrentView = Top; _initialized = true; }
/// <summary> /// Creates a new Mainloop, to run it you must provide a driver, and choose /// one of the implementations UnixMainLoop, NetMainLoop or WindowsMainLoop. /// </summary> public MainLoop(IMainLoopDriver driver) { this.driver = driver; _timeouts0 = new SortedList <long, Timeout>(); _timeouts1 = new SortedList <long, Timeout>(); Timeouts = _timeouts0; _parityTimeoutsId = 0; _timeoutsLocker = new object(); _idleHandlers0 = new List <Action>(); _idleHandlers1 = new List <Action>(); IdleHandlers = _idleHandlers0; _parityIdleHandlers = 0; _idleHandlersLocker = new object(); driver.Setup(this); }
/// <summary> /// Creates a new Mainloop. /// </summary> /// <param name="driver">Should match the <see cref="ConsoleDriver"/> (one of the implementations UnixMainLoop, NetMainLoop or WindowsMainLoop).</param> public MainLoop(IMainLoopDriver driver) { Driver = driver; driver.Setup(this); }
/// <summary> /// Initializes the Terminal.Gui application /// </summary> static void Init(Func <Toplevel> topLevelFactory, ConsoleDriver driver = null, IMainLoopDriver mainLoopDriver = null) { if (_initialized && driver == null) { return; } // Used only for start debugging on Unix. //#if DEBUG // while (!System.Diagnostics.Debugger.IsAttached) { // System.Threading.Thread.Sleep (100); // } // System.Diagnostics.Debugger.Break (); //#endif // 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);