simplify ansi disabling on mac (removing type issues)

This commit is contained in:
deeplow 2022-07-25 16:30:35 +01:00
parent 95ed34626d
commit 201bf5ec03
No known key found for this signature in database
GPG key ID: 577982871529A52A

View file

@ -4,9 +4,10 @@ import platform
import signal import signal
import sys import sys
import uuid import uuid
from typing import Dict, NoReturn, Optional, TextIO from typing import Dict, Optional
import click import click
import colorama
from PySide2 import QtCore, QtWidgets from PySide2 import QtCore, QtWidgets
from ..global_common import GlobalCommon from ..global_common import GlobalCommon
@ -57,25 +58,9 @@ def gui_main(filename: Optional[str]) -> bool:
# Make sure /usr/local/bin is in the path # Make sure /usr/local/bin is in the path
os.environ["PATH"] = "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin" os.environ["PATH"] = "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
# Strip ANSI colors from stdout output, to prevent terminal colors from breaking # Don't show ANSI colors from stdout output, to prevent terminal
# the macOS GUI app # colors from breaking the macOS GUI app
from strip_ansi import strip_ansi colorama.deinit()
class StdoutFilter:
def __init__(self, stream: TextIO) -> None:
self.stream = stream
def __getattr__(self, attr_name): # type: ignore [no-untyped-def]
return getattr(self.stream, attr_name)
def write(self, data: str) -> None:
self.stream.write(strip_ansi(data))
def flush(self) -> None:
self.stream.flush()
sys.stdout = StdoutFilter(sys.stdout)
sys.stderr = StdoutFilter(sys.stderr)
# Create the Qt app # Create the Qt app
app_wrapper = ApplicationWrapper() app_wrapper = ApplicationWrapper()