|
1 |
| -using System; |
| 1 | +#nullable enable |
| 2 | +using System; |
2 | 3 | using System.IO;
|
| 4 | +using System.Runtime.Versioning; |
3 | 5 | using System.Text;
|
4 | 6 |
|
5 | 7 | #pragma warning disable IDE0060 // Remove unused parameter
|
6 | 8 | namespace CSDiscordService.Eval.ResultModels
|
7 | 9 | {
|
8 | 10 | public class ConsoleLikeStringWriter : StringWriter
|
9 | 11 | {
|
10 |
| - public ConsoleLikeStringWriter(StringBuilder builder) : base(builder) { } |
| 12 | + private ConsoleKeyInfo _readKeyValue = new('a', ConsoleKey.A, false, false, false); |
| 13 | + private string _readLineValue = $"line{Environment.NewLine}"; |
| 14 | + |
| 15 | + |
| 16 | + public ConsoleColor BackgroundColor { get; set; } = Console.BackgroundColor; |
| 17 | + public int BufferHeight { get; set; } |
| 18 | + public int BufferWidth { get; set; } |
| 19 | + |
| 20 | + [SupportedOSPlatform("windows")] |
| 21 | + public bool CapsLock => Console.CapsLock; |
| 22 | + public int CursorLeft { get; set; } |
| 23 | + public int CursorSize { get; set; } |
| 24 | + public int CursorTop { get; set; } |
| 25 | + [SupportedOSPlatform("windows")] |
| 26 | + public bool CursorVisible { get; set; } |
| 27 | + public TextWriter Error { get; set; } |
| 28 | + public ConsoleColor ForegroundColor { get; set; } = Console.ForegroundColor; |
| 29 | + public TextWriter In { get; set; } = new StringWriter(); |
| 30 | + public Encoding InputEncoding { get; set; } = Encoding.UTF8; |
| 31 | + public TextWriter Out { get; set; } |
| 32 | + public Encoding OutEncoding { get; set; } |
| 33 | + [SupportedOSPlatform("windows")] |
| 34 | + public string Title { get; set; } = "This is a Console, I promise!"; |
| 35 | + public bool TreateControlCAsInput { get; set; } = Console.TreatControlCAsInput; |
| 36 | + public int WindowHeight { get; set; } |
| 37 | + public int WindowLeft { get; set; } |
| 38 | + public int WindowTop { get; set; } |
| 39 | + public int WindowWidth { get; set; } |
| 40 | + |
| 41 | + public event ConsoleCancelEventHandler? CancelKeyPress { add { } remove { } } |
| 42 | + |
| 43 | + public ConsoleLikeStringWriter(StringBuilder builder) : base(builder) |
| 44 | + { |
| 45 | + Error = this; |
| 46 | + Out = this; |
| 47 | + OutEncoding = this.Encoding; |
| 48 | + } |
| 49 | + |
| 50 | + public void SetReadKeyValue(ConsoleKeyInfo value) |
| 51 | + { |
| 52 | + _readKeyValue = value; |
| 53 | + } |
| 54 | + |
| 55 | + public void SetReadLineValue(string line) |
| 56 | + { |
| 57 | + _readLineValue = $"{line}{Environment.NewLine}"; |
| 58 | + } |
11 | 59 |
|
12 | 60 | public void Beep() { }
|
13 | 61 |
|
14 | 62 | public void Beep(int a, int b) { }
|
15 | 63 |
|
16 |
| - public void Clear() { } |
| 64 | + public void Clear() |
| 65 | + { |
| 66 | + base.GetStringBuilder().Clear(); |
| 67 | + } |
| 68 | + public (int Left, int Top) GetCursorPosition() |
| 69 | + { |
| 70 | + return (CursorLeft, CursorTop); |
| 71 | + } |
17 | 72 |
|
18 |
| - public void MoveBufferArea(int a, int b, int c, int d, int e) { } |
| 73 | + public void MoveBufferArea(int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop) { } |
19 | 74 |
|
20 |
| - public void MoveBufferArea(int a, int b, int c, int d, int e, char f, ConsoleColor g, ConsoleColor h) { } |
| 75 | + public void MoveBufferArea(int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop, char sourceChar, ConsoleColor sourceForeColor, ConsoleColor sourceBackColor) { } |
21 | 76 |
|
22 | 77 | public Stream OpenStandardError() => new MemoryStream();
|
23 | 78 |
|
24 |
| - public Stream OpenStandardError(int a) => new MemoryStream(a); |
| 79 | + public Stream OpenStandardError(int bufferSize) => new MemoryStream(bufferSize); |
25 | 80 |
|
26 | 81 | public Stream OpenStandardInput() => new MemoryStream();
|
27 | 82 |
|
28 |
| - public Stream OpenStandardInput(int a) => new MemoryStream(a); |
| 83 | + public Stream OpenStandardInput(int bufferSize) => new MemoryStream(bufferSize); |
29 | 84 |
|
30 | 85 | public Stream OpenStandardOutput() => new MemoryStream();
|
31 | 86 |
|
32 |
| - public Stream OpenStandardOutput(int a) => new MemoryStream(a); |
| 87 | + public Stream OpenStandardOutput(int bufferSize) => new MemoryStream(bufferSize); |
33 | 88 |
|
34 |
| - public int Read() => 0; |
| 89 | + public int Read() => -1; |
35 | 90 |
|
36 |
| - public ConsoleKeyInfo ReadKey() => new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false); |
| 91 | + public ConsoleKeyInfo ReadKey() => _readKeyValue; |
37 | 92 |
|
38 |
| - public ConsoleKeyInfo ReadKey(bool a) |
| 93 | + public ConsoleKeyInfo ReadKey(bool intercept) |
39 | 94 | {
|
40 |
| - if (a) |
| 95 | + if (intercept) |
41 | 96 | {
|
42 |
| - Write("a"); |
| 97 | + Write(_readKeyValue.KeyChar); |
43 | 98 | }
|
44 | 99 | return ReadKey();
|
45 | 100 | }
|
46 | 101 |
|
47 |
| - public string ReadLine() => $"a{Environment.NewLine}"; |
| 102 | + public string ReadLine() => _readLineValue; |
48 | 103 |
|
49 |
| - public void ResetColor() { } |
| 104 | + public void ResetColor() |
| 105 | + { |
| 106 | + ForegroundColor = Console.ForegroundColor; |
| 107 | + BackgroundColor = Console.BackgroundColor; |
| 108 | + } |
50 | 109 |
|
51 |
| - public void SetBufferSize(int a, int b) { } |
| 110 | + public void SetBufferSize(int width, int height) |
| 111 | + { |
| 112 | + BufferWidth = width; |
| 113 | + BufferHeight = height; |
| 114 | + } |
52 | 115 |
|
53 |
| - public void SetCursorPosition(int a, int b) { } |
| 116 | + public void SetCursorPosition(int left, int top) |
| 117 | + { |
| 118 | + CursorLeft = left; |
| 119 | + CursorTop = top; |
| 120 | + } |
| 121 | + |
| 122 | + public void SetError(TextWriter wr) |
| 123 | + { |
| 124 | + Error = wr; |
| 125 | + } |
54 | 126 |
|
55 |
| - public void SetError(TextWriter wr) { } |
| 127 | + public void SetIn(TextWriter wr) |
| 128 | + { |
| 129 | + In = wr; |
| 130 | + InputEncoding = wr.Encoding; |
| 131 | + } |
56 | 132 |
|
57 |
| - public void SetIn(TextWriter wr) { } |
58 |
| - |
59 |
| - public void SetOut(TextWriter wr) { } |
| 133 | + public void SetOut(TextWriter wr) |
| 134 | + { |
| 135 | + Out = wr; |
| 136 | + OutEncoding = wr.Encoding; |
| 137 | + } |
| 138 | + |
| 139 | + public void SetWindowPosition(int left, int top) |
| 140 | + { |
| 141 | + WindowLeft = left; |
| 142 | + WindowTop = top; |
| 143 | + } |
| 144 | + |
| 145 | + public void SetWindowSize(int width, int height) |
| 146 | + { |
| 147 | + WindowWidth = width; |
| 148 | + WindowHeight = height; |
| 149 | + } |
60 | 150 |
|
61 |
| - public void SetWindowPosition(int a, int b) { } |
62 |
| - |
63 |
| - public void SetWindowSize(int a, int b) { } |
64 | 151 | }
|
65 | 152 | }
|
66 | 153 |
|
|
0 commit comments