This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathIConsole.cs
131 lines (114 loc) · 3.44 KB
/
IConsole.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
namespace Microsoft.PowerShell
{
/// <summary>
/// Interface for console APIs used by Pager.
/// </summary>
interface IConsole
{
/// <summary>
/// Height of the buffer.
/// </summary>
int BufferHeight { get; }
/// <summary>
/// Width of the buffer.
/// </summary>
int BufferWidth { get; }
/// <summary>
/// Height of the window.
/// </summary>
int WindowHeight { get; }
/// <summary>
/// Width of the window.
/// </summary>
int WindowWidth { get; }
/// <summary>
/// Clear the contents of the console.
/// </summary>
void Clear();
/// <summary>
/// Read key press from the user.
/// </summary>
/// <param name="intercept">Intercept the key press and not show on console.</param>
/// <returns>ConsoleKeyInfo object for the key press.</returns>
ConsoleKeyInfo ReadKey(bool intercept);
/// <summary>
/// Write the value to console.
/// </summary>
/// <param name="value">Value to be written to console.</param>
void Write(string value);
/// <summary>
/// Write the value to console and append end of line.
/// </summary>
/// <param name="value">Value to be written to console.</param>
void WriteLine(string value);
}
/// <summary>
/// Implementation on IConsole which redirects APIs to System.Console APIs.
/// </summary>
internal class SystemConsole : IConsole
{
/// <summary>
/// Height of the buffer.
/// </summary>
public int BufferHeight
{
get => System.Console.BufferHeight;
}
/// <summary>
/// Width of the buffer.
/// </summary>
public int BufferWidth
{
get => System.Console.BufferWidth;
}
/// <summary>
/// Height of the window.
/// </summary>
public int WindowHeight
{
get => System.Console.WindowHeight;
}
/// <summary>
/// Width of the window.
/// </summary>
public int WindowWidth
{
get => System.Console.WindowWidth;
}
/// <summary>
/// Clear the contents of the console.
/// </summary>
public void Clear()
{
System.Console.Clear();
}
/// <summary>
/// Read key press from the user.
/// </summary>
/// <param name="intercept">Intercept the key press and not show on console.</param>
/// <returns>ConsoleKeyInfo object for the key press.</returns>
public ConsoleKeyInfo ReadKey(bool intercept)
{
return System.Console.ReadKey(intercept);
}
/// <summary>
/// Write the value to console.
/// </summary>
/// <param name="value">Value to be written to console.</param>
public void Write(string value)
{
System.Console.Write(value);
}
/// <summary>
/// Write the value to console and append end of line.
/// </summary>
/// <param name="value">Value to be written to console.</param>
public void WriteLine(string value)
{
System.Console.WriteLine(value);
}
}
}