ChainCLI
A modern C++20 command-line interface library
Loading...
Searching...
No Matches
logstyle.h
1/*
2 * Copyright 2025 Dominik Czekai
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#pragma once
18#include <map>
19#include <string>
20
21#include "loglevel.h"
22
23#if defined(_MSC_VER)
24constexpr const std::string ESC = "\x1B";
25#else
26constexpr const std::string ESC = "\033";
27#endif
28
29namespace cli::logging
30{
31
32// contains ANSI escape codes for styling log messages
33using LogStyleMap = std::map<LogLevel, std::string>;
34
35// Default console styles
36inline LogStyleMap defaultStyles()
37{
38 using enum cli::logging::LogLevel;
39 return {
40 {TRACE, ESC + "[90m"}, // gray
41 {VERBOSE, ESC + "[90m"}, // gray
42 {DEBUG, ESC + "[36m"}, // cyan
43 // Info uses plain grey text (no color)
44 {SUCCESS, ESC + "[32m"}, // green
45 {WARNING, ESC + "[33m"}, // yellow
46 {ERROR, ESC + "[31m"}, // red
47 };
48}
49} // namespace cli::logging