File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
### Fixes
6
6
- Fix ansi escape codes on legacy Windows console
7
- * Issue #79 , PR #80
7
+ * Issue #79 , PR #80 , PR # 85
8
8
9
9
## 1.2.0 - 2023-07-02
10
10
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ changes to the code.
30
30
* [ Subparsers] ( #working-with-subparsers )
31
31
* [ Third party formatters] ( #working-with-third-party-formatters ) (ft. django)
32
32
* [ Optparse] ( #optparse-support ) (experimental)
33
+ * [ Legacy Windows] ( #legacy-windows-support )
33
34
34
35
## Installation
35
36
@@ -239,3 +240,19 @@ Syntax highlighting works the same as `argparse`.
239
240
Colors in the ` usage ` are not supported yet.
240
241
241
242
Customizing the group name format is not supported. optparse uses Title Case format by default.
243
+
244
+ ## Legacy Windows support
245
+
246
+ If your application still runs on legacy Windows versions (older than Windows 10), you'll need to
247
+ enable ANSI escape sequences by calling ` colorama.init() ` otherwise colors will be disabled:
248
+
249
+ ``` python
250
+ import argparse
251
+ import colorama
252
+ from rich_argparse import RichHelpFormatter
253
+
254
+ colorama.init()
255
+ parser = argparse.ArgumentParser(... , formatter_class = RichHelpFormatter)
256
+ ...
257
+ ```
258
+ This is ** not** required on Windows 10 and newer or on other operating systems.
Original file line number Diff line number Diff line change @@ -34,7 +34,12 @@ def _initialize_win_colors() -> bool: # pragma: no cover
34
34
if _windows_console_fixed is None :
35
35
winver = sys .getwindowsversion () # type: ignore[attr-defined]
36
36
if winver .major < 10 or winver .build < 10586 :
37
- _windows_console_fixed = False
37
+ try :
38
+ import colorama
39
+
40
+ _windows_console_fixed = isinstance (sys .stdout , colorama .ansitowin32 .StreamWrapper )
41
+ except Exception :
42
+ _windows_console_fixed = False
38
43
else :
39
44
import ctypes
40
45
You can’t perform that action at this time.
0 commit comments