コード例 #1
0
        public void DisplayHelp()
        {
            _window.WriteLine(InteractiveWindowResources.KeyboardShortcuts);
            _window.Write(ShortcutDescriptions);

            _window.WriteLine(InteractiveWindowResources.ReplCommands);
            foreach (var line in Help())
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }

            // Hack: Display script directives only in CS/VB interactive window
            // TODO: https://github.com/dotnet/roslyn/issues/6441
            var evaluatorTypeName = _window.Evaluator.GetType().Name;

            if (evaluatorTypeName == "CSharpInteractiveEvaluator" ||
                evaluatorTypeName == "VisualBasicInteractiveEvaluator")
            {
                _window.WriteLine(InteractiveWindowResources.CSVBScriptDirectives);
                foreach (var line in s_CSVBScriptDirectives)
                {
                    _window.Write(HelpIndent);
                    _window.WriteLine(line);
                }
            }
        }
コード例 #2
0
        public void DisplayHelp()
        {
            _window.WriteLine("Keyboard shortcuts:");
            foreach (var line in s_shortcutDescriptions)
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }

            _window.WriteLine("REPL commands:");
            foreach (var line in Help())
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }
        }
コード例 #3
0
        public void DisplayHelp()
        {
            _window.WriteLine(InteractiveWindowResources.KeyboardShortcuts);
            foreach (var line in s_shortcutDescriptions)
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }

            _window.WriteLine(InteractiveWindowResources.ReplCommands);
            foreach (var line in Help())
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }
        }
コード例 #4
0
ファイル: RSessionCallback.cs プロジェクト: skeptycal/RTVS
        public async Task <string> ReadUserInput(string prompt, int maximumLength, CancellationToken ct)
        {
            _services.MainThread().Post(() => {
                if (!ct.IsCancellationRequested)
                {
                    _interactiveWindow.Write(prompt);
                }
            });

            var tcs = new TaskCompletionSource <string>();

            Task.Run(() => {
                using (var reader = _interactiveWindow.ReadStandardInput()) {
                    tcs.TrySetResult(reader?.ReadToEnd() ?? "\n");
                }
            }, ct).DoNotWait();

            tcs.RegisterForCancellation(ct).UnregisterOnCompletion(tcs.Task);

            try {
                return(await tcs.Task);
            } catch (OperationCanceledException) {
                _services.MainThread().Post(() => {
                    if (!ct.IsCancellationRequested)
                    {
                        _interactiveWindow.Operations.TrySubmitStandardInput();
                    }
                });
                throw;
            }
        }
コード例 #5
0
 public Task <string> ReadUserInput(string prompt, int maximumLength, CancellationToken ct)
 {
     _coreShell.DispatchOnUIThread(() => _interactiveWindow.Write(prompt));
     return(Task.Run(() => {
         using (var reader = _interactiveWindow.ReadStandardInput()) {
             return reader != null ? Task.FromResult(reader.ReadToEnd()) : Task.FromResult("\n");
         }
     }, ct));
 }
コード例 #6
0
        public bool ProcessMessage(string message)
        {
            // Note: Post() to UI thread is expensive, and can saturate the message pump when there's a lot of output,
            // making UI non-responsive. So avoid using it unless we need it - and we only need it for FlushOutput,
            // and we only need it to handle CR.
            if (message.Length > 1 && message[0] == '\r' && message[1] != '\n')
            {
                _coreShell.MainThread().Post(() => {
                    // Make sure output buffer is up to date
                    _interactiveWindow.FlushOutput();

                    // If message starts with CR we remember current output buffer
                    // length so we can continue writing lines into the same spot.
                    // See txtProgressBar in R.
                    // Store the message and the initial position. All subsequent
                    // messages that start with CR will be written into the same place.
                    if (_messagePos != null)
                    {
                        ProcessReplacement();
                    }

                    // Locate last end of line
                    var snapshot = _interactiveWindow.OutputBuffer.CurrentSnapshot;
                    var line     = snapshot.GetLineFromPosition(snapshot.Length);
                    var text     = message.Substring(1);

                    _messagePos = new MessagePos()
                    {
                        Text              = text,
                        Position          = line.Start,
                        PlaceholderLength = text.Length + 8 // buffer for, say, '| 100%'
                    };

                    // It is important that replacement matches original text length
                    // since interactive window creates fixed colorized spans for errors
                    // and replacement of text by a text with a different length
                    // causes odd changes in color - word may appear partially in
                    // black and partially in red.

                    // Replacement placeholder so we can receive 'buffer changed' event
                    // Placeholder is whitespace that is as long as original message plus
                    // few more space to account for example, for 0% - 100% when CR is used
                    // to display ASCII progress.
                    var placeholder = new string(' ', _messagePos.PlaceholderLength);

                    _interactiveWindow.Write(placeholder);
                    _interactiveWindow.FlushOutput(); // Must flush so we do get 'buffer changed' immediately.
                });
                return(true);
            }
            return(false);
        }
コード例 #7
0
        public override void Write(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            int offset = window.Write(value);

            if (spans != null)
            {
                spans.Add(new Span(offset, value.Length));
            }
        }
コード例 #8
0
        internal void WriteFrameworkElement(System.Windows.UIElement control, System.Windows.Size desiredSize)
        {
            if (_window == null)
            {
                return;
            }

            _window.Write("");
            _window.FlushOutput();

            var caretPos = _window.TextView.Caret.Position.BufferPosition;
            var manager  = InlineReplAdornmentProvider.GetManager(_window.TextView);

            manager.AddAdornment(new ZoomableInlineAdornment(control, _window.TextView, desiredSize), caretPos);
        }
