@@ -99,7 +99,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
9999 eprintln ! ( "The input passed via stdin is not formatted" ) ;
100100 std:: process:: exit ( 1 ) ;
101101 } else {
102- println ! ( "The input passed via stdin is already formatted" ) ;
102+ eprintln ! ( "The input passed via stdin is already formatted" ) ;
103103 }
104104 } else {
105105 print ! ( "{}" , formatted_content) ;
@@ -127,7 +127,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
127127 for ( index, file_path) in input_gdscript_files. iter ( ) . enumerate ( ) {
128128 let file_number = index + 1 ;
129129 terminal_clear_line ( ) ;
130- print ! ( "\r Formatting file {}/{}" , file_number, total_files) ;
130+ eprint ! ( "\r Formatting file {}/{}" , file_number, total_files) ;
131131 io:: stdout ( ) . flush ( ) . unwrap ( ) ;
132132
133133 let input_content = fs:: read_to_string ( file_path)
@@ -142,6 +142,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
142142 } else if args. stdout {
143143 // Clear the current line before printing formatted files to stdout, to erase the "Formatting file ..." message
144144 terminal_clear_line ( ) ;
145+ // A little bit hacky, but because terminals by default output both stdout and stderr
146+ // we need to return carriage to the start to print formatted output from the start of the line
147+ eprint ! ( "\r " ) ;
145148 // If there are multiple input files we still allow stdout but we print a separator
146149 if total_files > 1 {
147150 println ! ( "#--file:{}" , file_path. display( ) ) ;
@@ -156,15 +159,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
156159 if args. check {
157160 if all_formatted {
158161 terminal_clear_line ( ) ;
159- println ! ( "\r All {} file(s) are formatted" , total_files) ;
162+ eprintln ! ( "\r All {} file(s) are formatted" , total_files) ;
160163 } else {
161164 terminal_clear_line ( ) ;
162165 eprintln ! ( "\r Some files are not formatted" ) ;
163166 std:: process:: exit ( 1 ) ;
164167 }
165168 } else if !args. stdout {
166169 terminal_clear_line ( ) ;
167- println ! (
170+ eprintln ! (
168171 "\r Formatted {} file{}" ,
169172 total_files,
170173 if total_files == 1 { "" } else { "s" }
@@ -175,5 +178,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
175178}
176179
177180fn terminal_clear_line ( ) {
178- print ! ( "\r {}" , " " . repeat( 80 ) ) ;
181+ eprint ! ( "\r {}" , " " . repeat( 80 ) ) ;
179182}
0 commit comments