Coverage for photoimport/ui.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Everything required to print the UI for the user
3:copyright: Copyright 2020 Edward Armitage.
4:license: MIT, see LICENSE for details.
5"""
6import sys
7from textwrap import indent
9from colorama import init, Fore, Style
12class ConsoleWriter:
13 """Class for grouping UI functionality"""
15 def __init__(self, silent_mode: bool) -> None:
16 """
17 :param silent_mode: When True, status() and action() are effectively
18 no-op methods.
19 """
20 init(autoreset=True)
21 self._silent_mode = silent_mode
23 @staticmethod
24 def fatal(error_code: int, msg: str) -> None:
25 """Prints an error message, and exits with the provided error code
27 :param error_code: The error code to use when exiting
28 :param msg: The error message to be shown
29 """
30 print(Fore.RED + "❌ A fatal error occurred:", file=sys.stderr)
31 print(indent(Fore.RED + msg, " "), file=sys.stderr)
32 print(Fore.RED + "Exiting" + Style.RESET_ALL, file=sys.stderr)
33 sys.exit(error_code)
35 def status(self, msg: str) -> None:
36 """Prints a message indicating the current status
38 :param msg: The message to be printed
39 """
40 if not self._silent_mode:
41 print(Fore.YELLOW + msg)
43 def action(self, msg: str) -> None:
44 """Prints a message showing an action that is being performed
46 :param msg: The message to be printed
47 """
48 if not self._silent_mode:
49 print(Fore.GREEN + msg)