File tree Expand file tree Collapse file tree
base/cvd/cuttlefish/ansi_codes Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,15 @@ cf_cc_library(
1313 ],
1414)
1515
16+ cf_cc_library (
17+ name = "should_color" ,
18+ srcs = ["should_color.cc" ],
19+ hdrs = ["should_color.h" ],
20+ deps = [
21+ "//cuttlefish/common/libs/utils:environment" ,
22+ ],
23+ )
24+
1625cf_cc_library (
1726 name = "terminal_colors" ,
1827 srcs = ["terminal_colors.cc" ],
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (C) 2026 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/should_color.h"
18+
19+ #include < unistd.h>
20+
21+ #include " cuttlefish/common/libs/utils/environment.h"
22+
23+ namespace cuttlefish {
24+ namespace {
25+
26+ bool ColorDefault (int fd) {
27+ // https://no-color.org/
28+ if (!StringFromEnv (" NO_COLOR" ).value_or (" " ).empty ()) {
29+ return false ;
30+ }
31+ // https://force-color.org/
32+ if (!StringFromEnv (" FORCE_COLOR" ).value_or (" " ).empty ()) {
33+ return true ;
34+ }
35+ return isatty (fd);
36+ }
37+
38+ } // namespace
39+
40+ bool ShouldColorStdout () { return ColorDefault (STDOUT_FILENO ); }
41+
42+ bool ShouldColorStderr () { return ColorDefault (STDERR_FILENO ); }
43+
44+ } // namespace cuttlefish
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (C) 2026 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+ namespace cuttlefish {
20+
21+ bool ShouldColorStdout ();
22+ bool ShouldColorStderr ();
23+
24+ } // namespace cuttlefish
You can’t perform that action at this time.
0 commit comments