1 /*
2 * Copyright 2015 WebAssembly Community Group participants
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef wasm_support_color_h
18 #define wasm_support_color_h
19
20 #include <iosfwd>
21
22 namespace Colors {
23 void setEnabled(bool enabled);
24 bool isEnabled();
25
26 #if defined(__linux__) || defined(__APPLE__)
27 void outputColorCode(std::ostream& stream, const char* colorCode);
normal(std::ostream & stream)28 inline void normal(std::ostream& stream) { outputColorCode(stream, "\033[0m"); }
red(std::ostream & stream)29 inline void red(std::ostream& stream) { outputColorCode(stream, "\033[31m"); }
magenta(std::ostream & stream)30 inline void magenta(std::ostream& stream) {
31 outputColorCode(stream, "\033[35m");
32 }
orange(std::ostream & stream)33 inline void orange(std::ostream& stream) {
34 outputColorCode(stream, "\033[33m");
35 }
grey(std::ostream & stream)36 inline void grey(std::ostream& stream) { outputColorCode(stream, "\033[37m"); }
green(std::ostream & stream)37 inline void green(std::ostream& stream) { outputColorCode(stream, "\033[32m"); }
blue(std::ostream & stream)38 inline void blue(std::ostream& stream) { outputColorCode(stream, "\033[34m"); }
bold(std::ostream & stream)39 inline void bold(std::ostream& stream) { outputColorCode(stream, "\033[1m"); }
40 #elif defined(_WIN32)
41 void outputColorCode(std::ostream& stream, const unsigned short& colorCode);
normal(std::ostream & stream)42 inline void normal(std::ostream& stream) { outputColorCode(stream, 0x07); }
red(std::ostream & stream)43 inline void red(std::ostream& stream) { outputColorCode(stream, 0x0c); }
magenta(std::ostream & stream)44 inline void magenta(std::ostream& stream) { outputColorCode(stream, 0x05); }
orange(std::ostream & stream)45 inline void orange(std::ostream& stream) { outputColorCode(stream, 0x06); }
grey(std::ostream & stream)46 inline void grey(std::ostream& stream) { outputColorCode(stream, 0x08); }
green(std::ostream & stream)47 inline void green(std::ostream& stream) { outputColorCode(stream, 0x02); }
blue(std::ostream & stream)48 inline void blue(std::ostream& stream) { outputColorCode(stream, 0x09); }
bold(std::ostream & stream)49 inline void bold(std::ostream& stream) { /* Do nothing */
50 }
51 #else
normal(std::ostream & stream)52 inline void normal(std::ostream& stream) {}
red(std::ostream & stream)53 inline void red(std::ostream& stream) {}
magenta(std::ostream & stream)54 inline void magenta(std::ostream& stream) {}
orange(std::ostream & stream)55 inline void orange(std::ostream& stream) {}
grey(std::ostream & stream)56 inline void grey(std::ostream& stream) {}
green(std::ostream & stream)57 inline void green(std::ostream& stream) {}
blue(std::ostream & stream)58 inline void blue(std::ostream& stream) {}
bold(std::ostream & stream)59 inline void bold(std::ostream& stream) {}
60 #endif
61 } // namespace Colors
62
63 #endif // wasm_support_color_h
64