From 24f2520099b13970c82dc24244f51063716ae37c Mon Sep 17 00:00:00 2001 From: David Stanek Date: Fri, 8 Apr 2022 19:00:50 -0400 Subject: [PATCH] fix: Remove customer color_print function --- copier/main.py | 5 ++--- copier/tools.py | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/copier/main.py b/copier/main.py index 66277a344..29ef0347a 100644 --- a/copier/main.py +++ b/copier/main.py @@ -12,7 +12,6 @@ from typing import Callable, Iterable, List, Mapping, Optional, Sequence from unicodedata import normalize -import colorama import pathspec from jinja2.loaders import FileSystemLoader from jinja2.sandbox import SandboxedEnvironment @@ -27,7 +26,7 @@ from .errors import CopierAnswersInterrupt, ExtensionNotFoundError, UserMessageError from .subproject import Subproject from .template import Template -from .tools import Style, TemporaryDirectory, color_print, is_binary, print_diff, printf +from .tools import Style, TemporaryDirectory, is_binary, print_diff, printf from .types import ( AnyByStrDict, JSONSerializable, @@ -263,7 +262,7 @@ def _solve_render_conflict( return True if self.diff and original_content and new_content: if is_binary(original_content) or is_binary(new_content): - color_print(colorama.Fore.YELLOW, " diff not availalbe for binaries") + print(colors.warn | " diff not availalbe for binaries") else: print_diff(dst_relpath, original_content, new_content) return bool(ask(f" Overwrite {dst_relpath}?", default=True)) diff --git a/copier/tools.py b/copier/tools.py index df4128753..533f64978 100644 --- a/copier/tools.py +++ b/copier/tools.py @@ -15,6 +15,7 @@ import colorama from packaging.version import Version +from plumbum import colors from pydantic import StrictBool from .types import IntSeq, StrSeq @@ -188,23 +189,21 @@ def is_binary(content: bytes) -> bool: return b"\x00" in content or b"\xff" in content -def color_print(color: int, msg: str): - print(f"{color}{msg}{colorama.Fore.RESET}") - - def print_diff(dst_relpath: Path, original_content: bytes, new_content: bytes): try: original_lines = get_lines(original_content) except Exception: - color_print( - colorama.Fore.YELLOW, "diff unavailable: unable to determine encoding" + print( + colors.warn + | f"diff unavailable: unable to determine encoding of {dst_relpath}" ) return try: new_lines = get_lines(new_content) except Exception: - color_print( - colorama.Fore.YELLOW, "diff unavailable: unable to determine encoding" + print( + colors.warn + | f"diff unavailable: unable to determine encoding of {dst_relpath}" ) return @@ -217,12 +216,13 @@ def print_diff(dst_relpath: Path, original_content: bytes, new_content: bytes): lineterm="", ): if line.startswith("---") or line.startswith("+++"): - color_print(colorama.Fore.YELLOW, f"{indent}{line}") + color = colors.yellow elif line.startswith("@@"): - color_print(colorama.Fore.MAGENTA, f"{indent}{line}") + color = colors.magenta elif line.startswith("-"): - color_print(colorama.Fore.RED, f"{indent}{line}") + color = colors.red elif line.startswith("+"): - color_print(colorama.Fore.GREEN, f"{indent}{line}") + color = colors.green else: - print(f"{indent}{line}") + color = colors.do_nothing + print(color | f"{indent}{line}")