Skip to content

Commit

Permalink
Make colorama an optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
erdnaxe authored and yhql committed Oct 24, 2023
1 parent 02f944c commit a1f1d0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
22 changes: 16 additions & 6 deletions rainbow/utils/color_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of rainbow
# This file is part of rainbow
#
# rainbow is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -16,10 +16,20 @@
#
# Copyright 2019 Victor Servant, Ledger SAS

import colorama
_RST = "\u001b[0m"
FOREGROUND_COLORS = {
"BLACK": "\u001b[30m",
"RED": "\u001b[31m",
"GREEN": "\u001b[32m",
"YELLOW": "\u001b[33m",
"BLUE": "\u001b[34m",
"MAGENTA": "\u001b[35m",
"CYAN": "\u001b[36m",
"WHITE": "\u001b[37m",
}

_RST = colorama.Fore.RESET


def color(name, x):
return f"{getattr(colorama.Fore,name)}{x}{_RST}"
def color(color_name: str, x: str) -> str:
"""Color string `x` with color `color_name`"""
color_code = FOREGROUND_COLORS.get(color_name, "")
return f"{color_code}{x}{_RST}"
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of rainbow
# This file is part of rainbow
#
# rainbow is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -45,7 +45,6 @@
"capstone>=4.0.0",
"lief>=0.10.0",
"intelhex",
"colorama",
"pygments",
"numpy",
"PyQt5"
Expand Down

0 comments on commit a1f1d0f

Please sign in to comment.