@@ -27,43 +27,63 @@ struct SC_COMPILER_EXPORT Console
2727 // / @param conversionBuffer The optional buffer used for UTF conversions
2828 Console (Span<char > conversionBuffer = {});
2929
30- // / @brief Prints a formatted string using SC::StringFormat
31- // / @tparam Types Types of `args`
32- // / @param fmt Format string
33- // / @param args Arguments to be formatted in the string
30+ // / @brief Prints a formatted string using SC::StringFormat to stdout
3431 // / @return `true` if message has been printed successfully to Console
3532 template <typename ... Types>
3633 bool print (StringSpan fmt, Types&&... args)
3734 {
38- StringFormatOutput output (fmt.getEncoding (), *this );
39- if (fmt.getEncoding () == StringEncoding::Ascii || fmt.getEncoding () == StringEncoding::Utf8)
40- {
41- // It's ok parsing format string '{' and '}' both for utf8 and ascii with StringIteratorASCII
42- // because on a valid UTF8 string, these chars are unambiguously recognizable
43- return StringFormat<StringIteratorASCII>::format (output, fmt, forward<Types>(args)...);
44- }
45- return false ; // UTF16/32 format strings are not supported
35+ return printInternal (true , fmt, forward<Types>(args)...);
4636 }
4737
48- // / @brief Prints a StringSpan to console
49- // / @param str The StringSpan to print
38+ // / @brief Prints a formatted string using SC::StringFormat to stderr
39+ // / @return `true` if message has been printed successfully to Console
40+ template <typename ... Types>
41+ bool printError (StringSpan fmt, Types&&... args)
42+ {
43+ return printInternal (false , fmt, forward<Types>(args)...);
44+ }
45+
46+ // / @brief Prints a string to console
5047 void print (const StringSpan str);
5148
52- // / @brief Prints a StringSpan to console and adds a newline at the end of it
53- // / @param str The StringSpan to print
54- void printLine (const StringSpan str);
49+ // / @brief Prints a string to stderr
50+ void printError (const StringSpan str);
5551
56- // / @brief Flushes the console output buffer
52+ // / @brief Flushes stdout
5753 void flush ();
5854
55+ // / @brief Flushes stderr
56+ void flushStdErr ();
57+
58+ // / @brief Prints a string to stdout and adds a newline at the end of it
59+ void printLine (const StringSpan str);
60+
61+ // / @brief Prints a string to stderr and adds a newline at the end of it
62+ void printErrorLine (const StringSpan str);
63+
5964 // / @brief Tries attaching current process to parent console (Windows only, has no effect elsewhere)
6065 // / @returns `true` if the parent console has been attached (Windows only, returns true elsewhere)
6166 static bool tryAttachingToParentConsole ();
6267
6368 private:
69+ template <typename ... Types>
70+ bool printInternal (bool useStdOut, StringSpan fmt, Types&&... args)
71+ {
72+ StringFormatOutput output (fmt.getEncoding (), *this , useStdOut);
73+ if (fmt.getEncoding () == StringEncoding::Ascii || fmt.getEncoding () == StringEncoding::Utf8)
74+ {
75+ // It's ok parsing format string '{' and '}' both for utf8 and ascii with StringIteratorASCII
76+ // because on a valid UTF8 string, these chars are unambiguously recognizable
77+ return StringFormat<StringIteratorASCII>::format (output, fmt, forward<Types>(args)...);
78+ }
79+ return false ; // UTF16/32 format strings are not supported
80+ }
6481 Span<char > conversionBuffer;
6582#if SC_PLATFORM_WINDOWS
66- void * handle;
83+ void printWindows (const StringSpan str, void * handle);
84+
85+ void * hStdOut;
86+ void * hStdErr;
6787 bool isConsole = true ;
6888 bool isDebugger = true ;
6989#endif
0 commit comments