Пример #1
0
 /// <summary>
 /// Stops console rendering cycle and disposes native provider
 /// </summary>
 public static void Shutdown()
 {
     if (Provider == null)
     {
         throw new ArgumentException("Not started");
     }
     Provider.Dispose();
     Provider = null;
     Focused  = null;
 }
Пример #2
0
        /// <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();
        }