Files
PowerShell/src/Microsoft.PowerShell.PSReadLine/ConsoleBufferBuilder.cs
T
Jason Shirk (POWERSHELL) 372d69583f Only use CHAR_INFO on Windows
CHAR_INFO has 4 bits for ConsoleColor.  On Linux, ConsoleColor is sometimes -1 (unknown),
which is a 17th possible value for ConsoleColor, which can't be represented in CHAR_INFO.

To fix this, I've introduced a bigger type that gets converted to CHAR_INFO when necessary.
2016-07-07 12:07:52 -07:00

60 lines
1.4 KiB
C#

/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Collections.Generic;
using Microsoft.PowerShell.Internal;
namespace Microsoft.PowerShell
{
internal class ConsoleBufferBuilder
{
private List<BufferChar> buffer;
private IConsole _console;
public ConsoleBufferBuilder(int capacity, IConsole console)
{
buffer = new List<BufferChar>(capacity);
_console = console;
}
BufferChar NewCharInfo(char c)
{
return new BufferChar
{
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));
}
}
public BufferChar[] ToArray()
{
return buffer.ToArray();
}
public int Length
{
get { return buffer.Count; }
}
}
}