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 2828# Based on colorama
2929# https://github.com/tartley/colorama
3030# Copyright Jonathan Hartley 2013
31- # Distrubuted under the BSD 3-Clause license.
31+ # Distributed under the BSD 3-Clause license.
3232# | Redistribution and use in source and binary forms, with or without
3333# | modification, are permitted provided that the following conditions are met:
3434# |
5656#
5757# Includes modifications to colorama made by Bram Geelen in
5858# 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+ #
5964
6065# stdlib
66+ import re
6167from abc import ABC
62- from typing import List
68+ from typing import List , Pattern
6369
6470# 3rd party
6571from colorama import init # type: ignore
@@ -112,6 +118,19 @@ def clear_line(mode: int = 2) -> str:
112118 return CSI + str (mode ) + 'K'
113119
114120
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+
115134class Colour (str ):
116135 r"""
117136 An ANSI escape sequence representing a colour.
You can’t perform that action at this time.
0 commit comments