Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/wabt/color.h
1 /* 2 * Copyright 2017 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 WABT_COLOR_H_ 18 #define WABT_COLOR_H_ 19 20 #include <cstdio> 21 22 namespace wabt { 23 24 #define WABT_FOREACH_COLOR_CODE(V) \ 25 V(Default, "\x1b[0m") \ 26 V(Bold, "\x1b[1m") \ 27 V(NoBold, "\x1b[22m") \ 28 V(Black, "\x1b[30m") \ 29 V(Red, "\x1b[31m") \ 30 V(Green, "\x1b[32m") \ 31 V(Yellow, "\x1b[33m") \ 32 V(Blue, "\x1b[34m") \ 33 V(Magenta, "\x1b[35m") \ 34 V(Cyan, "\x1b[36m") \ 35 V(White, "\x1b[37m") 36 37 class Color { 38 public: 39 Color() : file_(nullptr), enabled_(false) {} 40 Color(FILE*, bool enabled = true); 41 42 // Write the given color to the file, if enabled. 43 #define WABT_COLOR(Name, code) \ 44 void Name() const { WriteCode(Name##Code()); } 45 WABT_FOREACH_COLOR_CODE(WABT_COLOR) 46 #undef WABT_COLOR 47 48 // Get the color code as a string, if enabled. 49 #define WABT_COLOR(Name, code) \ 50 const char* Maybe##Name##Code() const { return enabled_ ? Name##Code() : ""; } 51 WABT_FOREACH_COLOR_CODE(WABT_COLOR) 52 #undef WABT_COLOR 53 54 // Get the color code as a string. 55 #define WABT_COLOR(Name, code) \ 56 static const char* Name##Code() { return code; } 57 WABT_FOREACH_COLOR_CODE(WABT_COLOR) 58 #undef WABT_COLOR 59 60 private: 61 static bool SupportsColor(FILE*); 62 void WriteCode(const char*) const; 63 64 FILE* file_; 65 bool enabled_; 66 }; 67 68 #undef WABT_FOREACH_COLOR_CODE 69 70 } // namespace wabt 71 72 #endif // WABT_COLOR_H_