Skip to content

Commit 4aab9b4

Browse files
committed
Move the TerminalColors type to ansi_codes
This places it closer to related code. Bug: b/507940443
1 parent 7cc8973 commit 4aab9b4

10 files changed

Lines changed: 90 additions & 35 deletions

File tree

base/cvd/cuttlefish/ansi_codes/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ cf_cc_library(
1212
"@abseil-cpp//absl/strings",
1313
],
1414
)
15+
16+
cf_cc_library(
17+
name = "terminal_colors",
18+
srcs = ["terminal_colors.cc"],
19+
hdrs = ["terminal_colors.h"],
20+
deps = [
21+
"//cuttlefish/ansi_codes",
22+
],
23+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2022 The Android Open Source Project
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+
#include "cuttlefish/ansi_codes/terminal_colors.h"
18+
19+
#include <string_view>
20+
21+
#include "cuttlefish/ansi_codes/ansi_codes.h"
22+
23+
namespace cuttlefish {
24+
25+
std::string_view TerminalColors::Reset() const {
26+
return is_tty_ ? kAnsiReset : "";
27+
}
28+
29+
std::string_view TerminalColors::BoldRed() const {
30+
return is_tty_ ? kAnsiRed : "";
31+
}
32+
33+
std::string_view TerminalColors::Red() const { return is_tty_ ? kAnsiRed : ""; }
34+
35+
std::string_view TerminalColors::Cyan() const {
36+
return is_tty_ ? kAnsiCyan : "";
37+
}
38+
39+
} // namespace cuttlefish
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2022 The Android Open Source Project
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+
19+
#include <string_view>
20+
21+
namespace cuttlefish {
22+
23+
class TerminalColors {
24+
public:
25+
TerminalColors(bool is_tty) : is_tty_(is_tty) {}
26+
std::string_view Reset() const;
27+
std::string_view BoldRed() const;
28+
std::string_view Red() const;
29+
std::string_view Cyan() const;
30+
31+
private:
32+
bool is_tty_;
33+
};
34+
35+
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/cvd/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ cf_cc_binary(
3030
srcs = ["main.cc"],
3131
deps = [
3232
":libcvd",
33+
"//cuttlefish/ansi_codes:terminal_colors",
3334
"//cuttlefish/common/libs/utils:environment",
3435
"//cuttlefish/common/libs/utils:files",
3536
"//cuttlefish/common/libs/utils:subprocess",
3637
"//cuttlefish/common/libs/utils:tee_logging",
3738
"//cuttlefish/flag_parser",
3839
"//cuttlefish/host/commands/cvd/cli:log_files",
39-
"//cuttlefish/host/commands/cvd/cli:utils",
40-
"//cuttlefish/host/commands/cvd/utils",
40+
"//cuttlefish/host/commands/cvd/utils:common",
4141
"//cuttlefish/host/commands/cvd/version",
4242
"//cuttlefish/host/libs/vm_manager",
4343
"//cuttlefish/posix:strerror",

base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ cf_cc_library(
180180
deps = [
181181
":command_request",
182182
":types",
183-
"//cuttlefish/ansi_codes",
183+
"//cuttlefish/ansi_codes:terminal_colors",
184184
"//cuttlefish/common/libs/fs",
185185
"//cuttlefish/common/libs/utils:contains",
186186
"//cuttlefish/common/libs/utils:files",

base/cvd/cuttlefish/host/commands/cvd/cli/selector/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ cf_cc_library(
6565
srcs = ["selector.cpp"],
6666
hdrs = ["selector.h"],
6767
deps = [
68+
"//cuttlefish/ansi_codes:terminal_colors",
6869
"//cuttlefish/common/libs/utils:users",
6970
"//cuttlefish/host/commands/cvd/cli:command_request",
7071
"//cuttlefish/host/commands/cvd/cli:interruptible_terminal",
71-
"//cuttlefish/host/commands/cvd/cli:utils",
7272
"//cuttlefish/host/commands/cvd/instances",
7373
"//cuttlefish/host/commands/cvd/instances:instance_manager",
7474
"//cuttlefish/result",

base/cvd/cuttlefish/host/commands/cvd/cli/selector/selector.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
#include <utility>
2525
#include <vector>
2626

27-
#include "absl/strings/ascii.h"
2827
#include "absl/strings/numbers.h"
2928

29+
#include "cuttlefish/ansi_codes/terminal_colors.h"
3030
#include "cuttlefish/host/commands/cvd/cli/command_request.h"
3131
#include "cuttlefish/host/commands/cvd/cli/interruptible_terminal.h"
32-
#include "cuttlefish/host/commands/cvd/cli/utils.h"
3332
#include "cuttlefish/host/commands/cvd/instances/local_instance.h"
3433
#include "cuttlefish/host/commands/cvd/instances/local_instance_group.h"
3534
#include "cuttlefish/host/commands/cvd/instances/status_fetcher.h"

base/cvd/cuttlefish/host/commands/cvd/cli/utils.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "fmt/format.h"
3434
#include "fmt/ranges.h" // NOLINT(misc-include-cleaner): version difference
3535

36-
#include "cuttlefish/ansi_codes/ansi_codes.h"
36+
#include "cuttlefish/ansi_codes/terminal_colors.h"
3737
#include "cuttlefish/common/libs/fs/shared_fd.h"
3838
#include "cuttlefish/common/libs/utils/contains.h"
3939
#include "cuttlefish/common/libs/utils/files.h"
@@ -244,20 +244,6 @@ Result<std::vector<Flag>> GetSiblingCommandFlags(const std::string& bin_name,
244244
return flags;
245245
}
246246

247-
std::string_view TerminalColors::Reset() const {
248-
return is_tty_ ? kAnsiReset : "";
249-
}
250-
251-
std::string_view TerminalColors::BoldRed() const {
252-
return is_tty_ ? kAnsiRed : "";
253-
}
254-
255-
std::string_view TerminalColors::Red() const { return is_tty_ ? kAnsiRed : ""; }
256-
257-
std::string_view TerminalColors::Cyan() const {
258-
return is_tty_ ? kAnsiCyan : "";
259-
}
260-
261247
std::string NoGroupMessage(const CommandRequest& request) {
262248
TerminalColors colors(isatty(1));
263249
return fmt::format("{}Command `{}{}{}{}` is not applicable: {}{}{}",

base/cvd/cuttlefish/host/commands/cvd/cli/utils.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <signal.h>
2020

2121
#include <string>
22-
#include <string_view>
2322
#include <vector>
2423

2524
#include "cuttlefish/common/libs/utils/subprocess.h"
@@ -85,18 +84,6 @@ struct TerminalSize {
8584
};
8685
Result<TerminalSize> GetTerminalSize();
8786

88-
class TerminalColors {
89-
public:
90-
TerminalColors(bool is_tty) : is_tty_(is_tty) {}
91-
std::string_view Reset() const;
92-
std::string_view BoldRed() const;
93-
std::string_view Red() const;
94-
std::string_view Cyan() const;
95-
96-
private:
97-
bool is_tty_;
98-
};
99-
10087
std::vector<std::string> ExpandProductPaths(const std::string& product_path,
10188
size_t num_instances);
10289

base/cvd/cuttlefish/host/commands/cvd/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
#include "android-base/file.h"
3333
#include "fmt/format.h"
3434

35+
#include "cuttlefish/ansi_codes/terminal_colors.h"
3536
#include "cuttlefish/common/libs/utils/environment.h"
3637
#include "cuttlefish/common/libs/utils/files.h"
3738
#include "cuttlefish/common/libs/utils/subprocess.h"
3839
#include "cuttlefish/common/libs/utils/tee_logging.h"
3940
#include "cuttlefish/flag_parser/flag.h"
4041
#include "cuttlefish/flag_parser/gflags_compat.h"
4142
#include "cuttlefish/host/commands/cvd/cli/log_files.h"
42-
#include "cuttlefish/host/commands/cvd/cli/utils.h"
4343
#include "cuttlefish/host/commands/cvd/cvd.h"
4444
#include "cuttlefish/host/commands/cvd/utils/common.h"
4545
#include "cuttlefish/host/commands/cvd/version/version.h"

0 commit comments

Comments
 (0)