Terminal.c 15.5 KB
Newer Older
Kitware Robot's avatar
Kitware Robot committed
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing#kwsys for details.  */
Kitware Robot's avatar
Kitware Robot committed
3 4 5 6 7 8
#include "kwsysPrivate.h"
#include KWSYS_HEADER(Terminal.h)

/* Work-around CMake dependency scanning limitation.  This must
   duplicate the above list of headers.  */
#if 0
Kitware Robot's avatar
Kitware Robot committed
9
#  include "Terminal.h.in"
Kitware Robot's avatar
Kitware Robot committed
10 11 12 13
#endif

/* Configure support for this platform.  */
#if defined(_WIN32) || defined(__CYGWIN__)
Kitware Robot's avatar
Kitware Robot committed
14
#  define KWSYS_TERMINAL_SUPPORT_CONSOLE
Kitware Robot's avatar
Kitware Robot committed
15 16
#endif
#if !defined(_WIN32)
Kitware Robot's avatar
Kitware Robot committed
17
#  define KWSYS_TERMINAL_ISATTY_WORKS
Kitware Robot's avatar
Kitware Robot committed
18 19 20 21
#endif

/* Include needed system APIs.  */

Kitware Robot's avatar
Kitware Robot committed
22
#include <stdarg.h> /* va_list */
Kitware Robot's avatar
Kitware Robot committed
23 24 25 26
#include <stdlib.h> /* getenv */
#include <string.h> /* strcmp */

#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
Kitware Robot's avatar
Kitware Robot committed
27 28
#  include <io.h>      /* _get_osfhandle */
#  include <windows.h> /* SetConsoleTextAttribute */
Kitware Robot's avatar
Kitware Robot committed
29 30 31
#endif

#if defined(KWSYS_TERMINAL_ISATTY_WORKS)
Kitware Robot's avatar
Kitware Robot committed
32
#  include <unistd.h> /* isatty */
Kitware Robot's avatar
Kitware Robot committed
33
#else
Kitware Robot's avatar
Kitware Robot committed
34
#  include <sys/stat.h> /* fstat */
Kitware Robot's avatar
Kitware Robot committed
35 36 37 38 39 40 41 42 43
#endif

static int kwsysTerminalStreamIsVT100(FILE* stream, int default_vt100,
                                      int default_tty);
static void kwsysTerminalSetVT100Color(FILE* stream, int color);
#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
static HANDLE kwsysTerminalGetStreamHandle(FILE* stream);
static void kwsysTerminalSetConsoleColor(HANDLE hOut,
                                         CONSOLE_SCREEN_BUFFER_INFO* hOutInfo,
Kitware Robot's avatar
Kitware Robot committed
44
                                         FILE* stream, int color);
Kitware Robot's avatar
Kitware Robot committed
45 46 47 48 49 50 51 52 53 54 55 56
#endif

