/
PhysicalConsole.cs
98 lines (84 loc) · 2.92 KB
/
PhysicalConsole.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// This file has been modified from the original form. See Notice.txt in the project root for more information.
using System;
using System.IO;
namespace McMaster.Extensions.CommandLineUtils
{
/// <summary>
/// An implementation of <see cref="IConsole"/> that wraps <see cref="System.Console"/>.
/// </summary>
public class PhysicalConsole : IConsole
{
/// <summary>
/// A shared instance of <see cref="PhysicalConsole"/>.
/// </summary>
public static IConsole Singleton { get; } = new PhysicalConsole();
private PhysicalConsole()
{
}
/// <summary>
/// <see cref="Console.CancelKeyPress"/>.
/// </summary>
public event ConsoleCancelEventHandler? CancelKeyPress
{
add => Console.CancelKeyPress += value;
remove
{
try
{
Console.CancelKeyPress -= value;
}
catch (PlatformNotSupportedException)
{
// https://github.com/natemcmaster/CommandLineUtils/issues/344
// Suppress this error during unsubscription on some Xamarin platforms.
}
}
}
/// <summary>
/// <see cref="Console.Error"/>.
/// </summary>
public TextWriter Error => Console.Error;
/// <summary>
/// <see cref="Console.In"/>.
/// </summary>
public TextReader In => Console.In;
/// <summary>
/// <see cref="Console.Out"/>.
/// </summary>
public TextWriter Out => Console.Out;
/// <summary>
/// <see cref="Console.IsInputRedirected"/>.
/// </summary>
public bool IsInputRedirected => Console.IsInputRedirected;
/// <summary>
/// <see cref="Console.IsOutputRedirected"/>.
/// </summary>
public bool IsOutputRedirected => Console.IsOutputRedirected;
/// <summary>
/// <see cref="Console.IsErrorRedirected"/>.
/// </summary>
public bool IsErrorRedirected => Console.IsErrorRedirected;
/// <summary>
/// <see cref="Console.ForegroundColor"/>.
/// </summary>
public ConsoleColor ForegroundColor
{
get => Console.ForegroundColor;
set => Console.ForegroundColor = value;
}
/// <summary>
/// <see cref="Console.BackgroundColor"/>.
/// </summary>
public ConsoleColor BackgroundColor
{
get => Console.BackgroundColor;
set => Console.BackgroundColor = value;
}
/// <summary>
/// <see cref="Console.ResetColor"/>.
/// </summary>
public void ResetColor() => Console.ResetColor();
}
}