+ Returns:
+ in_str with recognized ANSI escape sequences removed.
+
+ .. warning::
+ This method works by using a regular expression.
+ It works for all ANSI escape sequences I've tested with but
+ may miss some; caveat emptor.
+
+ >>> import ansi as a
+ >>> s = a.fg('blue') + 'blue!' + a.reset()
+ >>> len(s) # '\x1b[38;5;21mblue!\x1b[m'
+ 18
+ >>> len(strip_ansi_sequences(s))
+ 5
+ >>> strip_ansi_sequences(s)
+ 'blue!'
+
+ """
+ return re.sub(r'\x1b\[[\d+;]*[a-z]', '', in_str)
+
+
+class SprintfStdout(contextlib.AbstractContextManager):
+ """
+ A context manager that captures outputs to stdout to a buffer
+ without printing them.
+
+ >>> with SprintfStdout() as buf:
+ ... print("test")
+ ... print("1, 2, 3")
+ ...
+ >>> print(buf(), end='')
+ test
+ 1, 2, 3