コード例 #9
0
        private static void AppendEscapedText(IInteractiveWindow window, string text, bool isError = false) {
            // http://en.wikipedia.org/wiki/ANSI_escape_code
            // process any ansi color sequences...
            ConsoleColor? color = null;
            List<ColoredSpan> colors;
            if (!window.OutputBuffer.Properties.TryGetProperty(ReplOutputClassifier.ColorKey, out colors)) {
                window.OutputBuffer.Properties[ReplOutputClassifier.ColorKey] = colors = new List<ColoredSpan>();
            }
            int start = 0, escape = text.IndexOf('\x1b');

            List<int> codes = new List<int>();
            while (escape != -1) {
                if (escape != start) {
                    // add unescaped text
                    if (isError) {
                        window.ErrorOutputWriter.Write(text.Substring(start, escape - start));
                    } else {
                        var span = window.Write(text.Substring(start, escape - start));
                        colors.Add(new ColoredSpan(span, color));
                    }
                }

                // process the escape sequence                
                if (escape < text.Length - 1 && text[escape + 1] == '[') {
                    // We have the Control Sequence Introducer (CSI) - ESC [

                    codes.Clear();
                    int? value = 0;

                    for (int i = escape + 2; i < text.Length; i++) { // skip esc + [
                        if (text[i] >= '0' && text[i] <= '9') {
                            // continue parsing the integer...
                            if (value == null) {
                                value = 0;
                            }
                            value = 10 * value.Value + (text[i] - '0');
                        } else if (text[i] == ';') {
                            if (value != null) {
                                codes.Add(value.Value);
                                value = null;
                            } else {
                                // CSI ; - invalid or CSI ### ;;, both invalid
                                break;
                            }
                        } else if (text[i] == 'm') {
                            if (value != null) {
                                codes.Add(value.Value);
                            }

                            // parsed a valid code
                            start = i + 1;
                            if (codes.Count == 0) {
                                // reset
                                color = null;
                            } else {
                                for (int j = 0; j < codes.Count; j++) {
                                    switch (codes[j]) {
                                        case 0: color = ConsoleColor.White; break;
                                        case 1: // bright/bold
                                            color |= ConsoleColor.DarkGray;
                                            break;
                                        case 2: // faint

                                        case 3: // italic
                                        case 4: // single underline
                                            break;
                                        case 5: // blink slow
                                        case 6: // blink fast
                                            break;
                                        case 7: // negative
                                        case 8: // conceal
                                        case 9: // crossed out
                                        case 10: // primary font
                                        case 11: // 11-19, n-th alternate font
                                            break;
                                        case 21: // bright/bold off 
                                            color &= ~ConsoleColor.DarkGray;
                                            break;
                                        case 22: // normal intensity
                                        case 24: // underline off
                                            break;
                                        case 25: // blink off
                                            break;
                                        case 27: // image - postive
                                        case 28: // reveal
                                        case 29: // not crossed out
                                        case 30: color = ConsoleColor.Black | ((color ?? ConsoleColor.Black) & ConsoleColor.DarkGray); break;
                                        case 31: color = ConsoleColor.DarkRed | ((color ?? ConsoleColor.Black) & ConsoleColor.DarkGray); break;
                                        case 32: color = ConsoleColor.DarkGreen | ((color ?? ConsoleColor.Black) & ConsoleColor.DarkGray); break;
                                        case 33: color = ConsoleColor.DarkYellow | ((color ?? ConsoleColor.Black) & ConsoleColor.DarkGray); break;
                                        case 34: color = ConsoleColor.DarkBlue | ((color ?? ConsoleColor.Black) & ConsoleColor.DarkGray); break;
                                        case 35: color = ConsoleColor.DarkMagenta | ((color ?? ConsoleColor.Black) & ConsoleColor.DarkGray); break;
                                        case 36: color = ConsoleColor.DarkCyan | ((color ?? ConsoleColor.Black) & ConsoleColor.DarkGray); break;
                                        case 37: color = ConsoleColor.Gray | ((color ?? ConsoleColor.Black) & ConsoleColor.DarkGray); break;
                                        case 38: // xterm 286 background color
                                        case 39: // default text color
                                            color = null;
                                            break;
                                        case 40: // background colors
                                        case 41:
                                        case 42:
                                        case 43:
                                        case 44:
                                        case 45:
                                        case 46:
                                        case 47: break;
                                        case 90: color = ConsoleColor.DarkGray; break;
                                        case 91: color = ConsoleColor.Red; break;
                                        case 92: color = ConsoleColor.Green; break;
                                        case 93: color = ConsoleColor.Yellow; break;
                                        case 94: color = ConsoleColor.Blue; break;
                                        case 95: color = ConsoleColor.Magenta; break;
                                        case 96: color = ConsoleColor.Cyan; break;
                                        case 97: color = ConsoleColor.White; break;
                                    }
                                }
                            }
                            break;
                        } else {
                            // unknown char, invalid escape
                            break;
                        }
                    }

                    escape = text.IndexOf('\x1b', escape + 1);
                }// else not an escape sequence, process as text
            }

            if (start != text.Length) {
                if (isError) {
                    window.ErrorOutputWriter.Write(text.Substring(start, escape - start));
                } else {
                    var span = window.Write(text.Substring(start));
                    colors.Add(new ColoredSpan(span, color));
                }
            }
        }