mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-14 13:49:09 +00:00
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.
60 lines
1.4 KiB
C#
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; }
|
|
}
|
|
}
|
|
}
|
|
|