Skip to content

Commit

Permalink
Merge pull request #1411 from zrquan/patch-perf
Browse files Browse the repository at this point in the history
Use re instead of pyparsing for "cleaning color"
  • Loading branch information
shelld3v authored Oct 16, 2024
2 parents 6631e05 + f001c7a commit 6c7e726
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
14 changes: 4 additions & 10 deletions lib/view/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
#
# Author: Mauro Soria

import string
import re

from colorama import init, Fore, Back, Style
from pyparsing import Literal, Word, Combine, Optional, Suppress, delimitedList, oneOf


BACK_COLORS = {
Expand Down Expand Up @@ -50,13 +49,8 @@
"normal": ""
}

# Credit: https://stackoverflow.com/a/2187024/12238982
_escape_seq = Combine(
Literal("\x1b")
+ "["
+ Optional(delimitedList(Word(string.digits), ";"))
+ oneOf(list(string.ascii_letters))
)
# Credit: https://stackoverflow.com/a/14693789
_ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')

init()

Expand All @@ -76,4 +70,4 @@ def set_color(msg, fore="none", back="none", style="normal"):


def clean_color(msg):
return Suppress(_escape_seq).transformString(msg)
return _ansi_escape.sub("", msg)
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ requests>=2.27.0
requests_ntlm>=1.1.0
colorama>=0.4.4
ntlm_auth>=1.5.0
pyparsing>=2.4.7
beautifulsoup4>=4.8.0
mysql-connector-python>=8.0.20
psycopg[binary]>=3.0
Expand Down

0 comments on commit 6c7e726

Please sign in to comment.