0031036: Foundation Classes, Message_PrinterOStream - add option printing colored...
[occt.git] / src / Message / Message_PrinterOStream.hxx
index dc008a0..ca10fdd 100644 (file)
 #ifndef _Message_PrinterOStream_HeaderFile
 #define _Message_PrinterOStream_HeaderFile
 
-#include <Standard.hxx>
-#include <Standard_Type.hxx>
-
-#include <Standard_Address.hxx>
-#include <Standard_Boolean.hxx>
+#include <Message_ConsoleColor.hxx>
 #include <Message_Printer.hxx>
-#include <Message_Gravity.hxx>
-#include <Standard_CString.hxx>
+#include <Standard_Address.hxx>
 #include <Standard_OStream.hxx>
-class TCollection_AsciiString;
-class TCollection_ExtendedString;
-
 
 class Message_PrinterOStream;
 DEFINE_STANDARD_HANDLE(Message_PrinterOStream, Message_Printer)
 
-//! Implementation of a message printer associated with an ostream
-//! The ostream may be either externally defined one (e.g. cout),
+//! Implementation of a message printer associated with an std::ostream
+//! The std::ostream may be either externally defined one (e.g. std::cout),
 //! or file stream maintained internally (depending on constructor).
 class Message_PrinterOStream : public Message_Printer
 {
-
+  DEFINE_STANDARD_RTTIEXT(Message_PrinterOStream, Message_Printer)
 public:
 
+  //! Setup console text color.
+  //!
+  //! On Windows, this would affect active terminal color output.
+  //! On other systems, this would put special terminal codes;
+  //! the terminal should support these codes or them will appear in text otherwise.
+  //! The same will happen when stream is redirected into text file.
+  //!
+  //! Beware that within multi-threaded environment inducing console colors
+  //! might lead to colored text mixture due to concurrency.
+  Standard_EXPORT static void SetConsoleTextColor (Standard_OStream* theOStream,
+                                                   Message_ConsoleColor theTextColor,
+                                                   bool theIsIntenseText = false);
+
+public:
   
   //! Empty constructor, defaulting to cout
   Standard_EXPORT Message_PrinterOStream(const Message_Gravity theTraceLevel = Message_Info);
@@ -58,16 +64,22 @@ public:
 {
   Close();
 }
-  
+
   //! Returns option to convert non-Ascii symbols to UTF8 encoding
-    Standard_Boolean GetUseUtf8() const;
+  Standard_Boolean GetUseUtf8() const { return myUseUtf8; }
   
   //! Sets option to convert non-Ascii symbols to UTF8 encoding
-    void SetUseUtf8 (const Standard_Boolean useUtf8);
-  
+  void SetUseUtf8 (const Standard_Boolean useUtf8) { myUseUtf8 = useUtf8; }
+
   //! Returns reference to the output stream
-    Standard_OStream& GetStream() const;
-  
+  Standard_OStream& GetStream() const { return *(Standard_OStream*)myStream; }
+
+  //! Returns TRUE if text output into console should be colorized depending on message gravity.
+  Standard_Boolean ToColorize() const { return myToColorize; }
+
+  //! Set if text output into console should be colorized depending on message gravity.
+  void SetToColorize (Standard_Boolean theToColorize) { myToColorize = theToColorize; }
+
   //! Puts a message to the current stream
   //! if its gravity is equal or greater
   //! to the trace level set by SetTraceLevel()
@@ -85,30 +97,13 @@ public:
   //! option is set, else replaced by symbols '?'
   Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
 
-
-
-  DEFINE_STANDARD_RTTI(Message_PrinterOStream,Message_Printer)
-
-protected:
-
-
-
-
 private:
 
-
   Standard_Address myStream;
   Standard_Boolean myIsFile;
   Standard_Boolean myUseUtf8;
-
+  Standard_Boolean myToColorize;
 
 };
 
-
-#include <Message_PrinterOStream.lxx>
-
-
-
-
-
 #endif // _Message_PrinterOStream_HeaderFile