+namespace
+{
+ inline bool CanUseColors()
+ {
+#ifdef INSPIRCD_DISABLE_COLORS
+ return false;
+#else
+ return isatty(fileno(stdout));
+#endif
+ }
+
+#ifdef _WIN32
+ inline WindowsStream& GetStreamHandle(std::ostream& os)
+ {
+ if (os.rdbuf() == std::cerr.rdbuf())
+ return StandardError;
+
+ if (os.rdbuf() == std::cout.rdbuf())
+ return StandardOutput;
+
+ // This will never happen.
+ throw std::invalid_argument("Tried to write color codes to a stream other than stdout or stderr!");
+ }
+#endif
+}
+
+#ifdef _WIN32