forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleBufferBuilder.cs
More file actions
59 lines (50 loc) · 1.39 KB
/
ConsoleBufferBuilder.cs
File metadata and controls
59 lines (50 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/********************************************************************++
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; }
}
}
}