CBMC
console.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Console
4 
5 Author: Daniel Kroening, dkr@amazon.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_UTIL_CONSOLE_H
13 #define CPROVER_UTIL_CONSOLE_H
14 
15 #include <cstddef> // IWYU pragma: keep
16 #include <iosfwd>
17 
18 class consolet
19 {
20 public:
21  static void init();
22 
23  // colors
24  static std::ostream &blue(std::ostream &);
25  static std::ostream &cyan(std::ostream &);
26  static std::ostream &green(std::ostream &);
27  static std::ostream &red(std::ostream &);
28  static std::ostream &yellow(std::ostream &);
29  static std::ostream &orange(std::ostream &);
30 
31  static std::ostream &bold(std::ostream &);
32  static std::ostream &faint(std::ostream &);
33  static std::ostream &underline(std::ostream &);
34 
35  static std::ostream &reset(std::ostream &);
36 
37  // cursor movement
38  static std::ostream &cursorup(std::ostream &);
39 
40  // deletion
41  static std::ostream &cleareol(std::ostream &); // erase to end of line
42 
43  static bool is_terminal()
44  {
45  init();
46  return _is_terminal;
47  }
48 
49  static bool use_SGR()
50  {
51  init();
52  return _use_SGR;
53  }
54 
55  static std::ostream &out()
56  {
57  init();
58  return *_out;
59  }
60 
61  static std::ostream &err()
62  {
63  init();
64  return *_err;
65  }
66 
67  static std::size_t width();
68 
69  // redirection
70  class redirectt
71  {
72  public:
73  // __out has some meaning on Windows, therefore using __console_out
74  redirectt(std::ostream &__console_out, std::ostream &__console_err);
75  ~redirectt();
76 
77  protected:
78  std::ostream *old_out = nullptr, *old_err = nullptr;
79  bool old_is_terminal = false;
80  };
81 
82 protected:
83  static bool _is_terminal;
84  static bool _use_SGR;
85  static bool _init_done;
86  static std::size_t _width;
87  static bool _width_is_set;
88  static std::ostream *_out;
89  static std::ostream *_err;
90 };
91 
92 #endif // CPROVER_UTIL_CONSOLE_H
std::ostream * old_out
Definition: console.h:78
redirectt(std::ostream &__console_out, std::ostream &__console_err)
Definition: console.cpp:229
std::ostream * old_err
Definition: console.h:78
bool old_is_terminal
Definition: console.h:79
static std::size_t _width
Definition: console.h:86
static bool use_SGR()
Definition: console.h:49
static void init()
Definition: console.cpp:73
static std::ostream & cursorup(std::ostream &)
Definition: console.cpp:184
static std::ostream & yellow(std::ostream &)
Definition: console.cpp:136
static bool _init_done
Definition: console.h:85
static bool _is_terminal
Definition: console.h:83
static std::ostream * _err
Definition: console.h:89
static std::ostream & blue(std::ostream &)
Definition: console.cpp:104
static std::ostream & underline(std::ostream &)
Definition: console.cpp:168
static std::ostream * _out
Definition: console.h:88
static std::ostream & reset(std::ostream &)
Definition: console.cpp:176
static std::ostream & cyan(std::ostream &)
Definition: console.cpp:112
static std::ostream & green(std::ostream &)
Definition: console.cpp:120
static std::size_t width()
Definition: console.cpp:196
static bool is_terminal()
Definition: console.h:43
static std::ostream & faint(std::ostream &)
Definition: console.cpp:160
static std::ostream & bold(std::ostream &)
Definition: console.cpp:152
static std::ostream & red(std::ostream &)
Definition: console.cpp:128
static std::ostream & err()
Definition: console.h:61
static bool _use_SGR
Definition: console.h:84
static bool _width_is_set
Definition: console.h:87
static std::ostream & orange(std::ostream &)
Definition: console.cpp:144
static std::ostream & cleareol(std::ostream &)
Definition: console.cpp:190
static std::ostream & out()
Definition: console.h:55