Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding #124

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
check for console before setting encoding
  • Loading branch information
Lee Christensen committed Feb 1, 2024
commit 3274e5e9f1e094c967fb56c940b3df682883d275
4 changes: 4 additions & 0 deletions Seatbelt/Interop/Kernel32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public struct WIN32_FIND_DATA
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetNamedPipeServerSessionId(IntPtr hPipe, out int ProcessId);

[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();


[Flags]
public enum ProcessAccess
{
Expand Down
12 changes: 11 additions & 1 deletion Seatbelt/Output/TextWriters/ConsoleTextWriter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using System;
using System.Text;
using Seatbelt.Interop;

namespace Seatbelt.Output.TextWriters
{
internal class ConsoleTextWriter : ITextWriter
{
public ConsoleTextWriter() => Console.OutputEncoding = Encoding.UTF8;
public ConsoleTextWriter()
{
if(IsConsolePresent())
Console.OutputEncoding = Encoding.UTF8;
}

public void Write(string str)
=> Console.Write(str);
Expand All @@ -21,5 +26,10 @@ public void WriteLine(string str)
public void Dispose()
{
}

bool IsConsolePresent()
{
return Kernel32.GetConsoleWindow() != IntPtr.Zero;
}
}
}
2 changes: 1 addition & 1 deletion Seatbelt/Seatbelt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Seatbelt : IDisposable

private readonly IOutputSink _outputSink;
private readonly Runtime _runtime;
private const string Version = "1.2.1";
private const string Version = "1.2.2";
private SeatbeltOptions Options { get; set; }

public Seatbelt(string[] args)
Expand Down