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


C# IConsole.Write方法代码示例

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


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

示例1: Process

        public IAcceptsInput Process(IConsole console)
        {
            _textInput.Value = null;

            var isCancelled = false;
            var sb = new StringBuilder();

            console.CursorVisible = true;
            var x = console.CursorLeft;
            var y = console.CursorTop;

            while (true)
            {
                var isFinished = false;
                char c;
                switch ((c = console.ReadKey()))
                {
                    case (char)8: // backspace
                        if (sb.Length > 0)
                        {
                            console.SetCursorPosition(x + sb.Length - 1, y);
                            console.Write(' ');
                            sb.Remove(sb.Length - 1, 1);
                            console.SetCursorPosition(x + sb.Length, y);
                        }
                        break;
                    case (char)13: // enter
                        isFinished = true;
                        break;
                    case (char)27: // escape
                        isCancelled = true;
                        break;
                    default:
                        if (!char.IsControl(c))
                        {
                            sb.Append(c);
                            console.Write(c);
                            console.SetCursorPosition(x + sb.Length, y);
                        }
                        break;
                }

                if (isFinished || isCancelled)
                {
                    break;
                }
            }

            console.CursorVisible = false;
            for (int i = 0; i < sb.Length; i++)
            {
                console.SetCursorPosition(x + i, y);
                console.Write(' ');
            }

            _textInput.Value = isCancelled ? null : sb.ToString();
            return _textInput;
        }
开发者ID:bfriesen,项目名称:BadSnowstorm,代码行数:58,代码来源:TextInputProcessor.cs

示例2: Execute

        public override void Execute(IConsole console)
        {
            int x = 1;
            string input;
            int option = -1;

            while (true)
            {
                console.WriteLine("****************************************");
                console.WriteLine("*\t" + _menu_header_text);
                console.WriteLine("****************************************");
                console.Write("\n\n");
                console.WriteLine("0 - Return");
                foreach (var entry in entries)
                {
                    console.WriteLine(x.ToString() + " - " + entry.menu_text);
                }

            
                while (option < 0)
                {
                    console.Write("Enter Selection: ");
                    try
                    {
                        input = console.ReadLine();
                    }
                    catch (IOException)
                    {
                        input = null;
                    }
                    if (input != null)
                    {
                        if (int.TryParse(input, out x))
                        {
                            if ((x >= 0) && (x <= entries.Count()))
                            {
                                option = x;
                                break;
                            }
                        }
                    }
                    console.WriteLine("\nInvalid selection");
                }

                if (option > 0)
                {
                    entries[option - 1].Execute(console);
                    option = -1;
                }
                else if (option == 0)
                    break;
            }
            return;
        }
开发者ID:ams-tech,项目名称:SpreadsheetsOnline,代码行数:54,代码来源:ConsoleMenu.cs

示例3: GetMenuSelection

        private char GetMenuSelection(IConsole console)
        {
            char c;

            do
            {
                c = console.ReadKey();
            } while (_menuItems.All(menuItem => menuItem.Id != c));

            console.Write(c);
            Thread.Sleep(250);
            console.CursorLeft = console.CursorLeft - 1;
            console.Write(' ');

            return c;
        }
开发者ID:bfriesen,项目名称:BadSnowstorm,代码行数:16,代码来源:MenuInputProcessor.cs

示例4: _ExecuteInConsole

        protected override void _ExecuteInConsole(IConsole console)
        {
            string retval = "";
            EveCrest crest = new EveCrest();

            var regions = crest.GetRoot().Query(r => r.Regions);
            var list = regions.Items.ToList();
            foreach (var region in list)
            {
                retval += region.Name;
                retval += "\n";
            }

            console.Write(retval);
        }
开发者ID:ams-tech,项目名称:SpreadsheetsOnline,代码行数:15,代码来源:Regions.cs

示例5: Render

        public static void Render(IConsole console, IList<IContentArea> contentAreas)
        {
            var mergedBorderRenderOverride =
                contentAreas
                    .Where(contentArea => contentArea.BorderRenderOverride != null)
                    .Aggregate((Func<Point, BorderInfo, bool>)((location, borderInfo) => false),
                        (accumulatedFunc, contentArea) =>
                            (point, borderInfo) =>
                                accumulatedFunc(point, borderInfo) || contentArea.BorderRenderOverride(point, borderInfo));

            foreach (var borderCharacter in contentAreas
                .Select(contentArea => contentArea.Border.GetBorderCharacters(contentArea.Bounds))
                .Merge(mergedBorderRenderOverride)
                .Where(borderCharacter =>
                    borderCharacter.Location.Left >= 0
                    && borderCharacter.Location.Left < console.WindowWidth
                    && borderCharacter.Location.Top >= 0
                    && borderCharacter.Location.Top < console.WindowHeight))
            {
                console.SetCursorPosition(borderCharacter.Location.Left, borderCharacter.Location.Top);
                console.Write(borderCharacter.GetValue());
            }
        }
