Skip to content

Commit a7bd450

Browse files
[1.1.0] Set VirtualTerminal && fix bug on Linux
1 parent 5c3d6ba commit a7bd450

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: ProgramExecutableAnalyzer
3-
Version: 1.0.1
3+
Version: 1.1.0
44
Summary: This script analyzes MZ-PE (MS-DOS) executable.
55
Home-page: https://github.com/mauricelambert/ProgramExecutableAnalyzer
66
Author: Maurice Lambert

ProgramExecutableAnalyzer.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: ProgramExecutableAnalyzer
3-
Version: 1.0.1
3+
Version: 1.1.0
44
Summary: This script analyzes MZ-PE (MS-DOS) executable.
55
Home-page: https://github.com/mauricelambert/ProgramExecutableAnalyzer
66
Author: Maurice Lambert

ProgramExecutableAnalyzer.egg-info/SOURCES.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ LICENSE.txt
22
MANIFEST.in
33
ProgramExecutableAnalyzer.py
44
README.md
5-
rich_ids.txt
65
setup.cfg
76
setup.py
87
ProgramExecutableAnalyzer.egg-info/PKG-INFO

ProgramExecutableAnalyzer.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
This script analyzes MZ-PE (MS-DOS) executable file.
2424
"""
2525

26-
__version__ = "1.0.1"
26+
__version__ = "1.1.0"
2727
__author__ = "Maurice Lambert"
2828
__author_email__ = "mauricelambert434@gmail.com"
2929
__maintainer__ = "Maurice Lambert"
@@ -124,6 +124,62 @@ class Section:
124124
argv.remove("-c")
125125

126126

127+
if name == 'nt':
128+
from ctypes.wintypes import DWORD
129+
from ctypes import windll, byref, WinDLL
130+
131+
def active_virtual_terminal() -> bool:
132+
"""
133+
This function active terminal colors on Windows.
134+
135+
return True on success and False on fail.
136+
137+
This function come from: https://raw.githubusercontent.com/mauricelambert/PythonToolsKit/main/PythonToolsKit/WindowsTerminal.py
138+
doc: https://docs.microsoft.com/fr-fr/windows/console/console-virtual-terminal-sequences#code-try-1
139+
140+
>>> print("\\x1b[32mabc\\x1b[0m")
141+
←[32mabc←[0m
142+
>>> active_virtual_terminal()
143+
True
144+
>>> print("\\x1b[32mabc\\x1b[0m")
145+
abc
146+
>>> active_virtual_terminal()
147+
False
148+
>>>
149+
"""
150+
151+
default_in_mode: DWORD = DWORD()
152+
default_out_mode: DWORD = DWORD()
153+
154+
kernel32: WinDLL = windll.kernel32
155+
_FuncPtr: type = kernel32._FuncPtr
156+
157+
GetStdHandle: _FuncPtr = kernel32.GetStdHandle
158+
GetConsoleMode: _FuncPtr = kernel32.GetConsoleMode
159+
SetConsoleMode: _FuncPtr = kernel32.SetConsoleMode
160+
161+
OUT_ENABLE_VIRTUAL_TERMINAL_PROCESSING: int = 0x0004
162+
OUT_DISABLE_NEWLINE_AUTO_RETURN: int = 0x0008
163+
164+
STDOUT: int = GetStdHandle(-11)
165+
166+
if not GetConsoleMode(STDOUT, byref(default_out_mode)):
167+
return False
168+
169+
new_out_mode = (
170+
OUT_ENABLE_VIRTUAL_TERMINAL_PROCESSING
171+
| OUT_DISABLE_NEWLINE_AUTO_RETURN
172+
)
173+
174+
new_out_mode = DWORD(default_out_mode.value | new_out_mode)
175+
176+
if not SetConsoleMode(STDOUT, new_out_mode):
177+
return False
178+
179+
return True
180+
181+
active_virtual_terminal()
182+
127183
colors = []
128184

129185

@@ -431,6 +487,7 @@ class SYSTEMTIME(Structure):
431487
print_(
432488
"Cannot check the siganture on Linux or from URL or STDIN", file=stderr
433489
)
490+
status = None
434491

435492
if status in (0, 0x800B0111):
436493
dword_encoding = DWORD()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="ProgramExecutableAnalyzer",
5-
version="1.0.1",
5+
version="1.1.0",
66
py_modules=["ProgramExecutableAnalyzer"],
77
install_requires=[],
88
author="Maurice Lambert",

0 commit comments

Comments
 (0)