@@ -39,15 +39,15 @@ impl Printer {
3939 pub fn print ( & self , writer : & mut dyn std:: io:: Write ) -> Result < ( ) > {
4040 match & self . r#type {
4141 PrinterType :: Json => {
42- writeln ! ( writer, "{}" , serde_json:: to_string_pretty( & self . info) ?) ?;
42+ write ! ( writer, "{}" , serde_json:: to_string_pretty( & self . info) ?) ?;
4343 Ok ( ( ) )
4444 }
4545 PrinterType :: Yaml => {
46- writeln ! ( writer, "{}" , serde_yaml:: to_string( & self . info) ?) ?;
46+ write ! ( writer, "{}" , serde_yaml:: to_string( & self . info) ?) ?;
4747 Ok ( ( ) )
4848 }
4949 PrinterType :: Plain => {
50- write ! ( writer, " \x1B [?7l{} \x1B [?7h" , self . info) ?;
50+ write_with_line_wrapping ( writer, & self . info . to_string ( ) ) ?;
5151 Ok ( ( ) )
5252 }
5353 PrinterType :: Image {
@@ -66,7 +66,7 @@ impl Printer {
6666 . add_image ( info_lines, image, * resolution)
6767 . context ( "Failed to render image" ) ?;
6868
69- write ! ( writer, " \x1B [?7l{ rendered} \x1B [?7h" ) ?;
69+ write_with_line_wrapping ( writer, & rendered) ?;
7070 Ok ( ( ) )
7171 }
7272 PrinterType :: Ascii { art, no_bold } => {
@@ -86,21 +86,23 @@ impl Printer {
8686 "" ,
8787 width = logo_lines. width( )
8888 ) ?,
89- ( None , None ) => {
90- buf. push ( '\n' ) ;
91- break ;
92- }
89+ ( None , None ) => break ,
9390 }
9491 }
9592
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) ?;
9894 Ok ( ( ) )
9995 }
10096 }
10197 }
10298}
10399
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+
104106impl PartialEq for PrinterType {
105107 fn eq ( & self , other : & Self ) -> bool {
106108 matches ! (
0 commit comments