Skip to content

Commit

Permalink
Add colors to repl
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Oct 20, 2024
1 parent f8caadb commit 184f8b0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions auto_editor/subcommands/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from dataclasses import dataclass, field
from fractions import Fraction
from os import environ

import auto_editor
from auto_editor.analyze import Levels
Expand Down Expand Up @@ -71,11 +72,19 @@ def main(sys_args: list[str] = sys.argv[1:]) -> None:
print(f"Auto-Editor {auto_editor.__version__}")
text = None

no_color = bool(environ.get("NO_COLOR") or environ.get("AV_LOG_FORCE_NOCOLOR"))
if no_color:
bold_pink = bold_red = reset = ""
else:
bold_pink = "\033[1;95m"
bold_red = "\033[1;31m"
reset = "\033[0m"

try:
while True:
try:
if text is None:
text = input("> ")
text = input(f"{bold_pink}>{reset} ")
else:
text += "\n" + input(" ")
except KeyboardInterrupt as e:
Expand All @@ -97,8 +106,8 @@ def main(sys_args: list[str] = sys.argv[1:]) -> None:

except ClosingError:
continue # Allow user to continue adding text
except (MyError, ZeroDivisionError) as e:
print(f"error: {e}")
except MyError as e:
print(f"{bold_red}error{reset}: {e}")

text = None

Expand Down

0 comments on commit 184f8b0

Please sign in to comment.