Giter Site home page Giter Site logo

Color on Windows about munit HOT 5 CLOSED

nemequ avatar nemequ commented on July 25, 2024
Color on Windows

from munit.

Comments (5)

nemequ avatar nemequ commented on July 25, 2024

I'm okay with b342b1b, but please use _getenv_s or _dupenv_s (I would probably use the former with a small stack based buffer, but whatever) to avoid that CRT warning.

I guess it would be possible to use SetConsoleTextAttribute to set colors on Windows, but TBH I'm not sure it's worth it. I don't think anyone takes the default command prompt seriously, and if conemu supports colors that's good enough for me.

from munit.

nemequ avatar nemequ commented on July 25, 2024

SetConsoleTextAttribute wouldn't work for people who are using --color always but redirecting the output (like we do to colorize AppVeyor's output), so it's probably better to avoid that.

Also, since you only want to check that ANSICON != NULL, you don't even need a buffer. Something like this should work:

if (isatty(fileno(stream))) {
  size_t ansicon_size;
  getenv_s(&ansicon_size, NULL, 0, "ANSICON");
  return ansicon_size != 0;
}
return false;

from munit.

jibsen avatar jibsen commented on July 25, 2024

I've updated the branch, but getenv_s is an extension to C11, so now some of the GCC builds break.

Quite oddly, only the mingw builds appear to break.

from munit.

nemequ avatar nemequ commented on July 25, 2024

Only mingw breaks because the getenv call is in guarded by an #if defined(_WIN32). I think everywhere else it's probably okay to assume that ttys support color. AFAIK Windows is the only platform which implements Annex K, but they're also the only ones who complain about getenv…

I pushed a fix which will just call the standard getenv on mingw, getenv_s on non-mingw windows, and still just use isatty everywhere else.

from munit.

jibsen avatar jibsen commented on July 25, 2024

Ah, of course -- thanks.

from munit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.