def should_use_colors(args) -> bool: """Processes arguments and decides whether to enable color in output""" if args.color == ColorMode.ON: return True if args.color == ColorMode.OFF: return False return is_terminal_support_colors()
def get_config_with_source(include_default: bool = False) -> str: """Return configuration along with source for each option.""" config_dict = conf.as_dict(display_source=True) with io.StringIO() as buf, redirect_stdout(buf): for section, options in config_dict.items(): if not include_default: options = { key: (value, source) for key, (value, source) in options.items() if source != "default" } # Print the section only when there are options after filtering if options: print(f"[{section}]") for key, (value, source) in options.items(): print(f"{key} = {value} [{source}]") print() code = buf.getvalue() if is_terminal_support_colors(): code = pygments.highlight(code=code, formatter=get_terminal_formatter(), lexer=IniLexer()) return code
def cheat_sheet(args): """Display cheat-sheet.""" with contextlib.ExitStack() as exit_stack: if not is_terminal_support_colors(): exit_stack.enter_context(patch_environ({ANSI_COLORS_DISABLED: "1"})) cprint("List of all commands:".upper(), attrs=["bold", "underline"]) print() display_commands_index()
def should_use_colors(args_or_color): """Processes arguments and decides whether to enable color in output""" # args.color is from argparse, Click CLI will pass in the color directly color = args_or_color.color if hasattr(args_or_color, 'color') else args_or_color if color == ColorMode.ON: return True if color == ColorMode.OFF: return False return is_terminal_support_colors()