Skip to content

Commit

Permalink
fix: Remove customer color_print function
Browse files Browse the repository at this point in the history
  • Loading branch information
dstanek committed Apr 8, 2022
1 parent bef089c commit 7e7e1a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
5 changes: 2 additions & 3 deletions copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
26 changes: 13 additions & 13 deletions copier/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import colorama
from packaging.version import Version
from plumbum import colors
from pydantic import StrictBool

from .types import IntSeq, StrSeq
Expand Down Expand Up @@ -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

Expand All @@ -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}")

0 comments on commit 7e7e1a7

Please sign in to comment.