void kwsysTerminal_cfprintf(int color, FILE* stream, const char* format, ...)
{
  /* Setup the stream with the given color if possible.  */
  int pipeIsConsole = 0;
  int pipeIsVT100 = 0;
  int default_vt100 = color & kwsysTerminal_Color_AssumeVT100;
  int default_tty = color & kwsysTerminal_Color_AssumeTTY;
#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
  CONSOLE_SCREEN_BUFFER_INFO hOutInfo;
  HANDLE hOut = kwsysTerminalGetStreamHandle(stream);
Kitware Robot's avatar
Kitware Robot committed
57
  if (GetConsoleScreenBufferInfo(hOut, &hOutInfo)) {
Kitware Robot's avatar
Kitware Robot committed
58 59
    pipeIsConsole = 1;
    kwsysTerminalSetConsoleColor(hOut, &hOutInfo, stream, color);
Kitware Robot's avatar
Kitware Robot committed
60
  }
Kitware Robot's avatar
Kitware Robot committed
61
#endif
Kitware Robot's avatar
Kitware Robot committed
62 63
  if (!pipeIsConsole &&
      kwsysTerminalStreamIsVT100(stream, default_vt100, default_tty)) {
Kitware Robot's avatar
Kitware Robot committed
64 65
    pipeIsVT100 = 1;
    kwsysTerminalSetVT100Color(stream, color);
Kitware Robot's avatar
Kitware Robot committed
66
  }
Kitware Robot's avatar
Kitware Robot committed
67 68 69

  /* Format the text into the stream.  */
  {
Kitware Robot's avatar
Kitware Robot committed
70 71 72 73
    va_list var_args;
    va_start(var_args, format);
    vfprintf(stream, format, var_args);
    va_end(var_args);
Kitware Robot's avatar
Kitware Robot committed
74 75
  }

Kitware Robot's avatar
Kitware Robot committed
76
/* Restore the normal color state for the stream.  */
Kitware Robot's avatar
Kitware Robot committed
77
#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
Kitware Robot's avatar
Kitware Robot committed
78
  if (pipeIsConsole) {
Kitware Robot's avatar
Kitware Robot committed
79 80
    kwsysTerminalSetConsoleColor(hOut, &hOutInfo, stream,
                                 kwsysTerminal_Color_Normal);
Kitware Robot's avatar
Kitware Robot committed
81
  }
Kitware Robot's avatar
Kitware Robot committed
82
#endif
Kitware Robot's avatar
Kitware Robot committed
83
  if (pipeIsVT100) {
Kitware Robot's avatar
Kitware Robot committed
84
    kwsysTerminalSetVT100Color(stream, kwsysTerminal_Color_Normal);
Kitware Robot's avatar
Kitware Robot committed
85
  }
Kitware Robot's avatar
Kitware Robot committed
86 87
}

Kitware Robot's avatar
Kitware Robot committed
88
/* Detect cases when a stream is definitely not interactive.  */
Kitware Robot's avatar
Kitware Robot committed
89 90 91
#if !defined(KWSYS_TERMINAL_ISATTY_WORKS)
static int kwsysTerminalStreamIsNotInteractive(FILE* stream)
{
Kitware Robot's avatar
Kitware Robot committed
92
  /* The given stream is definitely not interactive if it is a regular
Kitware Robot's avatar
Kitware Robot committed
93 94
     file.  */
  struct stat stream_stat;
Kitware Robot's avatar
Kitware Robot committed
95 96
  if (fstat(fileno(stream), &stream_stat) == 0) {
    if (stream_stat.st_mode & S_IFREG) {
Kitware Robot's avatar
Kitware Robot committed
97 98
      return 1;
    }
Kitware Robot's avatar
Kitware Robot committed
99
  }
Kitware Robot's avatar
Kitware Robot committed
100 101 102 103 104
  return 0;
}
#endif

/* List of terminal names known to support VT100 color escape sequences.  */
Kitware Robot's avatar
Kitware Robot committed
105
static const char* kwsysTerminalVT100Names[] = { "Eterm",
Kitware Robot's avatar
Kitware Robot committed
106 107
                                                 "alacritty",
                                                 "alacritty-direct",
Kitware Robot's avatar
Kitware Robot committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
                                                 "ansi",
                                                 "color-xterm",
                                                 "con132x25",
                                                 "con132x30",
                                                 "con132x43",
                                                 "con132x60",
                                                 "con80x25",
                                                 "con80x28",
                                                 "con80x30",
                                                 "con80x43",
                                                 "con80x50",
                                                 "con80x60",
                                                 "cons25",
                                                 "console",
                                                 "cygwin",
                                                 "dtterm",
                                                 "eterm-color",
                                                 "gnome",
                                                 "gnome-256color",
                                                 "konsole",
                                                 "konsole-256color",
                                                 "kterm",
                                                 "linux",
                                                 "msys",
                                                 "linux-c",
                                                 "mach-color",
                                                 "mlterm",
                                                 "putty",
                                                 "putty-256color",
                                                 "rxvt",
                                                 "rxvt-256color",
                                                 "rxvt-cygwin",
                                                 "rxvt-cygwin-native",
                                                 "rxvt-unicode",
                                                 "rxvt-unicode-256color",
                                                 "screen",
                                                 "screen-256color",
                                                 "screen-256color-bce",
                                                 "screen-bce",
                                                 "screen-w",
                                                 "screen.linux",
Kitware Robot's avatar
Kitware Robot committed
149 150
                                                 "tmux",
                                                 "tmux-256color",
Kitware Robot's avatar
Kitware Robot committed
151 152 153 154 155 156 157
                                                 "vt100",
                                                 "xterm",
                                                 "xterm-16color",
                                                 "xterm-256color",
                                                 "xterm-88color",
                                                 "xterm-color",
                                                 "xterm-debian",
Kitware Robot's avatar
Kitware Robot committed
158
                                                 "xterm-kitty",
Kitware Robot's avatar
Kitware Robot committed
159 160
                                                 "xterm-termite",
                                                 0 };
