silkfire / Pastel

Snazz up your console output!
MIT License
405 stars 24 forks source link

No Pastel color output in macOS Terminal #23

Closed foobit closed 3 years ago

foobit commented 3 years ago

In the example below, the first WriteLine does not output red in the macOS Terminal (Catalina). However, the second WriteLine does output in red.

using System;
using System.Drawing;
using Pastel;

namespace TestColorOutput
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!".Pastel(Color.Red));
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Hello World!");
        }
    }
}

Notes

I also tested the above example in Windows 10 and Ubuntu 18.04 which behaves as expected.

silkfire commented 3 years ago

I've read somewhere before that ANSI codes have limited support on macOS but can't verify for sure. As I'm not a daily user of Mac myself it's hard for me to test this out. Feel free to post a PR if you come up with a fix or if you find out more information on the state of ANSI color codes in the Mac ecosystem that could be of use in developing a solution.

foobit commented 3 years ago

I'm still investigating. Note: Pastel color output works properly when running inside Visual Studio Code Terminal window.

As you said the macOS terminal is not interpreting it correctly. I'm going to look in to the Console.ForegroundColor source and see if there is something similar to Windows where we need to set a specific console mode.

KoB-Kirito commented 3 years ago

Can confirm this, it doesn't work with Terminal.

foobit commented 3 years ago

Ok, I found the issue.

The macOS terminal does not support the SGR 38 and 48 color parameters modes (24 bit color). However, the SGR 3/4/8 bit color modes formats do work. Wikipedia: ANSI escape codes

For me a proper fix would be:

Unfortunately, that doesn't sound like a simple pull request. However, at least it would be testable on non macOS terminals.

silkfire commented 3 years ago

Interesting finds there! I'll glady review any PRs to determine if this could be seamlessly merged into the library.

silkfire commented 3 years ago

Closing due to inactivity.

KoB-Kirito commented 3 years ago

Uhm, I still wait for a fix. What activity do you want? Nothing changed.

silkfire commented 3 years ago

I understand but as no one has contributed with a pull request in support of a solution I'd keep things tidy to not have a bunch of stale issues lying around. If things change I'd gladly reopen the issue or post a new one.