Colorizer.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2013 The Android Open Source Project
  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. #ifndef ANDROID_SURFACE_FLINGER_COLORIZER_H
  17. #define ANDROID_SURFACE_FLINGER_COLORIZER_H
  18. namespace android {
  19. // ---------------------------------------------------------------------------
  20. class Colorizer {
  21. bool mEnabled;
  22. public:
  23. enum color {
  24. RED = 31,
  25. GREEN = 32,
  26. YELLOW = 33,
  27. BLUE = 34,
  28. MAGENTA = 35,
  29. CYAN = 36,
  30. WHITE = 37
  31. };
  32. Colorizer(bool enabled)
  33. : mEnabled(enabled) {
  34. }
  35. void colorize(String8& out, color c) {
  36. if (mEnabled) {
  37. out.appendFormat("\e[%dm", c);
  38. }
  39. }
  40. void bold(String8& out) {
  41. if (mEnabled) {
  42. out.append("\e[1m");
  43. }
  44. }
  45. void reset(String8& out) {
  46. if (mEnabled) {
  47. out.append("\e[0m");
  48. }
  49. }
  50. };
  51. // ---------------------------------------------------------------------------
  52. }; // namespace android
  53. #endif /* ANDROID_SURFACE_FLINGER_COLORIZER_H */