Wrap Windows virtual terminal sequence enabling in a try/except to fallback on disabling color in case of any exception.

pull/159/head
David Pokora 6 years ago
parent 05bfbf10cf
commit 072cc152d1
No known key found for this signature in database
GPG Key ID: 3CED48D1BB21BDD7
  1. 5
      slither/utils/colors.py

@ -25,6 +25,7 @@ def enable_windows_virtual_terminal_sequences():
Reference: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
"""
try:
from ctypes import windll, byref
from ctypes.wintypes import DWORD, HANDLE
@ -52,6 +53,10 @@ def enable_windows_virtual_terminal_sequences():
if (current_mode.value & virtual_terminal_flag) == 0:
if not kernel32.SetConsoleMode(current_handle, current_mode.value | virtual_terminal_flag):
return False
except:
# Any generic failure (possibly from calling these methods on older Windows builds where they do not exist)
# will fall back onto disabling colorization.
return False
return True

Loading…
Cancel
Save