Kitware Robot's avatar
Kitware Robot committed
161 162 163 164 165

/* Detect whether a stream is displayed in a VT100-compatible terminal.  */
static int kwsysTerminalStreamIsVT100(FILE* stream, int default_vt100,
                                      int default_tty)
{
Kitware Robot's avatar
Kitware Robot committed
166 167
  /* Force color according to http://bixense.com/clicolors/ convention.  */
  {
Kitware Robot's avatar
Kitware Robot committed
168 169 170 171
    const char* clicolor_force = getenv("CLICOLOR_FORCE");
    if (clicolor_force && *clicolor_force &&
        strcmp(clicolor_force, "0") != 0) {
      return 1;
Kitware Robot's avatar
Kitware Robot committed
172 173 174
    }
  }

Kitware Robot's avatar
Kitware Robot committed
175 176 177
  /* If running inside emacs the terminal is not VT100.  Some emacs
     seem to claim the TERM is xterm even though they do not support
     VT100 escapes.  */
Kitware Robot's avatar
Kitware Robot committed
178
  {
Kitware Robot's avatar
Kitware Robot committed
179 180 181
    const char* emacs = getenv("EMACS");
    if (emacs && *emacs == 't') {
      return 0;
Kitware Robot's avatar
Kitware Robot committed
182
    }
Kitware Robot's avatar
Kitware Robot committed
183
  }
Kitware Robot's avatar
Kitware Robot committed
184 185

  /* Check for a valid terminal.  */
Kitware Robot's avatar
Kitware Robot committed
186
  if (!default_vt100) {
Kitware Robot's avatar
Kitware Robot committed
187 188
    const char** t = 0;
    const char* term = getenv("TERM");
Kitware Robot's avatar
Kitware Robot committed
189 190
    if (term) {
      for (t = kwsysTerminalVT100Names; *t && strcmp(term, *t) != 0; ++t) {
Kitware Robot's avatar
Kitware Robot committed
191
      }
Kitware Robot's avatar
Kitware Robot committed
192 193
    }
    if (!(t && *t)) {
Kitware Robot's avatar
Kitware Robot committed
194 195
      return 0;
    }
Kitware Robot's avatar
Kitware Robot committed
196
  }
Kitware Robot's avatar
Kitware Robot committed
197 198 199 200

#if defined(KWSYS_TERMINAL_ISATTY_WORKS)
  /* Make sure the stream is a tty. */
  (void)default_tty;
Kitware Robot's avatar
Kitware Robot committed
201
  return isatty(fileno(stream)) ? 1 : 0;
Kitware Robot's avatar
Kitware Robot committed
202
#else
Kitware Robot's avatar
Kitware Robot committed
203
  /* Check for cases in which the stream is definitely not a tty.  */
Kitware Robot's avatar
Kitware Robot committed
204
  if (kwsysTerminalStreamIsNotInteractive(stream)) {
Kitware Robot's avatar
Kitware Robot committed
205
    return 0;
Kitware Robot's avatar
Kitware Robot committed
206
  }
Kitware Robot's avatar
Kitware Robot committed
207 208 209 210 211 212 213

  /* Use the provided default for whether this is a tty.  */
  return default_tty;
#endif
}

