papermario/tools/splat/util/log.py
HailSanta 6c606383e8
nok and pra done (#936)
* nok_04 ok

* thread done

* push block doc

* nok done

* almost done pra

* pra done

* cleanup pra_31 mtx names

* git subrepo pull --force tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "3bbc02af68"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "3bbc02af68"
git-subrepo:
  version:  "0.4.5"
  origin:   "???"
  commit:   "???"

---------

Co-authored-by: HailSanta <Hail2Santa@gmail.com>
2023-02-08 09:47:26 +09:00

46 lines
958 B
Python

import sys
from typing import NoReturn, Optional
from colorama import Fore, init, Style
init(autoreset=True)
newline = True
Status = Optional[str]
def write(*args, status=None, **kwargs):
global newline
if not newline:
print("")
newline = True
print(status_to_ansi(status) + str(args[0]), *args[1:], **kwargs)
def error(*args, **kwargs) -> NoReturn:
write(*args, **kwargs, status="error")
sys.exit(2)
# The line_num is expected to be zero-indexed
def parsing_error_preamble(path, line_num, line):
write("")
write(f"error reading {path}, line {line_num + 1}:", status="error")
write(f"\t{line}")
def status_to_ansi(status: Status):
if status == "ok":
return Fore.GREEN
elif status == "warn":
return Fore.YELLOW + Style.BRIGHT
elif status == "error":
return Fore.RED + Style.BRIGHT
elif status == "skip":
return Style.DIM
else:
return ""