예제 #1
0
        private void TestSetup(KeyMode keyMode, params KeyHandler[] keyHandlers)
        {
            Console.Clear();
            PSConsoleReadLine.ClearHistory();
            PSConsoleReadLine.ClearKillRing();

            // We don't want stdout redirected, we want it sent to the screen.
            var standardOutput = new StreamWriter(Console.OpenStandardOutput())
            {
                AutoFlush = true
            };

            Console.SetOut(standardOutput);

            var options = new SetPSReadlineOption
            {
                AddToHistoryHandler  = null,
                BellStyle            = PSConsoleReadlineOptions.DefaultBellStyle,
                CompletionQueryItems = PSConsoleReadlineOptions.DefaultCompletionQueryItems,
                ContinuationPrompt   = PSConsoleReadlineOptions.DefaultContinuationPrompt,
                ContinuationPromptBackgroundColor = Console.BackgroundColor,
                ContinuationPromptForegroundColor = Console.ForegroundColor,
                DingDuration                  = 1,      // Make tests virtually silent when they ding
                DingTone                      = 37,     // Make tests virtually silent when they ding
                EmphasisBackgroundColor       = Console.BackgroundColor,
                EmphasisForegroundColor       = PSConsoleReadlineOptions.DefaultEmphasisForegroundColor,
                ExtraPromptLineCount          = PSConsoleReadlineOptions.DefaultExtraPromptLineCount,
                HistoryNoDuplicates           = PSConsoleReadlineOptions.DefaultHistoryNoDuplicates,
                HistorySearchCaseSensitive    = PSConsoleReadlineOptions.DefaultHistorySearchCaseSensitive,
                HistorySearchCursorMovesToEnd = PSConsoleReadlineOptions.DefaultHistorySearchCursorMovesToEnd,
                MaximumHistoryCount           = PSConsoleReadlineOptions.DefaultMaximumHistoryCount,
                MaximumKillRingCount          = PSConsoleReadlineOptions.DefaultMaximumKillRingCount,
                ResetTokenColors              = true,
                ShowToolTips                  = PSConsoleReadlineOptions.DefaultShowToolTips,
                WordDelimiters                = PSConsoleReadlineOptions.DefaultWordDelimiters,
            };

            switch (keyMode)
            {
            case KeyMode.Cmd:
                options.EditMode = EditMode.Windows;
                break;

            case KeyMode.Emacs:
                options.EditMode = EditMode.Emacs;
                break;

#if FALSE
            case KeyMode.Vi:
                options.EditMode = EditMode.Vi;
                break;
#endif
            }

            PSConsoleReadLine.SetOptions(options);

            foreach (var keyHandler in keyHandlers)
            {
                PSConsoleReadLine.SetKeyHandler(new [] { keyHandler.Chord }, keyHandler.Handler, "", "");
            }

            var colorOptions = new SetPSReadlineOption();
            foreach (var val in typeof(TokenClassification).GetEnumValues())
            {
                colorOptions.TokenKind       = (TokenClassification)val;
                colorOptions.ForegroundColor = ForegroundColors[(int)val];
                colorOptions.BackgroundColor = BackgroundColors[(int)val];
                PSConsoleReadLine.SetOptions(colorOptions);
            }
        }