/* VT100 escape sequence strings.  */
Kitware Robot's avatar
Kitware Robot committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
#if defined(__MVS__)
/* if building on z/OS (aka MVS), assume we are using EBCDIC */
#  define ESCAPE_CHAR "\47"
#else
#  define ESCAPE_CHAR "\33"
#endif

#define KWSYS_TERMINAL_VT100_NORMAL ESCAPE_CHAR "[0m"
#define KWSYS_TERMINAL_VT100_BOLD ESCAPE_CHAR "[1m"
#define KWSYS_TERMINAL_VT100_UNDERLINE ESCAPE_CHAR "[4m"
#define KWSYS_TERMINAL_VT100_BLINK ESCAPE_CHAR "[5m"
#define KWSYS_TERMINAL_VT100_INVERSE ESCAPE_CHAR "[7m"
#define KWSYS_TERMINAL_VT100_FOREGROUND_BLACK ESCAPE_CHAR "[30m"
#define KWSYS_TERMINAL_VT100_FOREGROUND_RED ESCAPE_CHAR "[31m"
#define KWSYS_TERMINAL_VT100_FOREGROUND_GREEN ESCAPE_CHAR "[32m"
#define KWSYS_TERMINAL_VT100_FOREGROUND_YELLOW ESCAPE_CHAR "[33m"
#define KWSYS_TERMINAL_VT100_FOREGROUND_BLUE ESCAPE_CHAR "[34m"
#define KWSYS_TERMINAL_VT100_FOREGROUND_MAGENTA ESCAPE_CHAR "[35m"
#define KWSYS_TERMINAL_VT100_FOREGROUND_CYAN ESCAPE_CHAR "[36m"
#define KWSYS_TERMINAL_VT100_FOREGROUND_WHITE ESCAPE_CHAR "[37m"
#define KWSYS_TERMINAL_VT100_BACKGROUND_BLACK ESCAPE_CHAR "[40m"
#define KWSYS_TERMINAL_VT100_BACKGROUND_RED ESCAPE_CHAR "[41m"
#define KWSYS_TERMINAL_VT100_BACKGROUND_GREEN ESCAPE_CHAR "[42m"
#define KWSYS_TERMINAL_VT100_BACKGROUND_YELLOW ESCAPE_CHAR "[43m"
#define KWSYS_TERMINAL_VT100_BACKGROUND_BLUE ESCAPE_CHAR "[44m"
#define KWSYS_TERMINAL_VT100_BACKGROUND_MAGENTA ESCAPE_CHAR "[45m"
#define KWSYS_TERMINAL_VT100_BACKGROUND_CYAN ESCAPE_CHAR "[46m"
#define KWSYS_TERMINAL_VT100_BACKGROUND_WHITE ESCAPE_CHAR "[47m"
Kitware Robot's avatar
Kitware Robot committed
242 243 244 245

/* Write VT100 escape sequences to the stream for the given color.  */
static void kwsysTerminalSetVT100Color(FILE* stream, int color)
{
Kitware Robot's avatar
Kitware Robot committed
246
  if (color == kwsysTerminal_Color_Normal) {
Kitware Robot's avatar
Kitware Robot committed
247 248
    fprintf(stream, KWSYS_TERMINAL_VT100_NORMAL);
    return;
Kitware Robot's avatar
Kitware Robot committed
249
  }
Kitware Robot's avatar
Kitware Robot committed
250

Kitware Robot's avatar
Kitware Robot committed
251
  switch (color & kwsysTerminal_Color_ForegroundMask) {
Kitware Robot's avatar
Kitware Robot committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
    case kwsysTerminal_Color_Normal:
      fprintf(stream, KWSYS_TERMINAL_VT100_NORMAL);
      break;
    case kwsysTerminal_Color_ForegroundBlack:
      fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_BLACK);
      break;
    case kwsysTerminal_Color_ForegroundRed:
      fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_RED);
      break;
    case kwsysTerminal_Color_ForegroundGreen:
      fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_GREEN);
      break;
    case kwsysTerminal_Color_ForegroundYellow:
      fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_YELLOW);
      break;
    case kwsysTerminal_Color_ForegroundBlue:
      fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_BLUE);
      break;
    case kwsysTerminal_Color_ForegroundMagenta:
      fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_MAGENTA);
      break;
    case kwsysTerminal_Color_ForegroundCyan:
      fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_CYAN);
      break;
    case kwsysTerminal_Color_ForegroundWhite:
      fprintf(stream, KWSYS_TERMINAL_VT100_FOREGROUND_WHITE);
      break;
