Commit 6c55071 1 parent 5e24faf commit 6c55071 Copy full SHA for 6c55071
File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 73
73
strip_impl ( data. as_ref ( ) ) . expect ( "writing to a Cursor<Vec<u8>> cannot fail" )
74
74
}
75
75
76
+ /// Strip ANSI escapes from `data` and return the remaining contents as a `String`.
77
+ ///
78
+ /// # Example
79
+ ///
80
+ /// ```
81
+ /// let str_with_colors = "\x1b[32mfoo\x1b[m bar";
82
+ /// let string_without_colors = strip_ansi_escapes::strip_str(string_with_colors);
83
+ /// assert_eq!(string_without_colors, "foo bar");
84
+ /// ```
85
+ pub fn strip_str < T > ( data : T ) -> String
86
+ where
87
+ T : AsRef < str > ,
88
+ {
89
+ let bytes = strip ( data. as_ref ( ) ) ;
90
+ String :: from_utf8 ( bytes)
91
+ . expect ( "stripping ANSI escapes from a UTF-8 string always results in UTF-8" )
92
+ }
93
+
76
94
struct Performer < W >
77
95
where
78
96
W : Write ,
You can’t perform that action at this time.
0 commit comments