@@ -39,15 +39,15 @@ impl Printer {
39
39
pub fn print ( & self , writer : & mut dyn std:: io:: Write ) -> Result < ( ) > {
40
40
match & self . r#type {
41
41
PrinterType :: Json => {
42
- writeln ! ( writer, "{}" , serde_json:: to_string_pretty( & self . info) ?) ?;
42
+ write ! ( writer, "{}" , serde_json:: to_string_pretty( & self . info) ?) ?;
43
43
Ok ( ( ) )
44
44
}
45
45
PrinterType :: Yaml => {
46
- writeln ! ( writer, "{}" , serde_yaml:: to_string( & self . info) ?) ?;
46
+ write ! ( writer, "{}" , serde_yaml:: to_string( & self . info) ?) ?;
47
47
Ok ( ( ) )
48
48
}
49
49
PrinterType :: Plain => {
50
- write ! ( writer, " \x1B [?7l{} \x1B [?7h" , self . info) ?;
50
+ write_with_line_wrapping ( writer, & self . info . to_string ( ) ) ?;
51
51
Ok ( ( ) )
52
52
}
53
53
PrinterType :: Image {
@@ -66,7 +66,7 @@ impl Printer {
66
66
. add_image ( info_lines, image, * resolution)
67
67
. context ( "Failed to render image" ) ?;
68
68
69
- write ! ( writer, " \x1B [?7l{ rendered} \x1B [?7h" ) ?;
69
+ write_with_line_wrapping ( writer, & rendered) ?;
70
70
Ok ( ( ) )
71
71
}
72
72
PrinterType :: Ascii { art, no_bold } => {
@@ -86,21 +86,23 @@ impl Printer {
86
86
"" ,
87
87
width = logo_lines. width( )
88
88
) ?,
89
- ( None , None ) => {
90
- buf. push ( '\n' ) ;
91
- break ;
92
- }
89
+ ( None , None ) => break ,
93
90
}
94
91
}
95
92
96
- // \x1B[?7l turns off line wrapping and \x1B[?7h turns it on
97
- write ! ( writer, "\x1B [?7l{buf}\x1B [?7h" ) ?;
93
+ write_with_line_wrapping ( writer, & buf) ?;
98
94
Ok ( ( ) )
99
95
}
100
96
}
101
97
}
102
98
}
103
99
100
+ fn write_with_line_wrapping ( writer : & mut dyn std:: io:: Write , content : & str ) -> Result < ( ) > {
101
+ // \x1B[?7l turns off line wrapping and \x1B[?7h turns it on
102
+ write ! ( writer, "\x1B [?7l{content}\x1B [?7h" ) ?;
103
+ Ok ( ( ) )
104
+ }
105
+
104
106
impl PartialEq for PrinterType {
105
107
fn eq ( & self , other : & Self ) -> bool {
106
108
matches ! (
0 commit comments