예제 #2
0
        private void TestSetup(KeyMode keyMode, params KeyHandler[] keyHandlers)
        {
            _console       = new TestConsole();
            _mockedMethods = new MockedMethods();
            var instance = (PSConsoleReadLine)typeof(PSConsoleReadLine)
                           .GetField("_singleton", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

            typeof(PSConsoleReadLine)
            .GetField("_mockableMethods", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(instance, _mockedMethods);
            typeof(PSConsoleReadLine)
            .GetField("_console", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(instance, _console);

            PSConsoleReadLine.ClearHistory();
            PSConsoleReadLine.ClearKillRing();

            var options = new SetPSReadlineOption
            {
                AddToHistoryHandler  = null,
                BellStyle            = PSConsoleReadlineOptions.DefaultBellStyle,
                CompletionQueryItems = PSConsoleReadlineOptions.DefaultCompletionQueryItems,
                ContinuationPrompt   = PSConsoleReadlineOptions.DefaultContinuationPrompt,
                ContinuationPromptBackgroundColor = _console.BackgroundColor,
                ContinuationPromptForegroundColor = _console.ForegroundColor,
                DingDuration                  = 1,      // Make tests virtually silent when they ding
                DingTone                      = 37,     // Make tests virtually silent when they ding
                EmphasisBackgroundColor       = _console.BackgroundColor,
                EmphasisForegroundColor       = PSConsoleReadlineOptions.DefaultEmphasisForegroundColor,
                ErrorBackgroundColor          = ConsoleColor.DarkRed,
                ErrorForegroundColor          = ConsoleColor.Red,
                ExtraPromptLineCount          = PSConsoleReadlineOptions.DefaultExtraPromptLineCount,
                HistoryNoDuplicates           = PSConsoleReadlineOptions.DefaultHistoryNoDuplicates,
                HistorySaveStyle              = HistorySaveStyle.SaveNothing,
                HistorySearchCaseSensitive    = PSConsoleReadlineOptions.DefaultHistorySearchCaseSensitive,
                HistorySearchCursorMovesToEnd = PSConsoleReadlineOptions.DefaultHistorySearchCursorMovesToEnd,
                MaximumHistoryCount           = PSConsoleReadlineOptions.DefaultMaximumHistoryCount,
                MaximumKillRingCount          = PSConsoleReadlineOptions.DefaultMaximumKillRingCount,
                ResetTokenColors              = true,
                ShowToolTips                  = PSConsoleReadlineOptions.DefaultShowToolTips,
                WordDelimiters                = PSConsoleReadlineOptions.DefaultWordDelimiters,
            };

            switch (keyMode)
            {
            case KeyMode.Cmd:
                options.EditMode = EditMode.Windows;
                break;

            case KeyMode.Emacs:
                options.EditMode = EditMode.Emacs;
                break;

            case KeyMode.Vi:
                options.EditMode = EditMode.Vi;
                break;
            }

            PSConsoleReadLine.SetOptions(options);

            foreach (var keyHandler in keyHandlers)
            {
                PSConsoleReadLine.SetKeyHandler(new [] { keyHandler.Chord }, keyHandler.Handler, "", "");
            }

            var colorOptions = new SetPSReadlineOption();

            foreach (var val in typeof(TokenClassification).GetEnumValues())
            {
                colorOptions.TokenKind       = (TokenClassification)val;
                colorOptions.ForegroundColor = ForegroundColors[(int)val];
                colorOptions.BackgroundColor = BackgroundColors[(int)val];
                PSConsoleReadLine.SetOptions(colorOptions);
            }
        }
예제 #3
0
        private void TestSetup(KeyMode keyMode, params KeyHandler[] keyHandlers)
        {
            Skip.If(WindowsConsoleFixtureHelper.GetKeyboardLayout() != this.Fixture.Lang,
                    $"Keyboard layout must be set to {this.Fixture.Lang}");

            _console       = new TestConsole(_);
            _mockedMethods = new MockedMethods();
            var instance = (PSConsoleReadLine)typeof(PSConsoleReadLine)
                           .GetField("_singleton", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

            typeof(PSConsoleReadLine)
            .GetField("_mockableMethods", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(instance, _mockedMethods);
            typeof(PSConsoleReadLine)
            .GetField("_console", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(instance, _console);

            PSConsoleReadLine.ClearHistory();
            PSConsoleReadLine.ClearKillRing();

            var options = new SetPSReadLineOption
            {
                AddToHistoryHandler           = PSConsoleReadLineOptions.DefaultAddToHistoryHandler,
                AnsiEscapeTimeout             = 0,
                BellStyle                     = PSConsoleReadLineOptions.DefaultBellStyle,
                CompletionQueryItems          = PSConsoleReadLineOptions.DefaultCompletionQueryItems,
                ContinuationPrompt            = PSConsoleReadLineOptions.DefaultContinuationPrompt,
                DingDuration                  = 1,      // Make tests virtually silent when they ding
                DingTone                      = 37,     // Make tests virtually silent when they ding
                ExtraPromptLineCount          = PSConsoleReadLineOptions.DefaultExtraPromptLineCount,
                HistoryNoDuplicates           = PSConsoleReadLineOptions.DefaultHistoryNoDuplicates,
                HistorySaveStyle              = HistorySaveStyle.SaveNothing,
                HistorySearchCaseSensitive    = PSConsoleReadLineOptions.DefaultHistorySearchCaseSensitive,
                HistorySearchCursorMovesToEnd = PSConsoleReadLineOptions.DefaultHistorySearchCursorMovesToEnd,
                MaximumHistoryCount           = PSConsoleReadLineOptions.DefaultMaximumHistoryCount,
                MaximumKillRingCount          = PSConsoleReadLineOptions.DefaultMaximumKillRingCount,
                ShowToolTips                  = PSConsoleReadLineOptions.DefaultShowToolTips,
                WordDelimiters                = PSConsoleReadLineOptions.DefaultWordDelimiters,
                PromptText                    = new [] { "" },
                Colors = new Hashtable {
                    { "ContinuationPrompt", MakeCombinedColor(_console.ForegroundColor, _console.BackgroundColor) },
                    { "Emphasis", MakeCombinedColor(PSConsoleReadLineOptions.DefaultEmphasisColor, _console.BackgroundColor) },
                    { "Error", MakeCombinedColor(ConsoleColor.Red, ConsoleColor.DarkRed) },
                }
            };

            switch (keyMode)
            {
            case KeyMode.Cmd:
                options.EditMode = EditMode.Windows;
                break;

            case KeyMode.Emacs:
                options.EditMode = EditMode.Emacs;
                break;

            case KeyMode.Vi:
                options.EditMode = EditMode.Vi;
                break;
            }

            PSConsoleReadLine.SetOptions(options);

            foreach (var keyHandler in keyHandlers)
            {
                PSConsoleReadLine.SetKeyHandler(new [] { keyHandler.Chord }, keyHandler.Handler, "", "");
            }

            var tokenTypes = new[]
            {
                "Default", "Comment", "Keyword", "String", "Operator", "Variable",
                "Command", "Parameter", "Type", "Number", "Member", "Selection",
                "InlinePrediction", "ListPrediction", "ListPredictionSelected"
            };
            var colors = new Hashtable();

            for (var i = 0; i < tokenTypes.Length; i++)
            {
                colors.Add(tokenTypes[i], MakeCombinedColor(Colors[i], BackgroundColors[i]));
            }
            var colorOptions = new SetPSReadLineOption {
                Colors = colors
            };

            PSConsoleReadLine.SetOptions(colorOptions);
        }