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


C# IConsole.SetCursorPosition方法代码示例

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


在下文中一共展示了IConsole.SetCursorPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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


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