Skip to content

Commit 304174a

Browse files
committed
Update nuget packages and implement property shims in the "ConsoleLikeStringWriter"
1 parent 4aafd10 commit 304174a

File tree

5 files changed

+123
-36
lines changed

5 files changed

+123
-36
lines changed

CSharpRepl.Tests/CSharpRepl.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
<PropertyGroup>
44
<EnablePreviewFeatures>true</EnablePreviewFeatures>
55
<LangVersion>preview</LangVersion>
6-
<TargetFramework>net6.0</TargetFramework>
6+
<TargetFramework>net7.0</TargetFramework>
77
<RootNamespace>CSDiscordService.Tests</RootNamespace>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1212
</ItemGroup>
1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.0" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0-preview-20211112-03" />
14+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.0-preview.1.22109.13" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0-release-20220209-04" />
1616
<PackageReference Include="xunit" Version="2.4.2-pre.12" />
1717
<PackageReference Include="xunit.runner.reporters" Version="2.4.2-pre.12" />
1818
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">

CSharpRepl.Tests/EvalTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public EvalTests(ITestOutputHelper outputHelper)
6969
[InlineData(@"var a = ""thing""; return a;", "thing", "string")]
7070
[InlineData("Math.Pow(1,2)", 1D, "double")]
7171
[InlineData(@"Enumerable.Range(0,1).Select(a=>""@"");", null, null)]
72-
[InlineData("typeof(int)", "System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", "RuntimeType")]
72+
[InlineData("typeof(int)", "System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", "RuntimeType")]
7373
[InlineData("Assembly.GetExecutingAssembly()", true, "RuntimeAssembly")]
7474
[InlineData("TimeSpan.FromSeconds(2310293892)", "26739.12:18:12", "TimeSpan")]
7575
public async Task Eval_WellFormattedCodeExecutes(string expr, object expected, string type)

CSharpRepl/CSharpRepl.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<EnablePreviewFeatures>true</EnablePreviewFeatures>
55
<LangVersion>preview</LangVersion>
6-
<TargetFramework>net6.0</TargetFramework>
6+
<TargetFramework>net7.0</TargetFramework>
77
<OutputType>Exe</OutputType>
88
<UserSecretsId>03629088-8bb9-4faf-8162-debf93066bc4</UserSecretsId>
99
</PropertyGroup>
@@ -18,13 +18,13 @@
1818

1919
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2020

21-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0-2.21561.5" />
21+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.2.0-2.22118.4" />
2222
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
23-
<PackageReference Include="NuGet.Packaging" Version="6.1.0-preview.1.38" />
24-
<PackageReference Include="NuGet.Protocol" Version="6.1.0-preview.1.38" />
25-
<PackageReference Include="NuGet.Resolver" Version="6.1.0-preview.1.38" />
23+
<PackageReference Include="NuGet.Packaging" Version="6.2.0-preview.2.75" />
24+
<PackageReference Include="NuGet.Protocol" Version="6.2.0-preview.2.75" />
25+
<PackageReference Include="NuGet.Resolver" Version="6.2.0-preview.2.75" />
2626
<PackageReference Include="Seq.Extensions.Logging" Version="6.1.0-dev-00091" />
27-
<PackageReference Include="System.Runtime.Experimental" Version="6.0.0" />
27+
<PackageReference Include="System.Runtime.Experimental" Version="7.0.0-preview.1.22076.8" />
2828
</ItemGroup>
2929
<ItemGroup>
3030
<None Update="start.sh">

CSharpRepl/Eval/ResultModels/ConsoleLikeStringWriter.cs

Lines changed: 111 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,153 @@
1-
using System;
1+
#nullable enable
2+
using System;
23
using System.IO;
4+
using System.Runtime.Versioning;
35
using System.Text;
46

57
#pragma warning disable IDE0060 // Remove unused parameter
68
namespace CSDiscordService.Eval.ResultModels
79
{
810
public class ConsoleLikeStringWriter : StringWriter
911
{
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+
}
1159

1260
public void Beep() { }
1361

1462
public void Beep(int a, int b) { }
1563

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+
}
1772

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) { }
1974

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) { }
2176

2277
public Stream OpenStandardError() => new MemoryStream();
2378

24-
public Stream OpenStandardError(int a) => new MemoryStream(a);
79+
public Stream OpenStandardError(int bufferSize) => new MemoryStream(bufferSize);
2580

2681
public Stream OpenStandardInput() => new MemoryStream();
2782

28-
public Stream OpenStandardInput(int a) => new MemoryStream(a);
83+
public Stream OpenStandardInput(int bufferSize) => new MemoryStream(bufferSize);
2984

3085
public Stream OpenStandardOutput() => new MemoryStream();
3186

32-
public Stream OpenStandardOutput(int a) => new MemoryStream(a);
87+
public Stream OpenStandardOutput(int bufferSize) => new MemoryStream(bufferSize);
3388

34-
public int Read() => 0;
89+
public int Read() => -1;
3590

36-
public ConsoleKeyInfo ReadKey() => new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false);
91+
public ConsoleKeyInfo ReadKey() => _readKeyValue;
3792

38-
public ConsoleKeyInfo ReadKey(bool a)
93+
public ConsoleKeyInfo ReadKey(bool intercept)
3994
{
40-
if (a)
95+
if (intercept)
4196
{
42-
Write("a");
97+
Write(_readKeyValue.KeyChar);
4398
}
4499
return ReadKey();
45100
}
46101

47-
public string ReadLine() => $"a{Environment.NewLine}";
102+
public string ReadLine() => _readLineValue;
48103

49-
public void ResetColor() { }
104+
public void ResetColor()
105+
{
106+
ForegroundColor = Console.ForegroundColor;
107+
BackgroundColor = Console.BackgroundColor;
108+
}
50109

51-
public void SetBufferSize(int a, int b) { }
110+
public void SetBufferSize(int width, int height)
111+
{
112+
BufferWidth = width;
113+
BufferHeight = height;
114+
}
52115

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+
}
54126

55-
public void SetError(TextWriter wr) { }
127+
public void SetIn(TextWriter wr)
128+
{
129+
In = wr;
130+
InputEncoding = wr.Encoding;
131+
}
56132

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+
}
60150

61-
public void SetWindowPosition(int a, int b) { }
62-
63-
public void SetWindowSize(int a, int b) { }
64151
}
65152
}
66153

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:6.0 as dotnet-build
1+
FROM mcr.microsoft.com/dotnet/sdk:7.0 as dotnet-build
22
WORKDIR /src
33
COPY . .
44
RUN dotnet --info
@@ -8,7 +8,7 @@ RUN dotnet build --configuration Release --no-restore
88
#RUN dotnet test --configuration Release CSharpRepl.Tests/CSharpRepl.Tests.csproj --no-build --no-restore
99
RUN dotnet publish --configuration Release CSharpRepl/CSharpRepl.csproj --no-build --no-restore -o /app
1010

11-
FROM mcr.microsoft.com/dotnet/aspnet:6.0
11+
FROM mcr.microsoft.com/dotnet/aspnet:7.0
1212
WORKDIR /app
1313
COPY --from=dotnet-build /app .
1414
ENTRYPOINT ["bash", "start.sh"]

0 commit comments

Comments
 (0)