Files
PowerShell/src/Microsoft.PowerShell.PSReadLine/ConsoleBufferBuilder.cs
T

59 lines
1.4 KiB
C#
Raw Normal View History

2016-04-27 10:52:58 -07:00
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Collections.Generic;
using Microsoft.PowerShell.Internal;
namespace Microsoft.PowerShell
{
internal class ConsoleBufferBuilder
{
2016-07-07 11:45:08 -07:00
private List<BufferChar> buffer;
2016-04-27 10:52:58 -07:00
private IConsole _console;
public ConsoleBufferBuilder(int capacity, IConsole console)
{
2016-07-07 11:45:08 -07:00
buffer = new List<BufferChar>(capacity);
2016-04-27 10:52:58 -07:00
_console = console;
}
2016-07-07 11:45:08 -07:00
BufferChar NewCharInfo(char c)
2016-04-27 10:52:58 -07:00
{
2016-07-07 11:45:08 -07:00
return new BufferChar
2016-04-27 10:52:58 -07:00
{
UnicodeChar = c,
BackgroundColor = _console.BackgroundColor,
ForegroundColor = _console.ForegroundColor
};
}
public void Append(string s)
{
foreach (char c in s)
{
buffer.Add(NewCharInfo(c));
}
}
public void Append(char c, int count)
{
while (count-- > 0)
{
buffer.Add(NewCharInfo(c));
}
}
2016-07-07 11:45:08 -07:00
public BufferChar[] ToArray()
2016-04-27 10:52:58 -07:00
{
return buffer.ToArray();
}
public int Length
{
get { return buffer.Count; }
}
}
}