From b2ee3c08394a4344a8ec01f46c1eed9074f552f3 Mon Sep 17 00:00:00 2001 From: Ducky Date: Sun, 15 Sep 2024 19:18:48 +0100 Subject: [PATCH] Say: fix emojis on macOS/Linux --- src/Booski/Say.cs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Booski/Say.cs b/src/Booski/Say.cs index 745570c..2298818 100644 --- a/src/Booski/Say.cs +++ b/src/Booski/Say.cs @@ -1,3 +1,4 @@ +using System.Runtime.InteropServices; using System.Text; namespace Booski; @@ -69,11 +70,21 @@ static void ConsoleMessage( bool separate = false ) { - var emojiPadding = 1; - var emojiPaddingString = new String(' ', emojiPadding); - if(!String.IsNullOrEmpty(emoji)) - message = $"{emoji}{emojiPaddingString}{message}"; + { + // BUG: If you're SSH'd into Windows from macOS/Linux, + // this won't trigger and the emoji padding will still be borked + if(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var emojiByteLength = Encoding.UTF8.GetBytes(emoji).Length; + if(emojiByteLength > 4) + { + message = $" {message}"; + } + } + + message = $"{emoji} {message}"; + } if(!String.IsNullOrEmpty(reason)) { @@ -90,8 +101,8 @@ static void ConsoleMessage( if (line != null) { paddedReason += Environment.NewLine; - if(!String.IsNullOrEmpty(emojiPaddingString)) - paddedReason += $"{emojiPaddingString} "; + if(!String.IsNullOrEmpty(emoji)) + paddedReason += $" "; paddedReason += line; } @@ -100,7 +111,7 @@ static void ConsoleMessage( message += paddedReason; } - + if(!Program.NoSay) { if(separate)