Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions colorama/initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,23 @@ def reset_all():
AnsiToWin32(orig_stdout).reset_all()


def init(autoreset=False, convert=None, strip=None, wrap=True):

_initialized = False

def init(autoreset=False, convert=None, strip=None, wrap=True):
if not wrap and any([autoreset, convert, strip]):
raise ValueError('wrap=False conflicts with any other arg=True')

global wrapped_stdout, wrapped_stderr
global orig_stdout, orig_stderr

global _initialized

if _initialized:
raise ValueError("Calling init() twice will result in recursion.")

if not _initialized:
_initialized = True

orig_stdout = sys.stdout
orig_stderr = sys.stderr

Expand All @@ -62,6 +71,7 @@ def init(autoreset=False, convert=None, strip=None, wrap=True):
atexit_done = True



def deinit():
if orig_stdout is not None:
sys.stdout = orig_stdout
Expand Down