@@ -20,13 +20,28 @@ use crate::infra::result::IntoResult;
20
20
use anyhow:: Result ;
21
21
use clap:: CommandFactory ;
22
22
use clap:: Parser ;
23
+ use colored:: Colorize ;
23
24
use std:: env;
24
25
25
26
pub mod api;
26
27
pub mod args;
27
28
pub mod display;
28
29
pub mod infra;
29
30
31
+ fn show_non_printable_chars ( text : String ) -> String {
32
+ #[ inline]
33
+ fn make_red ( str : & str ) -> String {
34
+ format ! ( "{}" , str . red( ) )
35
+ }
36
+
37
+ text. replace ( ' ' , & make_red ( "·" ) )
38
+ . replace ( '\0' , & make_red ( "␀\0 " ) )
39
+ . replace ( '\t' , & make_red ( "␉\t " ) )
40
+ . replace ( '\n' , & make_red ( "␊\n " ) )
41
+ . replace ( '\r' , & make_red ( "␍\r " ) )
42
+ . replace ( "\r \n " , & make_red ( "␍␊\r \n " ) )
43
+ }
44
+
30
45
fn panic_if_err < T > ( result : & Result < T > ) {
31
46
if let Err ( e) = result {
32
47
panic ! ( "{}" , e)
@@ -160,13 +175,22 @@ async fn main() -> Result<()> {
160
175
return ( ) . into_ok ( ) ;
161
176
}
162
177
163
- if output. ends_with ( "\n \n " ) {
164
- print ! ( "{}" , & output[ ..output. len( ) - 1 ] ) ;
165
- } else if output. ends_with ( '\n' ) {
166
- print ! ( "{}" , output) ;
167
- } else {
168
- println ! ( "{}" , output) ;
169
- }
178
+ let output = {
179
+ let output = if output. ends_with ( "\n \n " ) {
180
+ output[ ..output. len ( ) - 1 ] . to_owned ( )
181
+ } else if output. ends_with ( '\n' ) {
182
+ output
183
+ } else {
184
+ format ! ( "{}\n " , output)
185
+ } ;
186
+ if args. debug {
187
+ show_non_printable_chars ( output)
188
+ } else {
189
+ output
190
+ }
191
+ } ;
192
+
193
+ print ! ( "{}" , output) ;
170
194
171
195
( ) . into_ok ( )
172
196
}
0 commit comments