From ebded7f8b65c7719207e764a23ad78d565a899a3 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Thu, 31 Oct 2024 19:18:37 -0300 Subject: [PATCH] Set process output encoding to UTF-8 This enables full unicode in commit change log too. --- src/File/GitHub.cs | 33 +-------------------------------- src/File/Process.cs | 3 ++- 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/src/File/GitHub.cs b/src/File/GitHub.cs index 44fa75a..0667019 100644 --- a/src/File/GitHub.cs +++ b/src/File/GitHub.cs @@ -270,40 +270,9 @@ commitJson is JObject commitObj && output.AppendLine($"# {group.Key}").AppendLine(); ColorConsole.WriteLine($"# {group.Key}".Gray()); - // GitHub REST API does not seem to handle unicode the same way the website - // does. Unicode emoji shows up perfectly fine on the web (see https://github.com/devlooped/oss/commits/main/.github/workflows/build.yml) - // yet each emoji shows up as multiple separate chars in the responses. We - // implement a simple cleanup that works in our tests with devlooped/oss repo. - static string removeUnicodeEmoji(string message) - { - var result = new StringBuilder(message.Length); - var index = 0; - while (index < message.Length) - { - // Consider up to U+036F / 879 char as "regular" text. - // This would allow some formatting chars still. - // Anything higher, consider as the start of an unicode emoji - // symbol comprising more chars until the next high one. - if (message[index] > 879) - { - while (++index <= message.Length && message[index] <= 879 && !char.IsWhiteSpace(message[index])) - ; - - index++; - } - else - { - result.Append(message[index]); - index++; - } - } - - return result.ToString(); - }; - foreach (var (sha, date, message) in commits) { - var line = $"- {removeUnicodeEmoji(message).Trim()} https://github.com/{group.Key}/commit/{sha[..7]}"; + var line = $"- {message.Trim()} https://github.com/{group.Key}/commit/{sha[..7]}"; output.AppendLine(line); ColorConsole.WriteLine(line.Gray()); } diff --git a/src/File/Process.cs b/src/File/Process.cs index c112a5a..c1b6190 100644 --- a/src/File/Process.cs +++ b/src/File/Process.cs @@ -10,7 +10,8 @@ public static bool TryExecute(string program, string arguments, out string outpu var info = new ProcessStartInfo(program, arguments) { RedirectStandardOutput = true, - RedirectStandardError = true + RedirectStandardError = true, + StandardOutputEncoding = System.Text.Encoding.UTF8, }; try