Skip to content

Commit fd12c76

Browse files
authored
refactor: use enums for ansi colors
1 parent 5729ab8 commit fd12c76

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

enum4linux-ng.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
from impacket.dcerpc.v5 import transport, samr
9999
from ldap3 import Server, Connection, DSA
100100
import yaml
101+
from enum import Enum
102+
101103
try:
102104
from yaml import CDumper as Dumper
103105
except ImportError:
@@ -320,35 +322,15 @@
320322
GLOBAL_COLORS = True
321323
GLOBAL_SAMBA_LEGACY = False
322324

323-
class Colors:
324-
ansi_reset = '\033[0m'
325-
ansi_red = '\033[91m'
326-
ansi_green = '\033[92m'
327-
ansi_yellow = '\033[93m'
328-
ansi_blue = '\033[94m'
329-
330-
@classmethod
331-
def red(cls, msg):
332-
if GLOBAL_COLORS:
333-
return f"{cls.ansi_red}{msg}{cls.ansi_reset}"
334-
return msg
335-
336-
@classmethod
337-
def green(cls, msg):
338-
if GLOBAL_COLORS:
339-
return f"{cls.ansi_green}{msg}{cls.ansi_reset}"
340-
return msg
341-
342-
@classmethod
343-
def yellow(cls, msg):
344-
if GLOBAL_COLORS:
345-
return f"{cls.ansi_yellow}{msg}{cls.ansi_reset}"
346-
return msg
325+
class Colors(Enum):
326+
red = '\033[91m'
327+
green = '\033[92m'
328+
yellow = '\033[93m'
329+
blue = '\033[94m'
347330

348-
@classmethod
349-
def blue(cls, msg):
331+
def __call__(self, message):
350332
if GLOBAL_COLORS:
351-
return f"{cls.ansi_blue}{msg}{cls.ansi_reset}"
333+
return f"{self.value}{message}\033[0m"
352334
return msg
353335

354336
class Result:
@@ -3163,7 +3145,7 @@ def valid_file(file, mode=os.R_OK):
31633145
### Print Functions and Error Processing
31643146

31653147
def print_banner():
3166-
print(f"{Colors.green(f'ENUM4LINUX - next generation (v{GLOBAL_VERSION})')}\n")
3148+
print(Colors.green(f'ENUM4LINUX - next generation (v{GLOBAL_VERSION})'), end="\n\n")
31673149

31683150
def print_heading(text, leading_newline=True):
31693151
output = f"| {text} |"

0 commit comments

Comments
 (0)