本文整理汇总了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;
}
示例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());
}
}
示例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);
}
示例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));
}
}