Skip to content

Commit 9557581

Browse files
authored
Add support for ANSI escape codes if run on Windows (for colored error messages). (#13)
1 parent 840aeae commit 9557581

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/code42cli/main.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
import platform
12
from argparse import ArgumentParser
23

34
import code42cli.securitydata.main as securitydata
45
from code42cli.compat import str
56
from code42cli.profile import profile
67

8+
# If on Windows, configure console session to handle ANSI escape sequences correctly
9+
# source: https://bugs.python.org/issue29059
10+
if platform.system().lower() == "windows":
11+
from ctypes import windll, c_int, byref
12+
13+
stdout_handle = windll.kernel32.GetStdHandle(c_int(-11))
14+
mode = c_int(0)
15+
windll.kernel32.GetConsoleMode(c_int(stdout_handle), byref(mode))
16+
mode = c_int(mode.value | 4)
17+
windll.kernel32.SetConsoleMode(c_int(stdout_handle), mode)
18+
719

820
def main():
921
code42_arg_parser = ArgumentParser()

0 commit comments

Comments
 (0)