当前位置: 首页>>代码示例>>C#>>正文


C# IInteractiveWindow.Write方法代码示例

本文整理汇总了C#中IInteractiveWindow.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IInteractiveWindow.Write方法的具体用法?C# IInteractiveWindow.Write怎么用?C# IInteractiveWindow.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IInteractiveWindow的用法示例。


在下文中一共展示了IInteractiveWindow.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AppendEscapedText

        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:
//.........这里部分代码省略.........
开发者ID:wenh123,项目名称:PTVS,代码行数:101,代码来源:BasePythonReplEvaluator.cs


注:本文中的IInteractiveWindow.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。