Skip to content

Commit

Permalink
WIP4
Browse files Browse the repository at this point in the history
  • Loading branch information
MoessnerFabian(Group) committed Jan 28, 2025
1 parent 724fdb5 commit e01f059
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 70 deletions.
3 changes: 1 addition & 2 deletions logprep/util/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
See: http://en.wikipedia.org/wiki/ANSI_escape_code
'''

# ANSI escape sequences
CSI = '\033['
OSC = '\033]'
BEL = '\a'
Expand Down Expand Up @@ -94,4 +93,4 @@ class AnsiStyle(AnsiCodes):
Fore = AnsiFore()
Back = AnsiBack()
Style = AnsiStyle()
Cursor = AnsiCursor()
Cursor = AnsiCursor()
67 changes: 3 additions & 64 deletions logprep/util/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from os import remove
from typing import TYPE_CHECKING, Optional, Union

from colorama import Back, Fore
from colorama.ansi import AnsiBack, AnsiFore
from logprep.util.ansi import Back, Fore, AnsiBack, AnsiFore

from logprep.processor.base.exceptions import FieldExistsWarning
from logprep.util.defaults import DEFAULT_CONFIG_LOCATION
Expand All @@ -29,7 +28,7 @@ def color_print_line(
if fore:
color += fore

print(color + message + get_ansi_code('reset', 'fore') + get_ansi_code('reset', 'back'))
print(color + message + Fore.RESET + Back.RESET)


def color_print_title(background: Union[str, AnsiBack], message: str):
Expand Down Expand Up @@ -405,64 +404,4 @@ def get_versions_string(config: "Configuration" = None) -> str:
else:
config_version = f"no configuration found in {', '.join([DEFAULT_CONFIG_LOCATION])}"
version_string += f"\n{'configuration version:'.ljust(padding)}{config_version}"
return version_string

def get_ansi_code(color, type):
if type == 'fore':
base = 30
elif type == 'back':
base = 40
else:
base = 30

colors = {
'black': 0,
'red': 1,
'green': 2,
'yellow': 3,
'blue': 4,
'magenta': 5,
'cyan': 6,
'white': 7,
'reset': 9,
'lightblack': 60,
'lightred': 61,
'lightgreen': 62,
'lightyellow': 63,
'lightblue': 64,
'lightmagenta': 65,
'lightcyan': 66,
'lightwhite': 67
}

return f"\x1b[{str(base+colors.get(color))}m"


class AnsiFore:
_colors = {
'RED': 31,
'GREEN': 32,
'BLUE': 34,
'RESET': 39
}

def __class_getitem__(cls, name):
if name in cls._colors:
return f'\033[{cls._colors[name]}m'
raise AttributeError(f"No Ansi code found: {name}")


class AnsiBack:
_colors = {
'RED': 41,
'GREEN': 42,
'BLUE': 44,
'RESET': 49
}

def __class_getitem__(cls, name):
if name in cls._colors:
return f'\033[{cls._colors[name]}m'
raise AttributeError(f"No Ansi code found: {name}")


return version_string
7 changes: 3 additions & 4 deletions logprep/util/rule_dry_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@
from functools import cached_property
from typing import Dict, List

from colorama import Back, Fore
from ruamel.yaml import YAML

from logprep.framework.pipeline import Pipeline, PipelineResult
from logprep.util.configuration import Configuration
from logprep.util.getter import GetterFactory
from logprep.util.helper import color_print_line, color_print_title, recursive_compare, get_ansi_code
from logprep.util.helper import AnsiBack, AnsiFore
from logprep.util.helper import color_print_line, color_print_title, recursive_compare
from logprep.util.ansi import Back, Fore

yaml = YAML(typ="safe", pure=True)

Expand Down Expand Up @@ -150,7 +149,7 @@ def _print_ndiff_items(self, diff):
elif item.startswith("? "):
color_print_line(Back.BLACK, Fore.WHITE, item)
else:
color_print_line(get_ansi_code('black', 'back'),get_ansi_code('cyan', 'fore'), item)
color_print_line(Back.BLACK, Fore.CYAN, item)



Expand Down

0 comments on commit e01f059

Please sign in to comment.