0

This is the source.cpp

#include "color.hpp"
#include<conio.h>
int main()
{
    std::cout << std::endl
              << color::style::reset << color::bg::green << color::fg::gray
              << "If you're seeing green bg, then color works!"
              << color::style::reset << std::endl;
    _getch();
    return 0;
}

And this is the code snippet from color.hpp :

template <typename T>
using enable = typename std::enable_if
    <
        std::is_same<T, color::style>::value ||
        std::is_same<T, color::fg>::value ||
        std::is_same<T, color::bg>::value ||
        std::is_same<T, color::fgB>::value ||
        std::is_same<T, color::bgB>::value,
        std::ostream &
    >::type;

template <typename T>
inline enable<T> operator<<(std::ostream &os, T const value)
{
    std::streambuf const *osbuf = os.rdbuf();
    return ((supportsColor()) && (isTerminal(osbuf)))
               ? os << "\033[" << static_cast<int>(value) << "m"
               : os;
}
}

Actually this is a header only library for making colorful console. I tried to compile this project as a console application with C++11 support but the output is unexpected. What do the output suggest?

Cœur
  • 37,241
  • 25
  • 195
  • 267
dlpsankhla
  • 132
  • 1
  • 2
  • 9

1 Answers1

2

The output suggests that color.hpp depends on a terminal which is interpreting special "escape" output code, but your terminal does not interpret these codes.

This isn't standard C++, BTW.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • @dlpsankhla C++ has no concept of what kind of terminal you have and how it might interpret your output. An equivalent ananogy would be opening a spreadsheet file with a text editor. You can see the data but the text editor doesn't interpret the data and display it as rows and columns. You may be looking for http://stackoverflow.com/questions/16755142/how-to-make-win32-console-recognize-ansi-vt100-escape-sequences or http://stackoverflow.com/questions/2294281/how-to-recognize-ansi-color-escape-codes-in-windows7-64-bit-command-terminal – Jerry Jeremiah Jun 22 '16 at 04:33
  • @dlpsankhla If you are using Windows 10 then there is built in support. Check this one out as well: http://www.nivot.org/blog/post/2016/02/04/Windows-10-TH2-%28v1511%29-Console-Host-Enhancements – Jerry Jeremiah Jun 22 '16 at 04:39