Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
        /// <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

            // 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;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes the Terminal.Gui application
        /// </summary>
        static void Init(Func <Toplevel> topLevelFactory)
        {
            if (_initialized)
            {
                return;
            }

            if (Driver == null)
            {
                var             p = Environment.OSVersion.Platform;
                IMainLoopDriver mainLoopDriver;

                if (UseSystemConsole)
                {
                    mainLoopDriver = new NetMainLoop();
                    Driver         = new NetDriver();
                }
                else if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
                {
                    var windowsDriver = new WindowsDriver();
                    mainLoopDriver = windowsDriver;
                    Driver         = windowsDriver;
                }
                else
                {
                    mainLoopDriver = new UnixMainLoop();
                    Driver         = new CursesDriver();
                }
                Driver.Init(TerminalResized);
                MainLoop = new MainLoop(mainLoopDriver);
                SynchronizationContext.SetSynchronizationContext(new MainLoopSyncContext(MainLoop));
            }
            Top          = topLevelFactory();
            Current      = Top;
            CurrentView  = Top;
            _initialized = true;
        }