1 # Copyright 2020 The Pigweed Authors
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 # use this file except in compliance with the License. You may obtain a copy of
7 # https://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations under
14 """Facilities for accessing the current Pigweed branding"""
16 from typing import Optional
17 from pathlib import Path
22 _memoized_banner: Optional[str] = None
24 # This is the default banner for Pigweed.
26 ▒█████▄ █▓ ▄███▒ ▒█ ▒█ ░▓████▒ ░▓████▒ ▒▓████▄
27 ▒█░ █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█ ▒█ ▀ ▒█ ▀ ▒█ ▀█▌
28 ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█ ▒███ ▒███ ░█ █▌
29 ▒█▀ ░█░ ▓█ █▓ ░█░ █ ▒█ ▒█ ▄ ▒█ ▄ ░█ ▄█▌
30 ▒█ ░█░ ░▓███▀ ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀
35 global _memoized_banner # pylint: disable=global-statement
36 if _memoized_banner is not None:
37 return _memoized_banner
39 parsed_env = pw_cli.env.pigweed_environment()
41 # Take the banner from the file PW_BRANDING_BANNER; or use the default.
42 banner_filename = parsed_env.PW_BRANDING_BANNER
43 _memoized_banner = (Path(banner_filename).read_text()
44 if banner_filename else _PIGWEED_BANNER)
46 # Color the banner if requested.
47 banner_color = parsed_env.PW_BRANDING_BANNER_COLOR
48 if banner_color != '':
49 _memoized_banner = getattr(
50 pw_cli.color.colors(),
55 return _memoized_banner