Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Demo/Hello.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#:property ImplicitUsings=true
#:package Spectre.Console@0.51.*

Console.WriteLine("Hello, World!");
using Spectre.Console;

AnsiConsole.MarkupLine(":globe_showing_americas: Hello, World!");
24 changes: 24 additions & 0 deletions src/SmallSharp/ConsoleEncodingInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace System;

/// <summary>
/// Ensures that when running from Visual Studio on Windows, the console encoding is set to UTF-8
/// to support full Unicode and emoji output.
/// </summary>
class ConsoleEncodingInitializer
{
#pragma warning disable CA2255 // The 'ModuleInitializer' attribute should not be used in libraries
[ModuleInitializer]
#pragma warning restore CA2255 // The 'ModuleInitializer' attribute should not be used in libraries
public static void Init()
{

#if DEBUG
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Console.InputEncoding = Console.OutputEncoding = Encoding.UTF8;
#endif
}
}
5 changes: 5 additions & 0 deletions src/SmallSharp/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@

<Import Project="..\build\SmallSharp.props" />

<!-- In SDK mode, we don't get the content files like we do in package mode, so we add it explicitly here -->
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)..\contentFiles\cs\netstandard2.0\ConsoleEncodingInitializer.cs"
NuGetPackageId="SmallSharp" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/SmallSharp/SmallSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<None Include="..\..\osmfeula.txt" Link="osmfeula.txt" PackagePath="OSMFEULA.txt" />
<Compile Update="ConsoleEncodingInitializer.cs" Pack="true" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/SmallSharp/SmallSharp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<!-- Ensure changes we make to this file trigger a new DTB -->
<UpToDateCheckBuilt Include="Properties\launchSettings.json" />
<UpToDateCheckBuilt Include="$(SmallSharpPackagesProps);$(SmallSharpPackagesTargets)" />
<Compile Update="@(Compile -> WithMetadataValue('NuGetPackageId', 'SmallSharp'))" Visible="false" />
</ItemGroup>

<!-- When restoring, if we include the source files, we'd get duplicate references. -->
Expand Down