Design Pattern Examples
Overview of object-oriented design patterns
DesignPatternExamples_python.enablevtmode Namespace Reference

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 :
 

Function Documentation

◆ _RestoreVTMode()

None _RestoreVTMode ( )
protected

If we are on Windows (as indicated by the presence of the Kernel32 DLL), restore the standard output mode for the Windows Console.

Definition at line 52 of file enablevtmode.py.

Referenced by DesignPatternExamples_python.enablevtmode.EnableVTMode().

◆ _SetVTMode()

None _SetVTMode ( )
protected

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.

Definition at line 39 of file enablevtmode.py.

Referenced by DesignPatternExamples_python.enablevtmode.EnableVTMode().

◆ EnableVTMode()

def EnableVTMode ( callable  function)

Wrap the given function with enabling and disabling the virtual terminal processing for a Windows Console.

The processing is disabled regardless of the exit state of the function.

This is generally intended to wrap a main() function like this:

sys.exit(EnableVTMode(main))

Definition at line 66 of file enablevtmode.py.

References DesignPatternExamples_python.enablevtmode._RestoreVTMode(), and DesignPatternExamples_python.enablevtmode._SetVTMode().

Variable Documentation

◆ ENABLE_VIRTUAL_TERMINAL_PROCESSING

int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004

Flag that, when set, enables virtual terminal processing and thus support for ANSI escape code handling.

Definition at line 21 of file enablevtmode.py.

◆ except

except :

Definition at line 32 of file enablevtmode.py.

◆ kernel32

None kernel32 = ctypes.windll.kernel32

Definition at line 31 of file enablevtmode.py.

◆ originalConsoleMode

None originalConsoleMode = None

Holds the original mode for Standard Output in the Windows Console so it can be restored later on.

Definition at line 25 of file enablevtmode.py.

◆ STD_OUTPUT_HANDLE

int STD_OUTPUT_HANDLE = -11

Value representing the Standard Output Handle in the Windows Console.

Definition at line 18 of file enablevtmode.py.

◆ try

try :

Definition at line 29 of file enablevtmode.py.