Kitware Robot's avatar
Kitware Robot committed
279 280
  }
  switch (color & kwsysTerminal_Color_BackgroundMask) {
Kitware Robot's avatar
Kitware Robot committed
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    case kwsysTerminal_Color_BackgroundBlack:
      fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_BLACK);
      break;
    case kwsysTerminal_Color_BackgroundRed:
      fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_RED);
      break;
    case kwsysTerminal_Color_BackgroundGreen:
      fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_GREEN);
      break;
    case kwsysTerminal_Color_BackgroundYellow:
      fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_YELLOW);
      break;
    case kwsysTerminal_Color_BackgroundBlue:
      fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_BLUE);
      break;
    case kwsysTerminal_Color_BackgroundMagenta:
      fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_MAGENTA);
      break;
    case kwsysTerminal_Color_BackgroundCyan:
      fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_CYAN);
      break;
    case kwsysTerminal_Color_BackgroundWhite:
      fprintf(stream, KWSYS_TERMINAL_VT100_BACKGROUND_WHITE);
      break;
Kitware Robot's avatar
Kitware Robot committed
305 306
  }
  if (color & kwsysTerminal_Color_ForegroundBold) {
Kitware Robot's avatar
Kitware Robot committed
307
    fprintf(stream, KWSYS_TERMINAL_VT100_BOLD);
Kitware Robot's avatar
Kitware Robot committed
308
  }
Kitware Robot's avatar
Kitware Robot committed
309 310 311 312
}

#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)

Kitware Robot's avatar
Kitware Robot committed
313 314 315 316 317 318
#  define KWSYS_TERMINAL_MASK_FOREGROUND                                      \
    (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED |                    \
     FOREGROUND_INTENSITY)
#  define KWSYS_TERMINAL_MASK_BACKGROUND                                      \
    (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED |                    \
     BACKGROUND_INTENSITY)
Kitware Robot's avatar
Kitware Robot committed
319 320 321 322 323 324 325

/* Get the Windows handle for a FILE stream.  */
static HANDLE kwsysTerminalGetStreamHandle(FILE* stream)
{
  /* Get the C-library file descriptor from the stream.  */
  int fd = fileno(stream);

Kitware Robot's avatar
Kitware Robot committed
326
#  if defined(__CYGWIN__)
Kitware Robot's avatar
Kitware Robot committed
327 328 329
  /* Cygwin seems to have an extra pipe level.  If the file descriptor
     corresponds to stdout or stderr then obtain the matching windows
     handle directly.  */
Kitware Robot's avatar
Kitware Robot committed
330
  if (fd == fileno(stdout)) {
Kitware Robot's avatar
Kitware Robot committed
331
    return GetStdHandle(STD_OUTPUT_HANDLE);
Kitware Robot's avatar
Kitware Robot committed
332
  } else if (fd == fileno(stderr)) {
Kitware Robot's avatar
Kitware Robot committed
333
    return GetStdHandle(STD_ERROR_HANDLE);
Kitware Robot's avatar
Kitware Robot committed
334
  }
Kitware Robot's avatar
Kitware Robot committed
335
#  endif
Kitware Robot's avatar
Kitware Robot committed
336 337 338 339 340 341 342 343

  /* Get the underlying Windows handle for the descriptor.  */
  return (HANDLE)_get_osfhandle(fd);
}

