|
6 | 6 |
|
7 | 7 | from pwnlib.term import termcap |
8 | 8 |
|
9 | | -# Accept any module attribute for type checking purposes. |
10 | | -# The actual implementation of __getattr__ is below, and |
11 | | -# only accepts a defined text decorator pattern, but generating |
12 | | -# all possible combinations of text decorators is not feasible. |
13 | | -# No IDE auto-complete but at least no type errors. |
14 | 9 | _WhenSetter: TypeAlias = Literal["always", "never", "auto"] | TextIO |
15 | 10 | class _TextDecorator(Protocol): |
16 | 11 | def __call__(self, desc: str, when: _WhenSetter | None = None) -> str: ... |
17 | 12 |
|
18 | 13 | if TYPE_CHECKING: |
| 14 | + # Accept any module attribute for type checking purposes. |
| 15 | + # The actual implementation of __getattr__ is below, and |
| 16 | + # only accepts a defined text decorator pattern, but generating |
| 17 | + # all possible combinations of text decorators is not feasible. |
| 18 | + # No IDE auto-complete but at least no type errors. |
19 | 19 | def __getattr__(name: str) -> _TextDecorator: ... |
20 | 20 | def get(desc: str) -> _TextDecorator: ... |
21 | 21 | when: bool | _WhenSetter |
@@ -80,6 +80,15 @@ def has_bright(self): |
80 | 80 | def has_gray(self): |
81 | 81 | return self.has_bright |
82 | 82 |
|
| 83 | + # Export the _WhenSetter and _TextDecorator types for type checking purposes. |
| 84 | + @property |
| 85 | + def _WhenSetter(self): |
| 86 | + return _WhenSetter |
| 87 | + |
| 88 | + @property |
| 89 | + def _TextDecorator(self): |
| 90 | + return _TextDecorator |
| 91 | + |
83 | 92 | def _fg_color(self, c): |
84 | 93 | c = termcap.get('setaf', c) or termcap.get('setf', c) |
85 | 94 | if not hasattr(c, 'encode'): |
|
0 commit comments