File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
3
- #include < concepts>
3
+ #include " ../TermColor.hpp"
4
+
4
5
#include < exception>
5
6
#include < fmt/core.h>
6
7
#include < memory>
7
8
#include < mitama/anyhow/anyhow.hpp>
8
9
#include < mitama/result/result.hpp>
9
10
#include < string>
11
+ #include < string_view>
10
12
#include < type_traits>
11
13
#include < utility>
12
14
@@ -57,16 +59,29 @@ namespace toml {
57
59
template <typename T, typename ... U>
58
60
inline Result<T>
59
61
try_find (const toml::value& v, const U&... u) noexcept {
60
- using namespace std ::string_view_literals; // NOLINT
62
+ using std::string_view_literals::operator " " sv;
63
+
64
+ if (cabin::shouldColorStderr ()) {
65
+ color::enable ();
66
+ } else {
67
+ color::disable ();
68
+ }
61
69
62
70
try {
63
71
return Ok (toml::find<T>(v, u...));
64
72
} catch (const std::exception& e) {
65
73
std::string what = e.what ();
66
- // TODO: make the same fix on upstream
67
- if (what.starts_with (" [error] " )) {
68
- what = what.substr (" [error] " sv.size ());
74
+
75
+ static constexpr std::size_t errorPrefixSize = " [error] " sv.size ();
76
+ static constexpr std::size_t colorErrorPrefixSize =
77
+ " \033 [31m\033 [01m[error]\033 [00m " sv.size ();
78
+
79
+ if (cabin::shouldColorStderr ()) {
80
+ what = what.substr (colorErrorPrefixSize);
81
+ } else {
82
+ what = what.substr (errorPrefixSize);
69
83
}
84
+
70
85
if (what.back () == ' \n ' ) {
71
86
what.pop_back (); // remove the last '\n' since logger::error adds one.
72
87
}
You can’t perform that action at this time.
0 commit comments