-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathTestConsole.TestConsoleWriter.cs
38 lines (33 loc) · 1.05 KB
/
TestConsole.TestConsoleWriter.cs
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
using System.IO;
using System.Text;
using CommandDotNet.Rendering;
namespace CommandDotNet.TestTools
{
public partial class TestConsole
{
private class TestConsoleWriter : TextWriter, IConsoleWriter
{
private readonly TestConsoleWriter? _inner;
private readonly StringBuilder _stringBuilder = new StringBuilder();
public TestConsoleWriter(
TestConsoleWriter? inner = null)
{
_inner = inner;
}
public override void Write(char value)
{
_inner?.Write(value);
if (value == '\b' && _stringBuilder.Length > 0)
{
_stringBuilder.Length = _stringBuilder.Length - 1;
}
else
{
_stringBuilder.Append(value);
}
}
public override Encoding Encoding { get; } = Encoding.Unicode;
public override string ToString() => _stringBuilder.ToString();
}
}
}