scenario_simulator_v2 C++ API
escape_sequence.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef OPENSCENARIO_INTERPRETER__CONSOLE__ESCAPE_SEQUENCE_HPP_
16 #define OPENSCENARIO_INTERPRETER__CONSOLE__ESCAPE_SEQUENCE_HPP_
17 
19 #include <string>
20 
22 {
23 inline namespace console
24 {
25 template <typename... Ts>
26 auto & escape_sequence(std::basic_ostream<Ts...> & os, const std::string & code)
27 {
28  return is_console(os) ? (os << "\x1b" << code) : os;
29 }
30 
31 #define BOILERPLATE(CODE, NAME) \
32  inline auto NAME = [](std::ostream & os) -> decltype(auto) { return escape_sequence(os, CODE); }
33 
35 BOILERPLATE("[1m", bold);
37 BOILERPLATE("[3m", italic); // Not widely supported. Sometimes treated as inverse.
39 BOILERPLATE("[5m", slow_blink); // Less than 150 per minute.
40 BOILERPLATE("[6m", rapid_blink); // More than 150 per minute. Not widely supported.
42 BOILERPLATE("[8m", conceal); // Not widely supported.
43 
44 inline namespace foreground
45 {
46 BOILERPLATE("[30m", black);
47 BOILERPLATE("[31m", red);
48 BOILERPLATE("[32m", green);
50 BOILERPLATE("[34m", blue);
52 BOILERPLATE("[36m", cyan);
53 BOILERPLATE("[37m", white);
54 } // namespace foreground
55 
56 namespace background
57 {
58 BOILERPLATE("[40m", black);
59 BOILERPLATE("[41m", red);
60 BOILERPLATE("[42m", green);
62 BOILERPLATE("[44m", blue);
64 BOILERPLATE("[46m", cyan);
65 BOILERPLATE("[47m", white);
66 } // namespace background
67 
68 #undef BOILERPLATE
69 } // namespace console
70 } // namespace openscenario_interpreter
71 
72 #endif // OPENSCENARIO_INTERPRETER__CONSOLE__ESCAPE_SEQUENCE_HPP_
#define BOILERPLATE(CODE, NAME)
Definition: escape_sequence.hpp:31
auto white
Definition: escape_sequence.hpp:65
auto red
Definition: escape_sequence.hpp:59
auto green
Definition: escape_sequence.hpp:60
auto yellow
Definition: escape_sequence.hpp:61
auto cyan
Definition: escape_sequence.hpp:64
auto blue
Definition: escape_sequence.hpp:62
auto magenta
Definition: escape_sequence.hpp:63
auto black
Definition: escape_sequence.hpp:58
auto blue
Definition: escape_sequence.hpp:50
auto yellow
Definition: escape_sequence.hpp:49
auto red
Definition: escape_sequence.hpp:47
auto magenta
Definition: escape_sequence.hpp:51
auto black
Definition: escape_sequence.hpp:46
auto green
Definition: escape_sequence.hpp:48
auto cyan
Definition: escape_sequence.hpp:52
auto white
Definition: escape_sequence.hpp:53
auto slow_blink
Definition: escape_sequence.hpp:39
auto rapid_blink
Definition: escape_sequence.hpp:40
auto reset
Definition: escape_sequence.hpp:34
auto underline
Definition: escape_sequence.hpp:38
auto conceal
Definition: escape_sequence.hpp:42
auto & escape_sequence(std::basic_ostream< Ts... > &os, const std::string &code)
Definition: escape_sequence.hpp:26
auto faint
Definition: escape_sequence.hpp:36
auto italic
Definition: escape_sequence.hpp:37
auto bold
Definition: escape_sequence.hpp:35
auto reverse
Definition: escape_sequence.hpp:41
auto is_console
Definition: is_console.hpp:26
Definition: escape_sequence.hpp:22
std::string string
Definition: junit5.hpp:26