render text by input color and style. It's not recommend that input text is already rendered.
(self, text: str, color: str = "", style: str = "")
| 33 | return [getattr(cls, name) for name in names] |
| 34 | |
| 35 | def render(self, text: str, color: str = "", style: str = "") -> str: |
| 36 | """ |
| 37 | render text by input color and style. |
| 38 | It's not recommend that input text is already rendered. |
| 39 | """ |
| 40 | # This method is called too frequently, which is not good. |
| 41 | colors = self.get_all_colors() |
| 42 | # Perhaps color and font should be distinguished here. |
| 43 | if color and color in colors: |
| 44 | error_message = f"color should be in: {colors} but now is: {color}" |
| 45 | raise ValueError(error_message) |
| 46 | if style and style in colors: |
| 47 | error_message = f"style should be in: {colors} but now is: {style}" |
| 48 | raise ValueError(error_message) |
| 49 | |
| 50 | text = f"{color}{text}{self.END}" |
| 51 | |
| 52 | return f"{style}{text}{self.END}" |
| 53 | |
| 54 | @staticmethod |
| 55 | def remove_ansi_codes(s: str) -> str: |
no test coverage detected