コード例 #1
0
ファイル: Console.cs プロジェクト: mpvyard/GoddamnConsole
        /// <summary>
        /// Starts rendering cycle and waits for shutdown
        /// </summary>
        public static void Start()
        {
            var pf       = Environment.OSVersion.Platform;
            var isUnix   = pf == PlatformID.Unix || pf == PlatformID.MacOSX || (int)pf == 128; // unix/macosx/mono linux
            var provider =
                isUnix
                    ? (INativeConsoleProvider) new UnixNativeConsoleProvider()
                    : new WindowsNativeConsoleProvider();

            if (Provider != null)
            {
                throw new ArgumentException("Already started");
            }
            Provider = provider;
            provider.Clear(_background);
            provider.KeyPressed += (o, e) =>
            {
                if (CanChangeFocus && e.Info.Key == ConsoleKey.Tab && e.Info.Modifiers == 0)
                {
                    _prevent = true;
                    FocusNext();
                    _prevent = false;
                    Refresh();
                    return;
                }
                if (CanChangeFocus && e.Info.Key == ConsoleKey.Tab && e.Info.Modifiers == ConsoleModifiers.Shift) // Can not intercept CTRL in Linux
                {
                    _prevent = true;
                    FocusNextWindow();
                    _prevent = false;
                    Refresh();
                    return;
                }
                _prevent = true;
                Focused?.OnKeyPressedInternal(e.Info);
                _prevent = false;
                Refresh();
            };
            provider.SizeChanged += (o, e) =>
            {
                _prevent = true;
                foreach (var window in Windows)
                {
                    window.OnSizeChangedInternal();
                }
                _prevent = false;
                Refresh();
            };
            _prevent = true;
            FocusNextWindow();
            _prevent = false;
            Refresh();
        }