开发者ID:bfriesen,项目名称:BadSnowstorm,代码行数:23,代码来源:BorderRenderer.cs

示例6: Initialize

 public void Initialize(IConsole console)
 {
     // display the error message at the beginning
     console.Write(Resources.Host_PSNotInstalled, System.Windows.Media.Colors.Red, null);
 }
开发者ID:Newtopian,项目名称:nuget,代码行数:5,代码来源:UnsupportedHost.cs

示例7: ReadBoardSize

        /// <summary>
        /// Reads from the input the game size.
        /// </summary>
        /// <param name="userInput">the user UI handling object</param>
        /// <returns>the size of the game board</returns>
        public static int ReadBoardSize(IConsole userInput)
        {
            userInput.Write("Welcome to \"Battle Field game.\" Enter battlefield size: N = ");
            int gameBoardSize = Convert.ToInt32(userInput.ReadLine());
            while (gameBoardSize < 1 || gameBoardSize > 10)
            {
                userInput.WriteLine("Enter a number between 1 and 10!");
                gameBoardSize = Convert.ToInt32(userInput.ReadLine());
            }

            return gameBoardSize;
        }
开发者ID:venelin-p-petrov,项目名称:Battle-Field-1-Telerik-Team-Strontium,代码行数:17,代码来源:GameEngine.cs

示例8: p

 static void p(IConsole output, string s)
 {
     output.Write (s);
 }
开发者ID:stangelandcl,项目名称:csharp-repl,代码行数:4,代码来源:CSharpShell.cs

示例9: EscapeChar

        static void EscapeChar(IConsole output, char c)
        {
            if (c == '\''){
                output.Write ("'\\''");
                return;
            }
            if (c > 32){
                output.Write (string.Format("'{0}'", c));
                return;
            }
            switch (c){
                case '\a':
                output.Write ("'\\a'");
                break;

                case '\b':
                output.Write ("'\\b'");
                break;

                case '\n':
                output.Write ("'\\n'");
                break;

                case '\v':
                output.Write ("'\\v'");
                break;

                case '\r':
                output.Write ("'\\r'");
                break;

                case '\f':
                output.Write ("'\\f'");
                break;

                case '\t':
                output.Write ("'\\t");
                break;

                default:
                output.Write (string.Format("'\\x{0:x}", (int) c));
                break;
            }
        }
开发者ID:stangelandcl,项目名称:csharp-repl,代码行数:44,代码来源:CSharpShell.cs

示例10: RenderContent


//.........这里部分代码省略.........
                        var removeFromBeginning = false;
                        while (lines.Count > paddedBounds.Height)
                        {
                            if (removeFromBeginning)
                            {
                                lines.RemoveAt(0);
                            }
                            else
                            {
                                lines.RemoveAt(lines.Count - 1);
                            }

                            removeFromBeginning = !removeFromBeginning;
                        }
                    }
                }

                for (int i = 0; i < lines.Count; i++)
                {
                    var line = lines[i];

                    if (line.Length > paddedBounds.Width)
                    {
                        if (ContentAlignment == ContentAlignment.TopLeft)
                        {
                            lines[i] = line.Substring(0, paddedBounds.Width);
                        }
                        else
                        {
                            var removeFromBeginning = false;
                            while (line.Length > paddedBounds.Width)
                            {
                                line = removeFromBeginning ? line.Substring(1) : line.Substring(0, line.Length - 1);
                                removeFromBeginning = !removeFromBeginning;
                            }

                            lines[i] = line;
                        }
                    }
                }
            }

            Func<string, int> xModifier;
            Func<string, int> yModifier;

            if (ContentAlignment == ContentAlignment.Centered)
            {
                Func<int, int, int> adjust = (containerBoundry, contentSize) => containerBoundry % 2 == 0 && contentSize % 2 == 1 ? 1 : 0;

                xModifier = line =>
                {
                    var lineLength = line.Count(c => !AllColors.Contains(c));
                    return Math.Max(paddedBounds.Left, paddedBounds.Left + (paddedBounds.Width / 2) - (lineLength / 2) - adjust(paddedBounds.Width, lineLength));
                };
                yModifier = line => Math.Max(paddedBounds.Top, paddedBounds.Top + (paddedBounds.Height / 2) - (lines.Count / 2) - adjust(paddedBounds.Height, lines.Count));
            }
            else
            {
                xModifier = line => paddedBounds.Left;
                yModifier = line => paddedBounds.Top;
            }

            for (int i = 0; i < lines.Count; i++)
            {
                var line = lines[i];
                var y = i + yModifier(line);
                var x = xModifier(line);

                if (line.Length > 0)
                {
                    foreach (char c in line)
                    {
                        if (ForegroundColors.Contains(c))
                        {
                            console.ForegroundColor = GetColor(c);
                        }
                        else if (BackgroundColors.Contains(c))
                        {
                            console.BackgroundColor = GetColor(c);
                        }
                        else
                        {
                            if (paddedBounds.Contains(x, y))
                            {
                                console.SetCursorPosition(x, y);
                                console.Write(c);
                            }

                            x++;
                        }
                    }
                }
                else
                {
                    console.SetCursorPosition(x, y);
                }
            }

            LastCursorLocation = new Point(console.CursorLeft, console.CursorTop);
        }
