Skip to content
Snippets Groups Projects
Commit 8799f3d5 authored by Lyndon Brown's avatar Lyndon Brown
Browse files

enable windows colour console support

and thus enable support for:
 - colour console logging.
 - colour help text.
 - colour highlighting of errors and warnings when parsing commandline
   arguments on windows.

according to [1] microsoft provide `isatty()` support under the name
`_isatty()` in `io.h` due to it being non-standard.

i was originally going to attempt to duplicate the use of the
`GetConsoleMode()` function as done in the rust `atty` crate, but the
existence of `_isatty()` is much more simple. it's left me confused over
why the rust crate uses `GetConsoleMode()` instead. i have not turned up
any info so far about when `_isatty()` was introduced on windows, so maybe
its too new? maybe it doesn't support special environments like cygwin? i
have noted that it was already in use by `src/text/unicode.c`.

[1]: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/isatty?view=msvc-170
parent f45fd76f
Branches win_isatty
No related tags found
No related merge requests found
......@@ -675,6 +675,11 @@ int clock_nanosleep(clockid_t clock_id, int flags,
# endif
#endif
#ifdef _WIN32
# include <io.h>
# define isatty(x) _isatty(x)
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
......
......@@ -154,7 +154,7 @@ static const struct vlc_logger_operations *Open(vlc_object_t *obj,
*sysp = verbosities + verbosity;
#if defined (HAVE_ISATTY) && !defined (_WIN32)
#if defined (HAVE_ISATTY)
if (isatty(STDERR_FILENO) && var_InheritBool(obj, "color"))
return &color_ops;
#endif
......
......@@ -182,10 +182,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
psz_shortopts[i_shortopts] = '\0';
int ret = -1;
bool color = false;
#ifndef _WIN32
color = (isatty(STDERR_FILENO));
#endif
bool color = isatty(STDERR_FILENO);
/*
* Parse the command line options
......
......@@ -584,10 +584,8 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
}
bool color = false;
#ifndef _WIN32
if (isatty(STDOUT_FILENO))
color = var_InheritBool(p_this, "color");
#endif
const bool desc = var_InheritBool(p_this, "help-verbose");
......@@ -646,12 +644,8 @@ static void ListModules (vlc_object_t *p_this, bool b_verbose)
bool color = false;
ShowConsole();
#ifndef _WIN32
if (isatty(STDOUT_FILENO))
color = var_InheritBool(p_this, "color");
#else
(void) p_this;
#endif
/* List all modules */
size_t count;
......
......@@ -39,9 +39,6 @@
#include <stdarg.h>
#include <stdlib.h>
#include <sys/types.h>
#if defined(_WIN32)
# include <io.h>
#endif
#include <errno.h>
#include <wctype.h>
......@@ -65,7 +62,7 @@ int utf8_vfprintf( FILE *stream, const char *fmt, va_list ap )
* which is different from the usual ANSI code page. Or maybe not, if the
* user called "chcp". Anyway, we prefer Unicode. */
int fd = _fileno (stream);
if (likely(fd != -1) && _isatty (fd))
if (likely(fd != -1) && isatty (fd))
{
wchar_t *wide = ToWide (str);
if (likely(wide != NULL))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment