158f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//===-- sanitizer_report_decorator.h ----------------------------*- C++ -*-===//
258f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//
358f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//                     The LLVM Compiler Infrastructure
458f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//
558f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany// This file is distributed under the University of Illinois Open Source
658f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany// License. See LICENSE.TXT for details.
758f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//
858f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//===----------------------------------------------------------------------===//
958f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//
1058f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany// Tags to decorate the sanitizer reports.
1158f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany// Currently supported tags:
1258f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//   * None.
1358f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//   * ANSI color sequences.
1458f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//
1558f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany//===----------------------------------------------------------------------===//
1658f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany
178f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov#ifndef SANITIZER_REPORT_DECORATOR_H
188f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov#define SANITIZER_REPORT_DECORATOR_H
1958f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany
202d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#include "sanitizer_common.h"
212d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
2258f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryanynamespace __sanitizer {
235d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hinesclass SanitizerCommonDecorator {
2413f5be4dd1d8bf6a44d8d976325f1c6f26fa9f7fTimur Iskhodzhanov  // FIXME: This is not portable. It assumes the special strings are printed to
2513f5be4dd1d8bf6a44d8d976325f1c6f26fa9f7fTimur Iskhodzhanov  // stdout, which is not the case on Windows (see SetConsoleTextAttribute()).
2658f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany public:
275d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines  SanitizerCommonDecorator() : ansi_(ColorizeReports()) {}
288f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov  const char *Bold()    const { return ansi_ ? "\033[1m" : ""; }
295d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines  const char *Default() const { return ansi_ ? "\033[1m\033[0m"  : ""; }
305d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines  const char *Warning()    { return Red(); }
315d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines  const char *EndWarning() { return Default(); }
325d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines protected:
338f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov  const char *Black()   const { return ansi_ ? "\033[1m\033[30m" : ""; }
348f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov  const char *Red()     const { return ansi_ ? "\033[1m\033[31m" : ""; }
358f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov  const char *Green()   const { return ansi_ ? "\033[1m\033[32m" : ""; }
368f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov  const char *Yellow()  const { return ansi_ ? "\033[1m\033[33m" : ""; }
378f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov  const char *Blue()    const { return ansi_ ? "\033[1m\033[34m" : ""; }
388f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov  const char *Magenta() const { return ansi_ ? "\033[1m\033[35m" : ""; }
398f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov  const char *Cyan()    const { return ansi_ ? "\033[1m\033[36m" : ""; }
408f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov  const char *White()   const { return ansi_ ? "\033[1m\033[37m" : ""; }
4158f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany private:
4258f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany  bool ansi_;
4358f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany};
442d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
4558f54555c2528f863e211a0679c2c423cfa55fb2Kostya Serebryany}  // namespace __sanitizer
468f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov
478f72f7cae84494d9bd0676b4a499e0f895460744Alexey Samsonov#endif  // SANITIZER_REPORT_DECORATOR_H
48