开发者ID:bfriesen,项目名称:BadSnowstorm,代码行数:101,代码来源:ContentArea.cs

示例11: ClearContent

        public void ClearContent(IConsole console)
        {
            var nonBorderBounds = GetNonBorderBounds();

            for (int y = nonBorderBounds.Top; y <= nonBorderBounds.Bottom; y++)
            {
                console.SetCursorPosition(nonBorderBounds.Left, y);
                console.Write(new string(' ', nonBorderBounds.Width));
            }
        }
开发者ID:bfriesen,项目名称:BadSnowstorm,代码行数:10,代码来源:ContentArea.cs

示例12: NewPrompt

 private static void NewPrompt(IConsole con)
 {
     //HACK: Should be a way to get this from IronPython
     con.Write(">>> ", Microsoft.Scripting.Hosting.Shell.Style.Prompt);
 }
开发者ID:kanbang,项目名称:Colt,代码行数:5,代码来源:IronPythonRepl.cs

示例13: WriteInterpreted

 public static void WriteInterpreted(IConsole console, string buffer, int paddingLeft, int paddingRight)
 {
     int num = console.BufferWidth - (paddingLeft + paddingRight);
     string str = new string(' ', paddingLeft);
     int num2 = 0;
     Stack<ConsoleColorExt> stack = new Stack<ConsoleColorExt>();
     foreach (Match match in FormatRegex.Matches(buffer))
     {
         if (match.Groups["Tag"].Success)
         {
             ConsoleColorExt ext = ParseColour(match.Groups["Inner"].Value, console.Theme);
             stack.Push(console.ForegroundColor);
             console.ForegroundColor = ext;
         }
         else if (match.Groups["EndTag"].Success)
         {
             if (stack.Count < 0)
             {
                 throw new Exception(string.Format(Strings.ConsoleInterpreter_UnexpectedEndTag, match.Index));
             }
             console.ForegroundColor = stack.Pop();
         }
         else if (match.Groups["Text"].Success)
         {
             foreach (string str3 in SplitLinebreaks(UnescapeString(match.Value)))
             {
                 string str4 = str3;
                 if (!(str4 == "\n") && !(str4 == Environment.NewLine))
                 {
                     goto Label_020A;
                 }
                 console.WriteLine(ConsoleVerbosity.Silent);
                 num2 = 0;
                 continue;
             Label_015D:
                 if ((num2 + str4.Length) > num)
                 {
                     string str5;
                     int length = str4.LastIndexOf(' ', num - num2, num - num2);
                     if (length <= 0)
                     {
                         length = num - num2;
                     }
                     if (num2 > 0)
                     {
                         str5 = str4.Substring(0, length);
                     }
                     else
                     {
                         str5 = str + str4.Substring(0, length);
                     }
                     if (console.BufferWidth == (num2 + str5.Length))
                     {
                         console.Write(ConsoleVerbosity.Silent, str5);
                     }
                     else
                     {
                         console.WriteLine(ConsoleVerbosity.Silent, str5);
                     }
                     str4 = str4.Substring(length + 1);
                     num2 = 0;
                 }
                 else
                 {
                     string str6 = str4;
                     if (num2 <= 0)
                     {
                         str6 = str + str4;
                     }
                     console.Write(ConsoleVerbosity.Silent, str6);
                     num2 += str4.Length;
                     str4 = "";
                 }
             Label_020A:
                 if (str4.Length > 0)
                 {
                     goto Label_015D;
                 }
             }
         }
     }
 }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:82,代码来源:ConsoleFormatter.cs


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