Files
mm/tools/decomp-permuter/src/printer.py
T
Anghelo Carvajal b6904aa2cc Convert every submodule into subrepo (#170)
* remove ZAPD submodule

* git subrepo clone https://github.com/zeldaret/ZAPD.git tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "ca229f19"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "ca229f19"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* git subrepo clone https://github.com/simonlindholm/decomp-permuter.git tools/decomp-permuter

subrepo:
  subdir:   "tools/decomp-permuter"
  merged:   "1e4b85a7"
upstream:
  origin:   "https://github.com/simonlindholm/decomp-permuter.git"
  branch:   "main"
  commit:   "1e4b85a7"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* Remove asm-differ

* git subrepo clone https://github.com/simonlindholm/asm-differ.git tools/asm-differ

subrepo:
  subdir:   "tools/asm-differ"
  merged:   "eaf72269"
upstream:
  origin:   "https://github.com/simonlindholm/asm-differ.git"
  branch:   "master"
  commit:   "eaf72269"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* remove asm-processor

* git subrepo clone https://github.com/simonlindholm/asm-processor.git tools/asm-processor

subrepo:
  subdir:   "tools/asm-processor"
  merged:   "85288fcd"
upstream:
  origin:   "https://github.com/simonlindholm/asm-processor.git"
  branch:   "master"
  commit:   "85288fcd"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* remove .gitmodules file

* Update REAMDE

* Update warnings
2021-06-07 18:31:56 -04:00

47 lines
1.4 KiB
Python

from typing import Optional
from .permuter import Permuter
# Number of additional characters to replace with spaces, in addition to what
# is required based on the length of the previous progress line. This could be
# set to 0, but it's nice to have some margin to deal with e.g. zero-width
# control characters.
SAFETY_PAD = 10
class Printer:
_last_progress: Optional[str] = None
def progress(self, message: str) -> None:
if self._last_progress is None:
clear = ""
else:
pad = max(len(self._last_progress) - len(message) + SAFETY_PAD, 0)
clear = "\b" * pad + " " * pad + "\r"
print(clear + message, end="", flush=True)
self._last_progress = message
def print(
self,
message: str,
permuter: Optional[Permuter],
who: Optional[str],
*,
color: str = "",
keep_progress: bool = False,
) -> None:
if self._last_progress is not None:
if keep_progress:
print()
else:
pad = len(self._last_progress) + SAFETY_PAD
print("\r" + " " * pad + "\r", end="")
if permuter is not None:
message = f"[{permuter.unique_name}] {message}"
if who is not None:
message = f"[{who}] {message}"
if color:
message = f"{color}{message}\u001b[0m"
print(message)
self._last_progress = None