File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 28
28
# Based on colorama
29
29
# https://github.com/tartley/colorama
30
30
# Copyright Jonathan Hartley 2013
31
- # Distrubuted under the BSD 3-Clause license.
31
+ # Distributed under the BSD 3-Clause license.
32
32
# | Redistribution and use in source and binary forms, with or without
33
33
# | modification, are permitted provided that the following conditions are met:
34
34
# |
56
56
#
57
57
# Includes modifications to colorama made by Bram Geelen in
58
58
# https://github.com/tartley/colorama/pull/141/files
59
+ #
60
+ # _ansi_re and strip_ansi based on https://github.com/pallets/click
61
+ # Copyright 2014 Pallets
62
+ # Distributed under the BSD 3-Clause license.
63
+ #
59
64
60
65
# stdlib
66
+ import re
61
67
from abc import ABC
62
- from typing import List
68
+ from typing import List , Pattern
63
69
64
70
# 3rd party
65
71
from colorama import init # type: ignore
@@ -112,6 +118,19 @@ def clear_line(mode: int = 2) -> str:
112
118
return CSI + str (mode ) + 'K'
113
119
114
120
121
+ _ansi_re : Pattern [str ] = re .compile (r"\033\[[;?0-9]*[a-zA-Z]" )
122
+
123
+
124
+ def strip_ansi (value : str ) -> str :
125
+ """
126
+ Strip ANSI colour codes from the given string to return a plaintext output.
127
+
128
+ :param value:
129
+ """
130
+
131
+ return _ansi_re .sub ("" , value )
132
+
133
+
115
134
class Colour (str ):
116
135
r"""
117
136
An ANSI escape sequence representing a colour.
You can’t perform that action at this time.
0 commit comments