Skip to content

Commit

Permalink
Set process output encoding to UTF-8
Browse files Browse the repository at this point in the history
This enables full unicode in commit change log too.
  • Loading branch information
kzu committed Oct 31, 2024
1 parent e7c3a2c commit ebded7f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 33 deletions.
33 changes: 1 addition & 32 deletions src/File/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
3 changes: 2 additions & 1 deletion src/File/Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ebded7f

Please sign in to comment.