/* Set color attributes in a Windows console.  */
static void kwsysTerminalSetConsoleColor(HANDLE hOut,
                                         CONSOLE_SCREEN_BUFFER_INFO* hOutInfo,
Kitware Robot's avatar
Kitware Robot committed
344
                                         FILE* stream, int color)
Kitware Robot's avatar
Kitware Robot committed
345 346
{
  WORD attributes = 0;
Kitware Robot's avatar
Kitware Robot committed
347
  switch (color & kwsysTerminal_Color_ForegroundMask) {
Kitware Robot's avatar
Kitware Robot committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
    case kwsysTerminal_Color_Normal:
      attributes |= hOutInfo->wAttributes & KWSYS_TERMINAL_MASK_FOREGROUND;
      break;
    case kwsysTerminal_Color_ForegroundBlack:
      attributes |= 0;
      break;
    case kwsysTerminal_Color_ForegroundRed:
      attributes |= FOREGROUND_RED;
      break;
    case kwsysTerminal_Color_ForegroundGreen:
      attributes |= FOREGROUND_GREEN;
      break;
    case kwsysTerminal_Color_ForegroundYellow:
      attributes |= FOREGROUND_RED | FOREGROUND_GREEN;
      break;
    case kwsysTerminal_Color_ForegroundBlue:
      attributes |= FOREGROUND_BLUE;
      break;
    case kwsysTerminal_Color_ForegroundMagenta:
      attributes |= FOREGROUND_RED | FOREGROUND_BLUE;
      break;
    case kwsysTerminal_Color_ForegroundCyan:
      attributes |= FOREGROUND_BLUE | FOREGROUND_GREEN;
      break;
    case kwsysTerminal_Color_ForegroundWhite:
      attributes |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
      break;
Kitware Robot's avatar
Kitware Robot committed
375 376
  }
  switch (color & kwsysTerminal_Color_BackgroundMask) {
Kitware Robot's avatar
Kitware Robot committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
    case kwsysTerminal_Color_Normal:
      attributes |= hOutInfo->wAttributes & KWSYS_TERMINAL_MASK_BACKGROUND;
      break;
    case kwsysTerminal_Color_BackgroundBlack:
      attributes |= 0;
      break;
    case kwsysTerminal_Color_BackgroundRed:
      attributes |= BACKGROUND_RED;
      break;
    case kwsysTerminal_Color_BackgroundGreen:
      attributes |= BACKGROUND_GREEN;
      break;
    case kwsysTerminal_Color_BackgroundYellow:
      attributes |= BACKGROUND_RED | BACKGROUND_GREEN;
      break;
    case kwsysTerminal_Color_BackgroundBlue:
      attributes |= BACKGROUND_BLUE;
      break;
    case kwsysTerminal_Color_BackgroundMagenta:
      attributes |= BACKGROUND_RED | BACKGROUND_BLUE;
      break;
    case kwsysTerminal_Color_BackgroundCyan:
      attributes |= BACKGROUND_BLUE | BACKGROUND_GREEN;
      break;
    case kwsysTerminal_Color_BackgroundWhite:
      attributes |= BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
      break;
Kitware Robot's avatar
Kitware Robot committed
404 405
  }
  if (color & kwsysTerminal_Color_ForegroundBold) {
Kitware Robot's avatar
Kitware Robot committed
406
    attributes |= FOREGROUND_INTENSITY;
Kitware Robot's avatar
Kitware Robot committed
407 408
  }
  if (color & kwsysTerminal_Color_BackgroundBold) {
Kitware Robot's avatar
Kitware Robot committed
409
    attributes |= BACKGROUND_INTENSITY;
Kitware Robot's avatar
Kitware Robot committed
410
  }
Kitware Robot's avatar
Kitware Robot committed
411 412 413 414
  fflush(stream);
  SetConsoleTextAttribute(hOut, attributes);
}
#endif