Skip to content

Commit

Permalink
Say: fix emojis on macOS/Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
electricduck committed Sep 15, 2024
1 parent 83a18c7 commit b2ee3c0
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Booski/Say.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Runtime.InteropServices;
using System.Text;

namespace Booski;
Expand Down Expand Up @@ -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))
{
Expand All @@ -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;
}

Expand All @@ -100,7 +111,7 @@ static void ConsoleMessage(

message += paddedReason;
}

if(!Program.NoSay)
{
if(separate)
Expand Down

0 comments on commit b2ee3c0

Please sign in to comment.