Design Pattern Examples
Overview of object-oriented design patterns
enablevtmode.py File Reference

Defines a wrapper function that enable virtual terminal processing for Windows Command Prompt. More...

Go to the source code of this file.

Namespaces

namespace  DesignPatternExamples_python
 The DesignPatternExamples_python package, containing 20 examples of design patterns, each in their own namespace.
 
namespace  DesignPatternExamples_python.enablevtmode
 

Functions

None _SetVTMode ()
 If we are on Windows (as indicated by the presence of the Kernel32 DLL), set the virtual terminal processing flag on the standard output for the Windows Console.
 
None _RestoreVTMode ()
 If we are on Windows (as indicated by the presence of the Kernel32 DLL), restore the standard output mode for the Windows Console.
 
def EnableVTMode (callable function)
 Wrap the given function with enabling and disabling the virtual terminal processing for a Windows Console.
 

Variables

int STD_OUTPUT_HANDLE = -11
 Value representing the Standard Output Handle in the Windows Console.
 
int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
 Flag that, when set, enables virtual terminal processing and thus support for ANSI escape code handling.
 
None originalConsoleMode = None
 Holds the original mode for Standard Output in the Windows Console so it can be restored later on.
 
 try :
 
ctypes kernel32 = ctypes.windll.kernel32
 
 except :
 

Detailed Description

Defines a wrapper function that enable virtual terminal processing for Windows Command Prompt.

This function is intended to wrap the call to main() so it can restore the mode on exit. How to use:

from .enablevtmode import EnableVTMode
def main() -> int:
return 0
sys.exit(EnableVTMode(main))

Definition in file enablevtmode.py.