Skip to content

Commit d28f18c

Browse files
committed
Use the ansi_codes library in cuttlefish/result
Bug: b/528061247
1 parent 23de9d8 commit d28f18c

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

base/cvd/cuttlefish/result/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ cf_cc_library(
99
srcs = ["error_type.cc"],
1010
hdrs = ["error_type.h"],
1111
deps = [
12+
"//cuttlefish/ansi_codes",
1213
"//libbase",
1314
"@abseil-cpp//absl/log",
15+
"@abseil-cpp//absl/strings",
1416
"@fmt",
1517
],
1618
)

base/cvd/cuttlefish/result/error_type.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
#include <utility>
2525
#include <vector>
2626

27+
#include "absl/strings/str_cat.h"
2728
#include "fmt/base.h"
2829

30+
#include "cuttlefish/ansi_codes/ansi_codes.h"
31+
2932
namespace cuttlefish {
3033

3134
StackTraceEntry::StackTraceEntry(std::string file, size_t line,
@@ -75,8 +78,6 @@ bool StackTraceEntry::HasMessage() const { return !message_.str().empty(); }
7578
fmt::format_context::iterator StackTraceEntry::format(
7679
fmt::format_context& ctx, const std::vector<FormatSpecifier>& specifiers,
7780
std::optional<int> index) const {
78-
static constexpr char kTerminalBoldRed[] = "\033[0;1;31m";
79-
static constexpr char kTerminalReset[] = "\033[0m";
8081
auto out = ctx.out();
8182
std::vector<FormatSpecifier> filtered_specs;
8283
bool arrow = false;
@@ -149,8 +150,8 @@ fmt::format_context::iterator StackTraceEntry::format(
149150
break;
150151
case FormatSpecifier::kMessage:
151152
if (color) {
152-
out = fmt::format_to(out, "{}{}{}", kTerminalBoldRed, message_.str(),
153-
kTerminalReset);
153+
out = fmt::format_to(out, "{}{}{}", kAnsiRed, message_.str(),
154+
kAnsiReset);
154155
} else {
155156
out = fmt::format_to(out, "{}", message_.str());
156157
}
@@ -164,7 +165,7 @@ fmt::format_context::iterator StackTraceEntry::format(
164165
file_.substr(last_slash == std::string::npos ? 0 : last_slash + 1);
165166
std::string last;
166167
if (HasMessage()) {
167-
last = color ? kTerminalBoldRed + message_.str() + kTerminalReset
168+
last = color ? absl::StrCat(kAnsiRed, message_.str(), kAnsiReset)
168169
: message_.str();
169170
}
170171
if (color) {

0 commit comments

Comments
 (0)